You would be better off using a list
to store the numbers. The below code is intended for Python v3.x so if you want to use it in Python v2.x, just replace input
with raw_input
.
print("Enter as many numbers you want, one at the time, enter stop to quit. ")
num = input("Enter number ").lower()
all_nums = list()
while num != "stop":
try:
all_nums.append(int(num))
except:
if num != "stop":
print("Please enter stop to quit")
num = input("Enter number ").lower()
print("Sum of all entered numbers is", sum(all_nums))
print("Avg of all entered numbers is", sum(all_nums)/len(all_nums))
sum
& len
are built-in methods on list
s & do exactly as their name says. The str.lower()
method converts a string to lower-case completely.