#This program generates a Fibonacci series based on user unput i=1 #Defines number to be zero i1=1 #Defines the first starting number i2=1 #Defines the second starting number i3=1 n=int(input("how many interactions would you like? ")) #Asks the user for integer input print(i1) #Prints the first number in the sequence print(i2) #Prints the second nummber in the sequence print(i3) while (i<=(n-3)): #while i is less than or equal to the input minus 2 i4=i1+i2+i3 #means that the third two term is the sum of the previous two terms print(i3) i1=i2 #defines the variable i1 as the previous value of i2 i2=i3 #defines the variable i2 as the previous value of i3 i3=i4 i=i+1 #means that the next integer is the previous interger plus 1 print("all done")
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