1
Count to 5
Use a for loop to print numbers from 1 to 5. Each number on a new line.
Loops repeat code multiple times.
FOR loop - for a specific number of times:
for i in range(5):
print(i) # Prints 0, 1, 2, 3, 4
range(5) gives numbers from 0 to 4.
range(1, 6) gives numbers from 1 to 5.
WHILE loop - while condition is true:
count = 0
while count < 3:
print(count)
count = count + 1 # or count += 1
Use a for loop to print numbers from 1 to 5. Each number on a new line.
Use a for loop to print "Hello" exactly 3 times.
Calculate the sum of numbers from 1 to 10 using a loop. Store result in 'total' and print it. Expected result: 55
Use a while loop to print numbers from 1 to 5.