这里是我的回答:
def numberTest():
global x, y, z
L1 = []
x = 0
y = 6
z = 1
while(x < 6):
try:
user = int(input("Enter {0} more number(s)".format(y)))
print("Your entered the number {0}".format(user))
x += 1
y -= 1
L1.append(user)
except ValueError:
print("That isn't a number please try again.")
while(z > 0):
numb = input("Type \"total\" for the total and \"average\"").lower()
if(numb == "total"):
a = sum(L1)
print("Your total is {0}".format(a))
z = 0
elif(numb == "average"):
b = sum(L1)/ len(L1)
print("Your average is {0}".format(round(b)))
z = 0
else:
print("Please try typing either \"total\" or \"average\".")
numberTest()
我想这几次,我知道它的工作原理。如果您对部分代码感到困惑,我会添加评论并回答更多问题。
'sum(list)',但是请不要命名你的列表'list',因为这是一个内置类型。 – smarx
不是说你有[mcve],但我敢打赌'numb1 = numb.lower'不会做你认为它的作用。 – jonrsharpe