Stuck with this

Here is a more robust way to input the number. It check if it can be added. Moreover I added the positive and negative number.

# -*-coding:Utf-8 -*

print ("Keep inputting numbers different than 0 and each one will be added together consecutively.") 
print ("Enter a and the total will be displayed on the screen. Have fun.")

sum = 0
x = ""

while type(x) == str:
        try:
                x = int(input("Value : "))
                if x == 0:
                        break
                sum += x
                x = ""
        except:
                x = ""
                print ("Please enter a number !")

print ("Result : ", sum)

Leave a Comment