# File: rfib.py
# Program to compute the first 20 numbers of the Fibonacci series
#
# Matt Bishop, ECS 10, Fall 2012
#
# get the nth Fibonacci number
#
def fib(n):
# base cases: f0 = 0, f1 = 1
if n == 0:
return 0
elif n == 1:
return 1
# recursion: fn = fn-1 + fn-2
return fib(n-1) + fib(n-2)
#
# main routine
#
def main():
# input number
try:
n = int(input("Fibonacci sequence from f0 to f: "))
except:
print("Need an integer")
return
# it better be non-negative!
if n < 0:
print("Need a non-negative integer")
return
# compute the sequence and print the terms
for i in range(n+1):
# get next Fibonacci number and
# announce it
print("Fibonacci number", i, "is", fib(i))
main()