+ 1
How do I right a simple python code to print Fibonacci number up say 21?
Fibonacci program
3 Answers
0
Here is my python code:
https://code.sololearn.com/cRdvpVrWwP57/?ref=app
+ 5
https://code.sololearn.com/cbfGtdkZiI5s/?ref=app
+ 1
________________________________________________________
# 1 Prints array of fibonacci items:
def fibo(n):
a, b, arr = 0, 1, []
while b <= n:
arr.append(b)
a, b = b, a + b
return arr
print fibo(21)
________________________________________________________
# 2 This one is more basic. Prints numbers each one in the next line
def fibo(n):
a, b = 0, 1
while b <= n:
print b
a, b = b, a + b
fibo(21)