while loop adds up the digits of a number, from the right. The loop has a break and an else block.
n = 2025
total = 0
while n > 0:
total += n % 10
n //= 10
if total > 6:
break
else:
print("all digits", end=" ")
print(total, n)
What does the program print?Log in to join the discussion.
Loading…