5. Write a second Python program to determine Fibonacci numbers. This program sh
ID: 3603437 • Letter: 5
Question
5. Write a second Python program to determine Fibonacci numbers. This program should include a recursive function to that finds the Fibonacci number of a given argument Fibonacci numbers were covered n class but if you are uncertain, look up some definition:s and examples on line. As always, be sure to include in your Lab Report citations to any sources of information you used while completing this lab exercise CS103 Laboratory Exercise 1 of 2 You may choose whether to allow a user to input a number, and find all of the Fibonacci numbers up to that point, or whether to simply hard-code into your program how many Fibonacci numbers to find. Either way, get your program running to find and display at least the first ten Fibonacci numbers, from the Fibonacci number of 1, which is 1, up to the Fibonacci number of 10, which is 89.Explanation / Answer
Hi
Below is the Python code-
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
nterms = int(input("How many terms? "))
if nterms <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.