Practice · Python

Practice while Loops

Repeat work with a while loop driven by a changing condition, and guarantee the loop terminates.

while Loopswarming python…

Level‑by‑Level Game Score

You are given a list level_enemies where each element represents the number of enemies in a video‑game level. The player earns 10 points per enemy. The game stops as soon as a level contains 0 enemies (the player quits). Write a function that returns the total points earned. If the list is empty, return 0.

Examples

calculate_total_score([3, 4, 2])   #  (3+4+2)*10 = 90
calculate_total_score([5, 0, 7])   #  stops at 0, only 5*10 = 50
calculate_total_score([])          #  0
Press Run to see output, or Check to grade against the tests.

Want a whole course built around while loops?

Start my path — free

Adaptive practice, streaks, projects with real code review. Free tier gates AI help, never content.