Created
November 8, 2015 19:44
-
-
Save jjst/87d738c12262f9d8bdd5 to your computer and use it in GitHub Desktop.
fibonacci recursive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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