我正在尝试制作一个程序,从用户那里获取 5 个整数,然后找到它们的平均值。我已将其设置为接收 5 个数字,但是如何将它们全部作为单独的变量返回,以便以后可以使用它们?谢谢!
def main():
x = 0
testScoreNumber = 1
while x < 5:
getNumber_0_100(testScoreNumber)
x += 1
testScoreNumber += 1
calcAverage(score1, score2, score3, score4, score5)
print(calculatedAverage)
def getNumber_0_100(testnumber):
test = int(input("Enter test score " + str(testnumber) + ":"))
testcount = 0
while testcount < 1:
test = int(input("Enter test score " + str(testnumber) + ":"))
if test > 0 or test < 100:
testcount += 1
return test
^这是问题所在,每次运行此函数时,我都希望它向不同的变量返回不同的值。前任。测试1,测试2,测试3。
def calcAverage(_score1,_score2,_score3,_score4,_score5):
total = _score1 + _score2 + _score3 + _score4 + _score5
calculatedAverage = total/5
return calculatedAverage