2017-08-15 23 views
-6
if score <=30: 
print = "You have scored:" + score + ":(" 

else score > = 31 and < = 60 
print = "You have scored:" + score + ":/" 

elif score < = 61 
print = "You have scored:" + score + ":)" 

我正在Python中的測驗,我需要它,這樣,當比分爲0-30,30-60和60+之間,顯示了不同的消息,雖然我試圖上面的代碼,它一直說無效的語法。Python的得分無效語法不會工作

+3

'elif的分數> = 31,得分=的<60'代替'別人得分> = 31,<= 60' – ettanany

+3

您還需要你的'elif'條件後冒號 – roganjosh

+0

繼續說無效語法 – user8469160

回答

-2
else score > = 31 and score <= 60 

需要是

elif score > = 31 and score <= 60: 

而你需要一個:添加到最後的elif了。而你的打印報告是錯誤的。語法是print 'hello'print('hello'),具體取決於python版本。你應該看看初學python語法的東西

+0

@kindall我只注意到原語的錯誤...... – dhdavvie

0

這是因爲score變量是一個整數,所以你不能像那樣打印它。試試這個,你打印的東西應該放在括號內,而不是「=」。在if語句之後還應該有一個「:」。試試這個:

if score <=30: 
    print("You have scored:" + str(score) + ":(") 

elif score >= 31 and score <= 60: 
    print("You have scored:" + str(score) + ":/") 

elif score <= 61: 
    print("You have scored:" + str(score) + ":)")