我正在嘗試製作一個計算用戶輸入年級的成績平均值的計算程序,然後將輸入與字典進行比較。這是我的代碼,我相信什麼是錯的。python dictonary和if語句
def average(g1):
dic = {"a": [4.],"A": [4.],"A-": [3.66],"a-": [3.66],"B+":[3.33], "b+": [3.33],"B": [3.],"b": [3.],"B-": [2.66], "b": [2.66],"C+": [2.33],"c+": [2.33],"C": [2.],"c": [2.], "D+": [1.66],"d+": [1.66],"D": [1.33],"d": [1.33],"D-": [1.], "d-": [1.],"F": [.66]}
for key in dic.keys():
if g1 in dic.keys:
print ("hello")
g1 = raw_input("Please enter grade 1: ")
average(g1)
是什麼讓你覺得有什麼不對?當你運行它會發生什麼?它與你的預期有什麼不同? – skrrgwasme
'對於dic.keys()中的關鍵字:'你認爲這樣做了什麼? 'dic.keys'你認爲這有什麼用? – njzk2