Skip to content

Commit

Permalink
add Fibonacci Generator Example
Browse files Browse the repository at this point in the history
  • Loading branch information
meleksabit committed Mar 30, 2022
1 parent 9cd3d2d commit d6b4bd5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Example generator which calculates fibonacci numbers:
# Generator version
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(100):
print(x)


# List version
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(100))

0 comments on commit d6b4bd5

Please sign in to comment.