Daily Python
Day 5Python~35 min
Loops
Repeat code with for and while
Track progress0/15 days
What you'll learn
forrange()whiletime.sleep()
- Loop with for and range()
- Repeat until a condition with while
- Build a countdown timer step by step
- Pause between prints with the time module
Lesson & examples
Read the code, then the explanation — try changing values before the project.
for loop with range
for i in range(5, 0, -1):
print(i)range(5, 0, -1) counts down: 5, 4, 3, 2, 1.
while loop
count = 0
while count < 5:
print(count)
count += 1Countdown with pause
import time
for i in range(10, 0, -2):
print(i)
time.sleep(2)
print("Happy New Year!")