Command Palette

Search for a command to run...

Hectal
Phase 2: Control Flow
Python · Exercise 2 of 6 PreviousNext
Beginner

Add numbers until a zero appears

The list data ends its real numbers at the first 0. Use a while loop to add up the numbers before the first 0 into the variable total.

Print the line Total: followed by the total. The list always contains a 0.

What Check tests

  1. [5, 10, 0, 7] gives a total of 15
  2. [3, 4, 0, 9] gives 7
  3. [0, 5] gives 0
  4. Your code uses a while loop
  5. The program prints Total: 15

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.