编写一个基本的数学程序来帮助我理解 python 数学计算。
如果我写
x = 15 + 30 + 45
print(x)
我明白了
90
如果我写
x = 90 / 3
print(x)
我明白了
30.0
但如果我写
def avg3():
print("This program will calculate the average of 3 scores")
scores = eval(input("enter 3 scores: "))
average = scores[0] + scores[1] + scores[2] / 3
avg = str(average)
print("The average of the input scores is " + avg + ".")
avg3()
并输入
15, 30, 45
返回的是
The average of the input scores is 60.0.
当然,我期待 30 岁。这是怎么回事?