原始代碼:局部變量在Python賦值之前引用3.2
>>> 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天 – Frangello