Problem with Fibonacci recursion

0

Hello, very recently we started with recursion and I do not understand it very much, they ask to create a program that makes the fibonacci succession but in several cases it gives me another value

#Fibonacci
def fibonacci(n):
    if n==1 or n ==0:
       return n
    else:
       return fibonacci(n-2)+ fibonacci(n-1)
numero =int (raw_input("Ingrese un numero entero positivo: "))
if numero < 0:
    print("Le dije que era un numero ENTERO POSITIVO")

 i = 0
 print("La sucesion Fibonacci es: ")
 for i in range (0,numero):
    print(fibonacci(i))       

That is my code, if you could tell me what I am failing I would thank you very much

    
asked by Wolf 16.10.2018 в 01:18
source

1 answer

0

I do not know how it would be in python, but I think you can use the logic of the code for what you need (is C):

int x=0,y=1,z=0,i;
for(i=1;i<=13;i++) {
z=y;
y=y+x;
cout<<y<<", ";
x=z;
}

Where and would represent the series. I hope it serves you.

    
answered by 16.10.2018 / 01:26
source