python - Python dict 项目匹配返回 TypeError: 'int' object is not iterable
问题描述
我有以下代码,我想匹配用户输入的 x 和 y 值相乘结果以匹配字典项。例如用户输入 x=2 和 y=3,乘法结果将是 6。x 和 y 值的顺序很重要,它应该与字典顺序匹配。例如 x=3 和 y=2 并不相同,尽管它们具有相似的乘法值。因此,我想要一个将这个乘积值与字典项相匹配的函数,以便对其进行评分。这里输出 typeError: 'int' object is not iterable 的代码:
scoremapDict = {(1, 1): 1, (1, 2): 2, (2, 1): 2, (1, 3): 3, (3, 1): 3, (1, 4): 4, (4, 1): 4, (2, 2): 4, (1, 5): 5,
(5, 1): 5, (4, 2): 8, (2, 4): 8, (2, 3): 6, (3, 2):6, (3, 3): 9, (2, 5): 10, (5, 2):10, (3, 4): 12,
(4, 3):12, (3, 5): 15, (5, 3): 15, (4, 4): 16, (4, 5): 20, (5, 4): 20, (5, 5): 25}
x = 5
y = 2
results = int(x*y)
for i in results:
if results == scoremapDict[(x,y)]:
print("High")
else:
print("None")
任何人都可以帮助这个 tyro python-er,在此先感谢:
解决方案
推荐阅读
- angular - _为什么_ AoT 会降低这个值?
- objective-c - 从不兼容的类型'void(^__strong)(int,const char *,int)'分配给'void(*)(int,const char *,int)'
- angular - Angular 组件作为 Mapbox 控件
- flutter - 点按即可对焦 Flutter 相机
- python - 如何访问自定义 APIRoute 类中的路由依赖项?
- list - 如何按 TCL 中的子元素之一对列表进行排序
- sapui5 - 如何验证并滚动到 sap.m.RadioButtonGroup
- android - 企业应用程序的托管配置(Android 管理 API)
- javascript - getBoundingClientRect(); 不工作..?
- accessibility-insights - Accessibility Insights for Windows 标记问题已在较新版本的 .NET Framework 中修复