My assignment is to add up a series of numbers using a loop, and that loop requires the sentinel value of 0
for it to stop. It should then display the total numbers added. So far, my code is:
total = 0
print("Enter a number or 0 to quit: ")
while True:
number = int(input("Enter a number or 0 to quit: "))
print("Enter a number or 0 to quit: ")
if number == 0:
break
total = total + number
print ("The total number is", total)
Yet when I run it, it doesn't print the total number after I enter 0
. It just prints "Enter a number or 0 to quit"
, though it's not an infinite loop.