#!/usr/bin/env python # Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) # # This work is licensed under the Creative Commons Attribution-NonCommercial- # ShareAlike License. To view a copy of this license, visit # http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to # Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, # 94105, USA. import sys def fibonacci(n): if n <= 0: return -1 fib = 1; prev_fib = 1 for i in xrange(2,n): (fib, prev_fib) = (fib+prev_fib, fib) return fib if len(sys.argv) != 2: print >>sys.stderr, \ "Usage:\n\t%s (n-th fibonacci # to calculate)\n" % (sys.argv[0]) sys.exit(-1) n = int(sys.argv[1]) print "fibonacci(%d): %d" % (n, fibonacci(n))