我是 python 新手,這是我的代碼,.lower 通??梢怨ぷ?,但這次不行。technical_dict = { dict : 'stores a key/value pair', list : 'stores a value at each index', map : 'see dict', set : 'stores unordered unique elements' } userInput = (input("What term would you like to lookup or type 'exit' to stop:")) if userInput.lower() not in technical_dict: print("Term does not exist in technical dictionary") if userInput.lower() in technical_dict: print(technical_dict[userInput.lower()]) while userInput.lower() != "exit": userInput = input("What term would you like to lookup or type 'exit' to stop:") if userInput.lower() in technical_dict: print(technical_dict[userInput.lower()]) if userInput.lower() not in technical_dict: print("Term does not exist in technical dictionary") break
1 回答

慕勒3428872
TA貢獻1848條經驗 獲得超6個贊
您創建詞典的方式似乎存在問題。您現在擁有的鍵值不是 string 或 str 類型。這就是為什么您會收到字典沒有屬性“lower”的錯誤。要修復此問題,您需要更改這些值,使其成為字符串類型。嘗試這個:
technical_dict = {
'dict' : 'stores a key/value pair',
'list' : 'stores a value at each index',
'map' : 'see dict',
'set' : 'stores unordered unique elements'
}
添加回答
舉報
0/150
提交
取消