Python练习实例015

问题:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-90分之间的用B表示,60分以下的用C表示。

#! /usr/bin/env python3
# -*- coding:utf-8 -*-

# Author   : Ma Yi
# Blog     : http://www.cnblogs.com/mayi0312/
# Date     : 2020-06-18
# Name     : demo015
# Software : PyCharm
# Note     : 利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-90分之间的用B表示,60分以下的用C表示。


# 入口函数
if __name__ == '__main__':
    score = int(input("Please input the score(0-100):"))
    if score > 100 or score < 0:
        print("Input score Error.")
    else:
        if score >= 90:
            print("%d Score is A" % score)
        elif score >= 60:
            print("%d Score is B" % score)
        else:
            print("%d Score is C" % score)

运行结果:

Please input the score(0-100):89
89 Score is B

Please input the score(0-100):93
93 Score is A

Please input the score(0-100):120
Input score Error.

Please input the score(0-100):56
56 Score is C
原文地址:https://www.cnblogs.com/mayi0312/p/13158787.html