99.6k views
4 votes
Does anyone know how to use a while loop and ask a user to input positive integers until the user enters 0 and print the sum so far after each input, then print final sum at the end in edhesive?

User Jrue
by
5.0k points

1 Answer

5 votes

In python:

total = 0

while True:

num = int(input("Enter a number: "))

if num == 0:

break

total += num

print(f"The final sum is {total}")

User Feroz Siddiqui
by
4.8k points