【发布时间】:2017-09-12 09:55:30
【问题描述】:
这是一个计算len(set_forbidden) > 0 次数的示例代码。现在,如果它计算的条件大于 3,那么我必须调用openthedoor(uppumanga),然后将计数重置为零。但是当我尝试打印 count 时,我得到 count = 1,任何解决此问题的帮助将不胜感激。
count = 0
def rydbergset(value,count):
if len(set_forbidden) > 0:
count+=1
last_time = True
print "this is the count greater than three-"+ str(count)
if (last_time == True) and (count>3):
openthedoor(uppumanga)
count = 0
else:
last_time = False
return set_forbidden,count
【问题讨论】:
-
在 Python 中你需要
and来表示逻辑和...&表示按位和... -
@JonClements 这是一个错误!现在计数也没有更新。所以它没有调用
openthedoor(uppumanga) -
退后一步,再次查看您的代码...您有 last_time 和 last_time_(带下划线)...我们也不知道
set_forbidden或 @ 的位置/内容987654329@ 来自... -
循环中可能有错误。您应该展开代码。
-
@JonClements 我只是展示了我询问的相关代码的一小部分。
标签: python function loops counter