一、题目:从键盘录入一个整数成绩,实现等级评比。如:90-100--->A,80-89--->B,70-79--->C,60-69--->D,0-59--->E,小于0 或大于100的数为非法数据(不是成绩的有效范围)
二、代码实现:
score=int(input('请输入一个成绩:'))
if score >= 90 and score <= 100:
print('A');
elif score >=80 and score <= 89:
print('B');
elif score >= 70 and score <= 79:
print('C');
elif score >=60 and score <= 69:
print('D');
elif score >=0 and score <= 59:
print('E');
else:
print('对不起,数据有误,不在成绩的有效范围')
tips:在python中,可以将if语句的条件语句写成if 90<=score<=100,此写法只在python中有效。