Please help!!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help!!!

Please help!!! Fibonacci. The Fibonacci sequence is one of the most famous formulas in mathematics. Each number in the sequence is the sum of the two numbers that precede it. For example, here is the Fibonacci sequence for 10 numbers, starting from 0: 0,1,1,2,3,5,8,13,21,34. Write a program to take N (variable num in code template) positive numbers as input, and recursively calculate and output the first N numbers of the Fibonacci sequence (starting from 0). Sample Input 6 Sample Output 0 1 1 2 3 5 If you are making the Fibonacci sequence for n numbers, you should use n<=1 condition as the base case.

15th Dec 2021, 2:11 PM
Ксенія Мельничук
4 Answers
+ 1
num = int(input()) def fibonacci(n): if n <= 1: return n else : return fibonacci(n-1) + fibonacci(n-2) for n in range(num): print(fibonacci(n))
15th Dec 2021, 2:16 PM
Wellsie
Wellsie - avatar
+ 1
Thanks 👍😊
15th Dec 2021, 2:22 PM
Ксенія Мельничук
+ 1
A little convoluted maybe. Other version: def fibonacci(n): a,b = 0,1 for i in range(n): print(a) a,b = b,a+b Call fibonacci(n) where n is the number of iterations.
16th Dec 2021, 2:42 AM
Arnaud Brd
0
Дан код. num = int(input()) def fibonacci(n): #complete the recursive function fibonacci(num). Помогите завершить!!!
15th Dec 2021, 2:12 PM
Ксенія Мельничук