Created
April 13, 2021 11:12
-
-
Save cristinelpopescu/b0c98bdd6f55e69c5a7ef873b703e55c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# fibonacci - generator | |
def fib(number): | |
a = 0 | |
b = 1 | |
for i in range(number): | |
yield a | |
temp = a | |
a = b | |
b = temp + b | |
for x in fib(20): | |
print(x) | |
# fibonacci - list | |
def fib2(number): | |
a = 0 | |
b = 1 | |
result =[] | |
for i in range(number): | |
result.append(a) | |
temp = a | |
a = b | |
b = temp + b | |
return result | |
print(fib2(20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment