- 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)

24th Jul 2021, 6:16 PM
ndatinya justin
ndatinya justin - avatar
5 Respostas
+ 3
ndatinya justin , what is your question ?
24th Jul 2021, 7:24 PM
Lothar
Lothar - avatar
+ 1
Thank you so much ,now it's working
25th Jul 2021, 5:04 PM
ndatinya justin
ndatinya justin - avatar
0
My code is not running
24th Jul 2021, 8:54 PM
ndatinya justin
ndatinya justin - avatar
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)
26th Jul 2021, 6:25 PM
Proto
Proto - avatar
- 1
For input(5) I'm getting 013 ,in fact I should get 01123 ,so the code is not correct , thanks
25th Jul 2021, 12:17 PM
ndatinya justin
ndatinya justin - avatar