Jump to content
xisto Community
Sign in to follow this  
lloydg

Fib Gen In Python

Recommended Posts

OK this is one of my first programs..

from Tkinter import *

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 + 1root = 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
Notice from jlhaslip:
bbcode tags are needed on code snippets

Share this post


Link to post
Share on other sites

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:

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 variabledef 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 + 1fib_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()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.