如何逐步将乌龟移动(将步长值随机设置为1-10像素),长度为1000像素?
这是我到目前为止所拥有的
import turtle;
import random;
turtle.fd(random.randrange(1,10))
答案 0 :(得分:1)
因为你似乎只想要一个在这里有效的答案是
from random import randint as ri
from itertools import takewhile as tw
import turtle as t
steps = [1,10]
it = iter(lambda:(t.fd(ri(*steps)) or 1),object())
print "Takes %d steps"%(sum(tw(lambda x:1e3-t.position()[0]>steps[-1],it))+1)