編寫一個基本的數學程序來幫助我理解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這是怎麼回事
?
好吧,現在我真的覺得自己像個白癡:-)。感謝您清理蜘蛛網。 – kjarsenal