#This program generates a Fibonacci series based on user input i=1 #Defines i to be zero i4=1 i1=1 #Starting number i2=1 #Starting number n=int(input("how many interations would you like? ")) #Asks user for integer input print(i1) #Prints starting number print(i2) #Prints starting number print(i4) while (i<=(n-3)): #Defines when to perform the sequence i3=i1+i2+i4 #Adds the two previous numbers and makes that the next print(i3) #Prints i3 which is i1+i2 i1=i2 #Continues the sequence so that i1 is now i2 i2=i4 #Continues the sequence so that i2 is now i3 i4=i3 i=i+1 #Next integer is integer + 1 print("all done") #Prints "all done" to show that the sequence has ended
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question