Created
January 4, 2015 03:31
-
-
Save RussellAndrewEdson/f4af5aa8119190a9d98c to your computer and use it in GitHub Desktop.
Python code to generate the nth Fibonacci number iteratively.
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
# Calculates the nth Fibonacci number using an iterative process. | |
def fibonacci(n): | |
(current, next) = (0, 1) | |
index = 0 | |
while (index < n): | |
(current, next) = (next, current + next) | |
index += 1 | |
return current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment