functional programming in python | Sololearn: Learn to code for FREE!


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)

7/24/2021 6:16:59 PM

ndatinya justin

5 Answers

New Answer


ndatinya justin , what is your question ?


Thank you so much ,now it's working


My code is not running


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)


For input(5) I'm getting 013 ,in fact I should get 01123 ,so the code is not correct , thanks