Skip to content

Instantly share code, notes, and snippets.

@jjst
Created November 8, 2015 19:44
Show Gist options
  • Save jjst/87d738c12262f9d8bdd5 to your computer and use it in GitHub Desktop.
Save jjst/87d738c12262f9d8bdd5 to your computer and use it in GitHub Desktop.
fibonacci recursive
def fibonacci(n):
if n == 0:
print "finobacci(0) = 0"
return 0
elif n == 1:
print "finobacci(1) = 1"
return 1
else:
print "fibonacci(%s) = fibonacci(%s) + fibonacci(%s)" % (n, n-1, n-2)
return fibonacci(n-1) + fibonacci(n-2)
user_input = int(raw_input("Please enter a non-negative integer here:"))
while user_input >= 0:
print fibonacci(user_input)
user_input = int(raw_input("Please enter a non-negative integer here:"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment