Why the if statements doesnt work at the below? I just want if the values are number do the math, if the values are string except "Done" give me just "enter a number" warning and continue, if the value is "Done" finish the job and give me the answers.
quantity = 0
sum = 0
avg = 0
n = None
while n != "Done":
try:
n = int(input("Enter a value:\n"))
sum = sum + n
quantity = quantity + 1
avg = sum / quantity
except:
print("Enter a number!")
if n =="Done":
print("Process is Done!")
break
print("Sum : {}, Quantity : {}, Avg : {}".format(sum, quantity,avg))
Aucun commentaire:
Enregistrer un commentaire