Python运行问题
有没有大佬解答一下,为什么同一串代码,点击run module以后,有时候能得到结果,有时候不能呢。 发代码 冬雪雪冬 发表于 2020-2-23 10:11发代码
import random
n = 8
red = yellow = green = 0
while n:
color = random.choice(['red','green','yellow'])
if color == 'red':
red += 1
elif color == 'green':
green += 1
else :
yellow += 1
if red > 3 or yellow > 3 or green > 6:
continue
n -= 1
print('red*',red,'+yellow*',yellow,'+green*',green)
如果red > 3yellow > 3 green > 6有任何一个成立,则continue,n不会再变化,形成无限循环 冬雪雪冬 发表于 2020-2-23 11:29
如果red > 3yellow > 3 green > 6有任何一个成立,则continue,n不会再变化,形成无限循环
好的,谢谢。明白了,多谢解答
页:
[1]