Displaying a fibonacci series[PYTHON] -
n=input('enter number of terms') a=1 print b=1 print b in range(1,n+1): c=a+b print c b=c a=b
this code learnt in school displaying fibonacci sequence. reason im getting wrong output--
output
enter number of terms5 1 1 2
can please tell me wrong?
indentation critical in python :
n=input('enter number of terms') a=1 print b=1 print b in range(1,n-1): c=a+b print c a=b b=c
your last 3 lines weren't part of loop, , last 2 of them wrong way round.
edit : range adjusted print requested number of items.
Comments
Post a Comment