【发布时间】:2022-01-01 11:51:08
【问题描述】:
我正在尝试使用下面的代码来检查是否允许某人乘坐过山车。第一部分是创建一个二维列表,第二部分是检查。
heights = [165, 154, 156, 143, 168, 170, 163, 153, 167]
ages = [18, 16, 11, 34, 25, 9, 32, 45, 23]
heights_and_ages = list(zip(heights, ages))
heights_and_ages = [list(info) for info in heights_and_ages]
can_ride_coaster = []
for info in heights_and_ages:
for height, age in info:
if height > 161 and age > 12:
can_ride_coaster.append(info)
我在第 19 行得到错误
for height, age in info:
错误是:
line 19, in <module>
for height, age in info:
TypeError: cannot unpack non-iterable int object
我认为是因为我使用了两个变量bcs,如果我使用一个就可以了,但是在网上搜索后似乎没有问题。我该如何解决这个问题?
【问题讨论】:
-
尝试使用 heights_and_ages = [[list(info)] 获取 heights_and_ages 中的信息]
标签: python python-3.x for-loop typeerror