- 1
functional programming in python
I've been asked to write a program which shows fibonacci numbers ,and i have a question on this, my code is def fib(n) a=0 b=1 print(a) print(b) for i in range (2,n): c=a+b a=b b=c print(c)
5 Respostas
+ 3
ndatinya justin ,
what is your question ?
+ 1
Thank you so much ,now it's working
0
My code is not running
0
Try this:
-------------------------
def fib(n):
A=0
B=1
C=0
i=0
while i<n:
if i==0:
print(A)
elif i==1:
print(B)
else:
C=A+B
print(C)
A=B
B=C
i+=1
-------------------------
pick a number for n and call fib(n)
- 1
For input(5) I'm getting 013 ,in fact I should get 01123 ,so the code is not correct , thanks