原题链接:http://www.runoob.com/python/python-exercise-example15.html
题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。
我的代码:
def fun(): score=int(input("please input the score:")) if score<60: grade="C" elif score<=89: grade="B" else: grade="A" print("%d is grade %s" %(score,grade))
这个if嵌套很容易,就不过多解释啦。