zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python二级练习(6)

Python 练习 二级
2023-09-14 09:16:25 时间

6. 从键盘接收一百分制成绩(0~100),要求输出其对应的成绩等级A~E。其中,90分以上为'A',80~89分为'B',70~79分为'C',60~69分为'D',60分以下为'E'。

#python 3.6
#蔡军生 
#http://blog.csdn.net/caimouse/article/details/51749579
#

dictionary = {90:'A', 80:'B', 70:'C', 60:'D', 0: 'E'}

score = int(input('请输入成绩(0~100):'))
if score > 100 or score < 0:
    print('输入错误成绩')
else:
    for key in sorted(dictionary.keys(),  reverse = True):
        if score >= key:
            print('成绩为', dictionary[key])
            break
输出结果:



========== RESTART: D:/work/example/py_ex_006.py ==========
请输入成绩(0~100):60
成绩为 E
>>> 
========== RESTART: D:/work/example/py_ex_006.py ==========
请输入成绩(0~100):70
成绩为 C
>>> 
========== RESTART: D:/work/example/py_ex_006.py ==========
请输入成绩(0~100):1010
输入错误成绩
>>> 

深入浅出Matplotlib
https://edu.csdn.net/course/detail/6859

深入浅出Numpy
http://edu.csdn.net/course/detail/6149 

Python游戏开发入门