+ 1

What's the error

my program for Fibonacci in Python is not showing any O/P nor any error.But I cannot find the bug...if anyone catches it please inform.I am inserting the code https://code.sololearn.com/cwLm85lIlDWl/?ref=app https://code.sololearn.com/cwLm85lIlDWl/?ref=app

16th Jul 2018, 2:39 PM
Ashita Udhani
Ashita Udhani - avatar
14 Réponses
+ 2
do you know how can I add a zero at the beginning though?
19th Jul 2018, 3:00 AM
Satyam
+ 4
I think the indention of line 15 and 16 (the last two lines) is wrong, it should be like this. def fibo(n): a=0 b=1 if(n<0): print("incorrect") elif(n==0): return a elif(n==1): return b else: for i in range(2,n): c=a+b a=b b=c return c print(fibo(9))
16th Jul 2018, 6:30 PM
Paul
Paul - avatar
17th Jul 2018, 4:26 PM
Satyam
+ 3
hello SC, I like to suggest to change c value to 1. Fibonacci series 1,1,2,3,.....or 0,1,1,2,3,5,8......
18th Jul 2018, 8:50 PM
Brahmeswara Rao
Brahmeswara Rao - avatar
+ 3
you're welcome
19th Jul 2018, 2:59 AM
Brahmeswara Rao
Brahmeswara Rao - avatar
+ 3
u will have to print the first two elements that is 0 and 1 directly before the loop
19th Jul 2018, 12:41 PM
Ashita Udhani
Ashita Udhani - avatar
+ 2
You didn't call the function.
16th Jul 2018, 4:40 PM
Satyam
+ 2
I have called in the print statement
16th Jul 2018, 6:24 PM
Ashita Udhani
Ashita Udhani - avatar
+ 2
You wrongly indented the print and the return like Paul Jacobs has mentioned.
17th Jul 2018, 2:29 AM
Satyam
+ 2
thanks S.C.
17th Jul 2018, 4:28 PM
Ashita Udhani
Ashita Udhani - avatar
+ 2
you're welcome.
17th Jul 2018, 4:29 PM
Satyam
+ 2
brahmeswara rao Thanks for pointing it out!
19th Jul 2018, 2:50 AM
Satyam
+ 2
ok
19th Jul 2018, 12:42 PM
Satyam
+ 1
still not showing any O/P
17th Jul 2018, 3:47 PM
Ashita Udhani
Ashita Udhani - avatar