# fibfun.py # Neal Nelson # # Fibonacci calculation using a for loop from Chapter 3 (Ch3p16). # Note the handy use of simultaneous assignment from Chapter 2 p36. # # This version uses a separate function (Chapter 6) to compute the fib (Ch6p7). # def fib(n): fibold = 1 fibnew = 1 for i in range(2,n): fibnew, fibold = fibold + fibnew, fibnew return fibnew def main(): n = input("Fibonacci calculator - enter a positive number: ") print "That Fibonacci number is: ", fib(n) main()