不好意思,最近有点忙,代码如下:
scores = list(map(int, input().split()))
max_score = max(scores)
for score in scores:
if score >= max_score - 10:
print('A')
elif score >= max_score - 20:
print('B')
elif score >= max_score - 30:
print('C')
elif score >= max_score - 40:
print('D')
else:
print('F')
你好!
首先,Python输入为input(),返回值为字符串,这个应该都知道。
其次,Python中字符串类型有个专有函数,叫split(),用于分割字符串,有两个参数:
list(map(int, input().split()))
其中,map(type, list)表示将list中所有元素转换为type类型,返回是一个迭代器,所以要用list将其转换为列表。
再用max(list)找出list中的最大数,一个一个判断即可。