I made this calculator in python that should add whatever value i give it and store the results in a variable. Then if my input in something other than the numbers, it should print the results....It does not give any error, but it prints the results as 0. Why are the numbers not being added even though i clearly added them.
while True:
inpt = input("> ")
calc = 0
if inpt == "1":
calc += 1
elif inpt == "2":
calc += 2
elif inpt == "3":
calc += 3
elif inpt == "4":
calc += 4
elif inpt == "5":
calc += 5
elif inpt == "6":
calc += 6
elif inpt == "7":
calc += 7
elif inpt == "8":
calc += 8
elif inpt == "9":
calc += 9
else:
break
print(calc)
while
loop, you setcalc=0
. Just put thecalc=0
statement outside of the loop.