【发布时间】:2014-04-05 01:42:10
【问题描述】:
原代码:
>>> def calcItemsLowShelfLife(shelfLifeList):
ctLowShelfLife = 0
for number in shelfLifeList:
if number <= 7:
ctLowShelfLife += 1
return ctLowShelfLife
>>> shelfLifeList = [5, 7, 10]
>>> lowShelfLife = calcItemsLowShelfLife(shelfLife)
当我尝试运行 python 3.2 时出现错误:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
lowShelfLife = calcItemsLowShelfLife(shelfLife)
File "<pyshell#5>", line 3, in calcItemsLowShelfLife
for number in shelfLifeList:
TypeError: 'int' object is not iterable
【问题讨论】:
-
你的缩进关闭了,我也不知道
ctLowShelfLife是什么? -
已修复!计算低保质期,计算有多少产品的保质期为 7 天或更短
标签: python list function variable-assignment python-3.2