Lesson 7: Fibonacci sequence with for loop and list

posted Dec 5, 2019, 8:55 AM by Attila Lengyel
a = 1
b = 1
c = a + b
print(a,b,c)

a = b
b = c
c = a + b
print(c)

a = b
b = c
c = a + b
print(c)

print("I'm the while loop")
x = 0
while x < 10:
a = b
b = c
c = a + b
print(c)
x = x + 1

a = 1
b = 1
c = a + b
print("I'm the for loop")
for x in range(0,10):
a = b
b = c
c = a + b
print(x, ":", c)

print("I'm the list")
f = [1,1,2]
for x in range(0,11):
f.append(f[len(f)-1] - 2 * f[len(f)-2])
print(f)
Comments