python 利用条件运算符:学习成绩>=90分用A表示,60-89分之间的用B表示,60分以下的用C表示。

一、参考解法:

score = int(input('输入分数:'))
print("A" if score>89 else('B' if score>59 else 'C'))

二、参考解法:

while 1:
    score = int(input('输入分数:'))
    mark = [90,60,0]
    result=['A','B','C']
    for i in range(0,3):
        if score>=mark[i]:
            print('%d属于:%s'%(score,result[i]))
            break

三、参考解法:

def grade(score):
    if score >=90:
        print("A")
    elif score>=60:
        print("B")
    else:
        print("C")
while 1:
    score = int(input('输入分数:'))
    grade(score)

 

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注