69.6k views
0 votes
The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, .. . . Each number in the se-quence (after the first two) is the sum of the previous two. Write a pro-gram that computes and outputs the nth Fibonacci number, where n is avalue entered by the user.

User Neilime
by
4.1k points

1 Answer

2 votes

Answer:

value=int(input("Enter the number up-to the user wants the Fibonacci series: "))

a=0

b=1

c=1

for x in range(value):

print(c,end=" ")

c=a+b

a=b

b=c

Output :

  • If the user input 5, then the output is "1 1 2 3 5".
  • If the user input 10, then the output is "1 1 2 3 5 8 13 21 34 55".

Step-by-step explanation:

  • The above defined a python program which is used for the Fibonacci series.
  • The first line of the program is used to instruct the user and take the input from the user.
  • Then the for loop executes up-to that range value.
  • Then in the for-loop, the two variable needs to store the current value and previous value which is used to give the series after addition.
User Arihant Nahata
by
4.9k points