求解答python问题

score=input("请输入成绩:")
score=int(score)
if score>=90:
print('A')
elif score>=80 and score<90:
print('B')
elif score>=70 and score<80:
print('C')
elif score>=60 and score<70:
print('D')
elif score<60:
print('F')
这个python程序出来只是一个分的等级,如:输入91,表现A
但是我想要的是输入一串成绩,比如输入76 59 78 88 10,然后显示出:
76:C
59:F
78:C
88:B
10:F
The End!
应该怎么修改这个程序?求解答。

首先,先帮你解决格式输出的问题:
输出10:E,对应的格式应为:

print("你的分数及相应等级为:%d:%c"%(score,'A'))

%d对应score,%c对应成绩等级

现在解决一次性输入多个score的问题,你可以创建一个列表,利用for循环及append()方法往列表中添加元素,然后对列表进行循环遍历执行if语句得到相应等级结果。
代码如下:

#score1=[76,59,78,88,10]
scoreList = []
for i in range(1,6):
    score = input("请输入成绩:")
    scoreList.append(score)
for score in scoreList:
    score = int(score)
    if score>=90:
        print("你的分数及相应等级为:%d:%c"%(score,'A'))
    elif score>=80 and score<90:
        print("你的分数及相应等级为:%d:%c"%(score,'B'))
    elif score>=70 and score<80:
        print("你的分数及相应等级为:%d:%c"%(score,'C'))
    elif score>=60 and score<70:
        print("你的分数及相应等级为:%d:%c"%(score,'D'))
    elif score<60:
        print("你的分数及相应等级为:%d:%c"%(score,'E'))

创建一个分数列表,往列表中加元素,循环判断结果,当然这个强制类型转换没有必要,%d也可换成%f

结果为:

img

望采纳

while True:
scores = input()
scores = scores.split(" ")
for score in scores:
s = int(score)
if s >= 90:
print(str(s) + ':A')
elif s >= 80 and s < 90:
print(str(s) + ':B')
elif s >= 70 and s < 80:
print(str(s) + ':C')
elif s >= 60 and s < 70:
print(str(s) + ':D')
elif s < 60:
print(str(s) + ':F')

76:C

59:F

78:C

88:B

10:F

The End!

搞定,望采纳

需要使我json区分空格然后生成数组,在用for遍历数组,进行判断。