参考代码如下:
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))