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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM