這裏是我的代碼。任何人都可以告訴我如何將內部循環改爲while循環。將循環轉換爲while循環
import turtle
import time
wn= turtle.Screen()
alex= turtle.Turtle()
alex.hideturtle()
alex.pensize(5)
list= [['alex.left(90)','alex.forward(200)','time.sleep(1)'],
['alex.right(90)','alex.forward(75)','time.sleep(1)'],
['alex.right(90)','alex.forward(55)','time.sleep(1)'],
['alex.penup()','alex.goto(65,136)','alex.pendown()','alex.circle(10)','time.sleep(1)'],
['alex.penup()','alex.goto(75,127)','alex.pendown()','alex.goto(75,98)','time.sleep(1)'],
['alex.right(90)','alex.forward(30)','time.sleep(1)','alex.goto(100,98)','time.sleep(1)'],
['alex.penup()','alex.goto(75,98)'],
['alex.pendown()','alex.left(90)','alex.forward(45)','time.sleep(1)']
,['alex.right(120)','alex.right(180)','alex.forward(50)','time.sleep(1)'],
['alex.penup()','alex.goto(74.00,51)','alex.pendown()','alex.right(120)','alex.forward(45)','alex.left(120)']]
for items in list:
for sublist in items:
exec(sublist)
wn.exitonclick()
你能告訴我們爲什麼你想這樣做嗎? –
'for'循環處理數組中的每個元素。這是一個瘋狂的猜測,OP只想處理一些元素。那是你打算做的@ user3558932? – alvits