Python Loops
💡
Exercise 20

99 Bottles 15 XP Medium

Ctrl+Enter Run Ctrl+S Save

"99 Bottles of Milk on the Wall" is a classic counting song. Let's code it!

The range() function can count backwards with a negative step:

for i in range(5, 0, -1): print(i) # Output: 5, 4, 3, 2, 1

The three arguments are: range(start, stop, step). The stop value is excluded.

📋 Instructions
Print a countdown from 5 to 1, followed by 'No more bottles!': ``` 5 bottles of milk on the wall. 4 bottles of milk on the wall. 3 bottles of milk on the wall. 2 bottles of milk on the wall. 1 bottles of milk on the wall. No more bottles! ``` Use `range(5, 0, -1)` and an f-string inside the loop.
Use for i in range(5, 0, -1): with print(f'{i} bottles of milk on the wall.'). After the loop, print 'No more bottles!'.
⚠️ Try solving it yourself first — you'll learn more!
for i in range(5, 0, -1):
    print(i)
# Output: 5, 4, 3, 2, 1
🧪 Test Cases
Input
Run your code
Expected
5 bottles of milk on the wall. 4 bottles of milk on the wall. 3 bottles of milk on the wall. ...
Expected output (6 lines)
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.