4,305 Posted Topics
Re: Nice tutorial! Sometimes an endless loop comes in handy ... // an endless loop with break condition int k = 0; while(true) { k++; cout << k << " "; if (k >= 10) break; } You can put this into a function and replace break with return. Also, put … | |
Sometimes it's easier to pick an image from the internet to display in your Python Tkinter GUI toolit program. | |
Shows how to convert a comma separated value (csv) string to a list of records, and then do some data processing. The csv strings usually come from csv files created by spreadsheets. | |
Let's assume you would have to design a 500 ml (about 1.1 pint) food/beverage container like a can and use the least amount of material. Here is a Python program that explains the steps to achieve this. | |
Re: In Python3 the **input()** function returns a string. If you want an integer you use **int(input())**. | |
Re: Is your calculator written in Python code or is it a executable program? | |
| |
Re: The Tkinter widgets you are dealing with in your program are ... tk.Entry() for data input tk.Label() to display info and results tk.Button() to start an action in the form of a function or method You can also bind the entry instance to a function after, let's say, the Enter … | |
Re: Which sorting algorithm did you use? | |
This shows you how to create a flashcard like quiz game using a Python dictionary. It's up to you to explore the approach and make this a more meaningful game. | |
Re: Your code is Python2 code and would give you lots of errors in Python3. | |
I thought it would be fun to code all the different ways to show Hello World on the display. Let's start simple ... `print("Hello World")` Can anybody print out "Hello World" vertically? | |
Re: Icons with a Kindergarten look, refreshing! To be new you have to change something. Let's hope it is security that was improved. | |
![]() | Re: I get errors when I try to compile this code ... typedef struct n{int a:3, b:29;struct n*c;}t;t* f();r(){}m(u)t*u;{t*w,*z; z=u->c,q(z),u->b=z->b*10, w=u->c=f(),w->a=1,w->c=z-> c;}t*k;g(u)t*u;{t*z,*v,*p, *x;z=u->c,q(z),u->b=z->b,v =z->c,z->a=2,x=z->c=f(),x ->a=3,x->b=2,p=x->c=f(),p ->c=f(),p->c->a=1,p->c->c= v;}int i;h(u)t*u;{t*z,*v,* w;int c,e;z=u->c,v=z->c,q( v),c=u->b,e=v->b,u->b=z->b ,z->a=3,z->b=c+1,e+9>=c&&( q(z),e=z->b,u->b+=e/c,w=f( ),w->b=e%c,w->c=z->c,u->c= w);}int(*y[4])()={r,m,g,h}; char *sbrk();main(){t*e,*p,*o; o=f(),o->c=o,o->b=1,e=f(), e->a=2,p=e->c=f(),p->b=2, p->c=o,q(e),e=e->c,(void)write (1,"2.",2);for(;;e=e->c){q(e), e->b=write(1,&e->b["0123456789"], 1);}}t*f(){return i||(i=1000, k=(t*)sbrk(i*sizeof(t))),k+--i; }q(p)t*p;(*y[p->a])(p);} I am using Windows7. |
Re: Using the Standard Template Library (STL) vector might make your life easier. ![]() | |
Re: Without thinking ... mylist = [0, 3, 6, 8, 8, 5, 2, 0, 7, 1, 9, 5, 0, 7, 7, 4, 2] s = "" n = 1 for ix, k in enumerate(mylist): if ix == n: s += ' ' n += 4 s += str(k) print(s) # 0 … | |
Re: subprocess.call() might do | |
Just wanted to know if anyone on DaniWeb is using or at least experimenting with Go. | |
Re: Also notice that the information returned resides in named tuples. | |
Re: Have you seen any "dark matter" lately? Actually you can only see the "dark matter effect" as it distorts light through gravitation. When two galaxies collide their shape will change, but the shape of the "dark matter effect" will stay the same. Some newer discoveries ... http://www.bbc.com/news/science-environment-32066013 So, what is … | |
Re: What have you coded so far? | |
Re: On first glance look at the items with the highest tottime values. Then check the number of calls and the percall time. Remember that function calls are expensive because of the overhead. | |
Re: You need to study up on your while loops. | |
Re: I have found plenty of ads that are a lot better then the TV show. | |
Re: An oldy but goody: Age of Empires II I find it very relaxing, yet challenging. | |
The Tkinter GUI toolkit's canvas object is very nice for all sorts of drawings and plotting. However, when it comes to saving the image Tkinter limits you to postscript printer files. One solution is to draw the same image in parallel on PIL's image-draw object in memory. This is made … | |
Re: I usually go for the lightest weight possible. | |
Re: Might be hidden in the Javascript section of the page. Not everything is straight HTML. | |
Re: Hmm ... import textwrap mylist = [83, 111, 109, 101, 119, 104, 101, 114, 101, 32, 105, 110, 32, 108, 97, 32, 77, 97, 110, 99, 104, 97, 44, 32, 105, 110, 32, 97, 32, 112, 108, 97, 99, 101, 32, 119, 104, 111, 115, 101, 32, 110, 97, 109, … | |
Re: The problem with Google is that they keep track of who is searching for what. Let's say you are looking for a brand of shoe, soon after you get shoe sales sending you e-mails. | |
Re: The lack of communication between Microsoft's different departments seems to be obvious. It is my distinct feeling that Microsoft never liked Python, so they put it in Irons. Years ago Microsoft tried to take over Java, this might have been an attempt to take over Python. | |
Re: Just a wild guess, look into Jython. | |
Re: Another thing to watch out for is the value of the Enter key. On Windows it is '\r\n' on Linux it is '\n'. I have seen this giving strange skip effects with the Go language. | |
Re: @snippsat good explanation! | |
Re: @snippsat, nice solution! | |
Re: Your keys have to be adjusted for the removed spaces ... class MessageEncoder: '''change the order of spaces in a text''' def __init__(self): pass def get_key(self): '''create and return the space char index key''' return ':'.join(str(ix) for ix, c in enumerate(self.text) if c==' ') def remove_space(self): '''return a list of … | |
We have had several snippets on the format() function. This one gives a condensed overview of the many options you have. | |
Re: I enjoy hiking in the nearby Sierra Nevada mountains, even on Friday the 13th. | |
| |
Re: Not counting reading the financial and international news on my iPad, I would say 3 to 4 hours. | |
Re: You are better off drawing three triangles ... ''' turtle_triangle_up.py use Python module turtle to draw a triangle pointing up draw three triangles and fill with different colors ''' import turtle as tu tu.title("triangle up") def triangle_up(x, y, side, color='black'): """ draw an equilateral triangle of size side starting at … | |
Re: It's been a while since I used wxPython, so thank you for the solution. | |
A very basic pygame sprite example. Moving a sprite with the arrow keys, could be the start of a great space game. | |
Re: A note to coding style: In just about all computer languages programmers try not to exceed about 80 characters per line of code. You could add your comments above the code line to help out, otherwise word wrap makes code pretty hard to read and understand. Again, there are a … | |
Re: Try ... sf = "For {} Root floor: {}, Ceiling: {}" n = 91 print(sf.format(n, math.floor(n**0.5), math.ceil(n**0.5))) n = 161 print(sf.format(n, math.floor(n**0.5), math.ceil(n**0.5))) | |
Re: @BustACode we just want to help you with your coding style. Python was written for readability, so yes PEP 8 is good to follow. See ... https://www.python.org/dev/peps/pep-0008/ Also, don't use unnecessary imports. They just clutter your code and are somewhat misleading. Remember ... import this The Ninja IDE helps you … |
The End.