mercredi 12 février 2020

Python - Using if statement, + while condition | Print integers, break when having digits

Question: Write a program to accept integer inputs until the user inputs a non‐integer. Then, the program prints the summation of the inputted numbers.

My code:

Total = 0
Count = 0
while True:
    n = input ('Enter integers')

    if (n.isdigit() == True):
        print (n)
    else:
        break
    n = int(n)    
    total = total + n
    count = count + 1
    sum = sum(total)

I could run the integers, but it fails to break when digits are typed... Anyone knows why? Also I am expecting the sum function to work but it couldn't add together the integers I input.

Thanks!

Aucun commentaire:

Enregistrer un commentaire