+ 1

I need some explain please

Ok im in the project call "Fibonacci" from python and this is the question: 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. So i did my code like this(im from Argentina that is why the variable's names are in spanish): numero_ingresado = int(input()) def fibonacci(numero_ingresado): if numero_ingresado<=1: return 1 else: crear_lista=list(range(numero_ingresado)) for numero_ingresado in crear_lista: print(numero_ingresado) llamar_a_funcion=fibonacci(numero_ingresado) print(llamar_a_funcion) My problem is that my output is: 0 1 2 3 4 None When it should be: 0 1 1 2 3 And i'd like to know how can i erase the "none" and make the code right,sorry if i am asking too much,its hard for me because i cant study all the week and when i can i tried to learn all i can .Thanks everyone that can help me.

24th Jan 2021, 1:18 AM
Melissa Franco
Melissa Franco - avatar
3 Respostas
+ 1
None is outputed by your last (global) print statement because you doesn't return anything from your fibonnacci function appart for numero_ingresado<=1... Numbers are outputed from your fibonnacci function, if numero_ingresado>1, but you only print the range between 0 and it (0 inclusive, max exclusive) without doing any logic to compute the fibonnacci terms ^^
24th Jan 2021, 1:41 AM
visph
visph - avatar