Nik*_*rud 3 python random while-loop
这就是我所拥有的,但这只生成一次随机数并无限地打印该数字:
import random
x = random.randint(0,10)
y = 7
while x != y:
print(x)
Run Code Online (Sandbox Code Playgroud)
像(在一段时间内移动条件):
stop_at = 7
while True:
num = random.randint(0, 10)
if num == stop_at:
break
print num
Run Code Online (Sandbox Code Playgroud)
或者,一个完整的重要因素:
from itertools import starmap, repeat, takewhile
from random import randint
for num in takewhile(lambda L: L != 7, starmap(randint, repeat( (0, 10) ))):
print num
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14573 次 |
| 最近记录: |