Question
Fibonacci the Fibonacci sequence starts 1, 1, 2, 3, 5, 8 Each number in the sequence (after the first two) is the sum of the
Fibonacci the Fibonacci sequence starts 1, 1, 2, 3, 5, 8 Each number in the sequence (after the first two) is the sum of the previous two. Write a program called Fibonacci.py or Lab6a.py that computes and outputs the nth Fibonacci number, where n is a value entered by the user.
o Hint: use 3 variables, one to store the sum of the previous two numbers, one to print out each iteration of the loop (this number is initialized to 1, and another to save the number you print to the screen (this number is initialized to 0)
o How would you get the program not to print out the last comma (,)?
What we have:
print("This program computes a Fibonacci series") n = int(input("Please enter what term in the Fibonacci sequence you would like to know:")) x1 = 0 x2 = 1 x3 = 0 print(n, end=",")[1, 1, 2, 3, 5, 8, 13, 21, 34, 55,] for i in range(n): print(x2) x1 = x1 + x2 x1 = x2 x2 = x3
What code should return:
This program computes a Fibonacci series
Please enter what term in the Fibonacci sequence you would like to know:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55
Process finished with exit code 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started