參考代碼如下:
scores = list(map(lambda x:int(x),list(input('請輸入至少5個學生的成績(用空格分隔):').split(' '))))
maxScore = max(scores)
for s in scores:
if s >= maxScore - 10:
print('百分製成績為{},等級為:{}'.format(s, "A"))
elif s >= maxScore - 20:
print('百分製成績為{},等級為:{}'.format(s, "B"))
elif s >= maxScore - 30:
print('百分製成績為{},等級為:{}'.format(s, "C"))
elif s >= maxScore - 40:
print('百分製成績為{},等級為:{}'.format(s, "D"))
else:
print('百分製成績為{},等級為:{}'.format(s, "F"))
運行結果:
Ⅱ python如何求平均數
import numpy as np
score1=[23,44,67,51]
average=sum(score1)/len(score1)
print('平均數是:{}'.format(average))