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

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 Если вы составляете последовательность Фибоначчи для n чисел, то вам нужно использовать условие n<=1 в качестве базового случая.

14th Dec 2021, 10:05 AM
Ксенія Мельничук
3 Answers
+ 1
num = int(input()) def fibonacci(n): #завершите рекурсивную функцию if n <= 1: return 0 else: x, y = 1, 0 for i in range(n): x, y = y, x+y print(x) fibonacci(num)
25th Nov 2022, 1:39 PM
Yevhen Lovkin
Yevhen Lovkin - avatar
0
О, помню это задание. 2 дня мучалась, но всё-таки сделала. Читайте матешу. Это поможет понять, как цикл сделать
14th Dec 2021, 11:42 AM
Ірина Скрипник
Ірина Скрипник - avatar
0
Inp= int(input("enter ") a=0 b=1 Print(a) Print(b) For i in range(Inp-2): C=a+b Print(c) a=b b=c
16th Dec 2021, 3:40 AM
Sonali Kala
Sonali Kala - avatar