#This program generates a Fibonacci series basead on user input i=1 #Defines i to be 0 i1=1 #this defines the first starting number i2=1 #this defines the second starting number i3=1 n=int(input("how many iterations would you like? ")) #Asks the user for integer input print(i1) #this prints the first number in the sequence print(i2) #this prints the second number in the sequence print(i3) while (i<=(n-3)): #this says that you preform the series when i is less than or equal to n-2 i4=i1+i2+i3 #this says that the 3rd term is the first two terms added together print(i3) #this says that once it computes the 3rd term, it'll print it out i1=i2 #this says that the first two terms are equal i2=i3 #this continues the sequence i3=i4 i=i+1 #this says that next integer is up one print("all done") #this prints "all done" once it prints out all the numbers in the sequence that you asked for
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