Lesson 6 of 18 · about 15 minutes
Loops 🔁
Loops repeat work so you do not have to. Python has two kinds.
for: go through each item
for planet in ["Mercury", "Venus", "Earth"]:
print(planet)
for i in range(5): # 0,1,2,3,4
print(i)
for i in range(1, 11, 2): # 1,3,5,7,9
print(i)
while: repeat until a condition changes
fuel = 3
while fuel > 0:
print("Burning fuel:", fuel)
fuel -= 1
print("Liftoff!")
break and continue
for n in range(10):
if n == 3:
continue # skip 3
if n == 6:
break # stop entirely
print(n)
enumerate: index and value together
for i, letter in enumerate("abc"):
print(i, letter)
⚠️ A
while loop whose condition never becomes False runs forever. Always change something inside it.Your challenge
Print the multiplication table for 7, from 7 x 1 = 7 up to 7 x 5 = 35, one per line, in exactly that format.