-1
我运行程序,但循环不停止时,单词等于50,000。产量有时超过5万。我不确定我做错了什么。python初学者 - 当条件满足时循环不中断
words = 0
unwanted_comments = 0
comments = 0
keep_going = True
while number_of_comments <= max_comments and keep_going == True:
num_per_comments = random.randint(1,1050)
if number_per_comments <= 1000:
words = number_per_comments + total
comments +=1
if words <= 50000:
keep_going = True
else:
keep_going = False
else:
unwanted_comments +=1
你永远不会改变'words'的值,因此总是小于50k。你也应该小心if-test周围的缩进。 – MatsLindh
为什么你需要'keep_going'?一旦你有超过'max_comments',你是不是想摆脱循环?如果是这样,你不需要'keep_going'。 –
除了永不改变单词的值,您也不会改变number_of_comments的值 – Legman