- 3

Where am i wrong

Fibbonacci

24th Nov 2020, 4:06 AM
Thakkar Heer
Thakkar Heer - avatar
18 odpowiedzi
+ 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
24th Nov 2020, 4:21 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
You also don't need to end nearly every line with a colon. https://code.sololearn.com/c3DX0O0ws415/?ref=app
24th Nov 2020, 4:16 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
24th Nov 2020, 4:34 AM
Tibor Santa
Tibor Santa - avatar
+ 3
No worries, take it easy. Good thing you figured it out 😉
24th Nov 2020, 5:25 AM
Tibor Santa
Tibor Santa - avatar
+ 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.
24th Nov 2020, 4:14 AM
Tibor Santa
Tibor Santa - avatar
+ 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.
24th Nov 2020, 4:26 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
are you good with the indentation yet?
24th Nov 2020, 4:29 AM
AlTairTech
AlTairTech - avatar
+ 2
A fibonacci sequence by definition starts from 0, so not sure what your issue is. https://www.mathsisfun.com/numbers/fibonacci-sequence.html
24th Nov 2020, 4:35 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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
24th Nov 2020, 4:28 AM
Thakkar Heer
Thakkar Heer - avatar
+ 1
Sorry guys i solved it
24th Nov 2020, 5:23 AM
Thakkar Heer
Thakkar Heer - avatar
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))
24th Nov 2020, 4:06 AM
Thakkar Heer
Thakkar Heer - avatar
0
It is working but the output is same
24th Nov 2020, 4:24 AM
Thakkar Heer
Thakkar Heer - avatar
0
No
24th Nov 2020, 4:31 AM
Thakkar Heer
Thakkar Heer - avatar
0
Please give the answer of problem
24th Nov 2020, 4:32 AM
Thakkar Heer
Thakkar Heer - avatar
0
I was not putting correct indentations
24th Nov 2020, 5:23 AM
Thakkar Heer
Thakkar Heer - avatar
0
Sorry😭😭😭😭
24th Nov 2020, 5:24 AM
Thakkar Heer
Thakkar Heer - avatar
- 1
Please help me i have posted my code
24th Nov 2020, 4:13 AM
Thakkar Heer
Thakkar Heer - avatar
- 1
Still it is not solving
24th Nov 2020, 4:20 AM
Thakkar Heer
Thakkar Heer - avatar