1def fib(num):
2 a = 0
3 b = 1
4 for i in range(num):
5 yield a
6 temp = a
7 a = b
8 b = temp + b
9
10
11for x in fib(100):
12 print(x)
13
14
15def fib2(num): # Creates fib numbers in a list
16 a = 0
17 b = 1
18 result = []
19 for i in range(num):
20 result.append(a)
21 temp = a
22 a = b
23 b = temp + b
24 return result
25
26
27print(fib2(100))
28
1number1 = 0
2print('1:', number1)
3number2 = 1
4for count in range(2, 101):
5 print(count, ':', number1 + number2)
6 number1 += number2
7 number2 = number1 - number2
1#Learnprogramo
2Number = int(input("How many terms? "))
3# first two terms
4First_Value, Second_Value = 0, 1
5i = 0
6if Number <= 0:
7print("Please enter a positive integer")
8elif Number == 1:
9print("Fibonacci sequence upto",Number,":")
10print(First_Value)
11else:
12print("Fibonacci sequence:")
13while i < Number:
14print(First_Value)
15Next = First_Value + Second_Value
16# update values
17First_Value = Second_Value
18Second_Value = Next
19i += 1