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

Popular posts from this blog

Regex find and replace between <div class="customclass"> and </div> tag -

jpa - Passing entitymanager from reflection method -