# File: fib.py # Author: Dr. Gibson # Date: 4/23/2017 # Section: N/A # E-mail: k.gibson@umbc.edu # Description: # This file contains python code that recursively implements # the Fibonacci sequence. FIB_FIRST = 0 FIB_SECOND = 1 def fib(position): # BASE CASES: first two Fibonacci positions if position == 1: return FIB_FIRST elif position == 2: return FIB_SECOND # RECURSIVE CASE: there are lower positions that we must # know before we can calculate this one else: # RECURSIVE CALL(S) return fib(position - 1) + fib(position - 2) def main(): position = int(input("What position of Fibonacci do you want? ")) answer = fib(position) print("The", position, "th position of Fibonacci is", answer) main()