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:
                x = int(input("Value : "))
                if x == 0:
                sum += x
                x = ""
                x = ""
                print ("Please enter a number !")

print ("Result : ", sum)

Browse More Popular Posts

Leave a Comment