我是 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
提交
取消