|
|
|
|
![]() ![]() |
Jun 12 2007, 08:37 AM
Post
#1
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 49 Joined: 11-June 07 From: Aus NSW sydney Member No.: 44,575 |
OK this is one of my first programs..
from Tkinter import * CODE def NextNumber(): count = 0 x = 0 y = 1 while count <= int(Range.get()): for item in [x]: listbox.insert(0, item) z = x x = z + y y = z count = count + 1 root = Tk() Title = Label(root, text = "Calculate fib number:") Title.pack() Range = Entry(root) Range.pack() PrintNextNumber = Button(root, text = " Display ", command = NextNumber) PrintNextNumber.pack() listbox = Listbox(root) listbox.config(selectborderwidth=1, height=1, width=50) listbox.pack() root.mainloop() what do you think of it??? inprovment? comment?... do i have any bad technecs or something?.. i know i havent put any comment in the code |
|
|
|
Oct 8 2007, 02:45 PM
Post
#2
|
|
|
Newbie [Level 2] ![]() ![]() Group: Members Posts: 28 Joined: 5-October 07 Member No.: 51,172 |
That's pretty cool. It would be easier if you didn't use a GUI, but it's still pretty simple. Personally I'd have done something more like:
CODE def fib_nums_1() #defining the function
count = 0 #We set the count variable to 0 as we have not yet done any production of the numbers a = 0 #Sets the first variable we require b = 1 #Sets the second necessary variable print b #We print the first of our numbers count = count + 1 #We add one to the count variable as we have processed and printed one fibonacci number c = a + b #We set the second number to be printed as the sum of the first two print c #Now we print it count = count + 1 #We add another one to the count variable def fib_nums_2() #Now we are defining the second function of our program a = c + b print a count = count + 1 b = a + c print b count = count + 1 c = b + a count = count + 1 fib_nums_1() while count != 100: #This obviously means that we will keep running the following code until the count variable is at 100, at which point we will have calculated and printed 100 fibonacci numbers fib_nums_2() |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 6th October 2008 - 07:16 PM |