Saturday, 14 May 2011

Python program to print fibonacci series upto given number.

hi,

Today i made a python program that prints fibonacci series upto 'n'  number.

the code is....

#usr/bin/env python
inpnum=int(input("enter the limit : "))
fiblist=[]
a,b=0,1
while a<inpnum:
    fiblist.append(a)
    a,b=b,a+b

print str(fiblist).strip("[]")

i/p:

enter the limit : 100

o/p:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89

No comments:

Post a Comment