創建一個將數字作爲參數的函數,並根據該數字返回一個等級。做這個代碼的各種方法是什麼?
分數級
任何大於1或小於0.6 'F'
0.9或更大的 「A」
0.8或更大的 「B」
0.7或更大「C」
0.6或更大「D」
我想弄明白另一種寫這段代碼的方式,因爲解釋器不會接受它。有人可以幫助我嗎?
def grader(score)
if score >= 0.9
return "A"
elsif score >= 0.8
return "B"
elsif score >= 0.7
return "C"
elsif score >= 0.6
return "D"
elsif score < 0.5 or score > 1.01
return "F"
else
return "O"
end
end
你如何獲得'score'? –
*口譯員不會接受* *?你得到了什麼錯誤? –
哦,錯誤是,「價值不是預期的」。 – DonTerry