Skip to content

Instantly share code, notes, and snippets.

@HarryCoops
Last active August 29, 2015 14:25
Show Gist options
  • Save HarryCoops/4f58340f66657dfc7f45 to your computer and use it in GitHub Desktop.
Save HarryCoops/4f58340f66657dfc7f45 to your computer and use it in GitHub Desktop.
# generator function for the fibonacci sequence
def fibonacci():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
def main():
term = int(input('nth term:'))
for index, i in enumerate(fibonacci()):
if index <= term:
print(i)
else:
break
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment