#This program generates a Fibonacci series based on user input i=1 #Define i to be 1 i1=1 #Define i1 to be 1 i2=1 #Define i2 to be 1 i3=1 #Define i3 to be 1 n=int(input("how many interations would you like?")) #Ask the user for integer input print(i1) #print the first number print(i2) #print the second number print(i3) #print the third number while (i<=(n-2)): #Loop i4=i1+i2+i3 #The third number equals to the sum of first two print(i4) #print the third number i1=i2 #Give the value of i2 to i1 i2=i3 #Gve the value of i3 to i2 i3=i4 #Gve the value of i4 to i3 i=i+1 #Goes to the next loop print("all done") #Print
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