Skip to content

while loops

Watch it run · 1 of 3

Add up the digits of 432

1n = 432
2total = 0
3while n > 0:
4 total += n % 10
5 n //= 10
6print(total)

Memory

int n

432

int total

0

Output

(nothing yet)

line 2Start.

step 1 of 10