Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
它得到的总和是正确的,但不是平均值。任何帮助都会很棒。
sum=0 for i in range(12): score_i=int(input('What is the score of exam %s: ' %(i+1))) sum=sum+score_i avg=sum/12 print(avg)
尝试添加小数点avg=sum/12.
avg=sum/12.
首先,sum是 Python 中的内置函数。您不应该将其用作变量。
sum
随着avg=sum/12您将整数除以整数,这在 Python 2 中给出了答案。
avg=sum/12
avg = sum/12.0应该产生预期的结果。
avg = sum/12.0