+ 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
14 Antworten
+ 2
do you know how can I add a zero at the beginning though?
+ 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))
+ 3
+ 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......
+ 3
you're welcome
+ 3
u will have to print the first two elements that is 0 and 1 directly before the loop
+ 2
You didn't call the function.
+ 2
I have called in the print statement
+ 2
You wrongly indented the print and the return like Paul Jacobs has mentioned.
+ 2
thanks S.C.
+ 2
you're welcome.
+ 2
brahmeswara rao Thanks for pointing it out!
+ 2
ok
+ 1
still not showing any O/P