- 3
Where am i wrong
Fibbonacci
18 Respostas
+ 3
Your working code here
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1)+recur_fibo(n-2))
nterms=10
if nterms<=0:
print("please enter a positive integer")
else:
print("fibonacci sequence")
for i in range(nterms):
print (recur_fibo(i))
Indentation problems and colons at the end of lines 3,5,9,11 were causing the problem
+ 3
You also don't need to end nearly every line with a colon.
https://code.sololearn.com/c3DX0O0ws415/?ref=app
+ 3
THAKKAR HEER two people have already posted working solutions. And YOU still have not linked your own code. How do you expect people to help you figure out what is wrong in your code, if we can't see it? We are not mind readers.
+ 3
No worries, take it easy. Good thing you figured it out 😉
+ 2
Indentation.
You need to align the beginning of the rows correctly with whitespace, so that python understands the block structure of your code.
You'd better save it on code playground and provide a link here, it will be easier for people to help.
+ 2
What do you mean the output is the same? It's a fibonacci sequence it should always be the same sequence up to a given number of iterations.
+ 2
are you good with the indentation yet?
+ 2
A fibonacci sequence by definition starts from 0, so not sure what your issue is.
https://www.mathsisfun.com/numbers/fibonacci-sequence.html
+ 1
I mean in the question the output is not fibonacci sequence and starts from 0 but in my output is fibonacci and then starts from 0
+ 1
Sorry guys i solved it
0
def recur_fibo(n):
if n<= 1:
return n:
else:
return(recur_fibo(n-1)+recur_fibo(n-2)):
nterms=10
if nterms<=0:
print("please enter a positive integer"):
else:
print("fibonacci sequence"):
for i in range(nterms):
print (recur_fibo(i))
0
It is working but the output is same
0
No
0
Please give the answer of problem
0
I was not putting correct indentations
0
Sorry😭😭😭😭
- 1
Please help me i have posted my code
- 1
Still it is not solving