python从键盘输入10名学生的成绩(用浮点数表示),进行优,良,及格和不及格人数的统计,并输出

从键盘输入10名学生的成绩(用浮点数表示),进行优,良,及格和不及格人数的统计,并输出

scores = []  # 定义一个空列表存放学生成绩
excellent, good, pass_num, fail_num = 0, 0, 0, 0  # 初始化优、良、及格和不及格人数

for i in range(10):
    score = float(input("请输入第{}个学生的成绩: ".format(i+1)))
    scores.append(score)  # 将输入的成绩存入列表中
    
    if score >= 90:
        excellent += 1
    elif score >= 80:
        good += 1
    elif score >= 60:
        pass_num += 1
    else:
        fail_num += 1
print("优秀人数:{},良好人数:{},及格人数:{},不及格人数:{}".format(excellent, good, pass_num, fail_num))

运行该代码后,程序会提示用户依次输入10名学生的成绩,并根据输入的成绩判断各个成绩段(大于等于90分为优,80-89分为良,60-79分为及格,小于60分为不及格)的人数,并输出到屏幕上。

excellent = 0
good = 0
passing = 0
fail = 0

for i in range(10):
    score = float(input())
    if score >= 90:
        excellent += 1
    elif score >= 80:
        good += 1
    elif score >= 60:
        passing += 1
    else:
        fail += 1

print("优%d" % excellent)
print("良%d" % good)
print("及格%d" % passing)
print("不及格%d" % fail)