← Back to Basics

Coin Hunt

5 of 8

Exercise 6: Coin Hunt πŸ’°

πŸ”„ While Loops

Your Task

Part A: Start with 0 coins. Use a while loop to add 20 coins at a time until you have 100+. Print coins each time.

Part B: Start with 0 coins. Loop forever asking "Collect or stop?". If "collect", add 25 coins. If "stop", break. Print total at the end.


Example Output

=== Part A ===
20
40
60
80
100
Done! 100 coins

=== Part B ===
Collect or stop? collect
25 coins
Collect or stop? collect
50 coins
Collect or stop? stop
Final: 50 coins

Input Lines (for browser)

collect collect stop

Try it yourself

Code: Coin Hunt

Loading Python runtime…
Python …
Loading...
bash
$ Click "Run" to execute your code...