# File: rfib.py
# Program to compute the first n numbers of the Fibonacci series recursively
#
# Matt Bishop, ECS 36A, Winter 2019
#
# 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))
#
# and away we go!
#
main()