2014-04-22 6 views
0

여기 내 코드입니다. 아무도 내부 루프를 while 루프로 변경하는 방법을 말해 줄 수 있습니다.for 루프에서 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() 
+2

왜 그렇게하고 싶은지 우리에게 말할 수 있습니까? –

+0

'for' 루프는 배열의 모든 단일 요소를 처리합니다. 야생의 추측이 있습니다. OP는 일부 요소 만 처리하려고했습니다. 그게 당신이 @ user3558932 할 작정입니까? – alvits

답변

-1

그것은 전적으로 분명 당신이 원하는, 그러나 당신은 사용을 고려 할 수 없습니다 년대 :

while True: 

그것은 것 다음 무한 루프 때까지 두 프로그램 또는 사용 종료 :

break 

Python 문서의 예는 다음과 같습니다.

이 지속적으로 루프 것, 출구없이 그러나

while True: 
    for items in list: 
     for sublist in items: 
      exec(sublist) 
     wn.exitonclick() 

을하거나 휴식 :

당신은 본질적으로 루프에 현재 가지고있는 둘 수 있었다.

+0

이것은 현재의 코드를'while True'로 감싸고 있습니다. 실제로 질문에 답하지 않습니다 –

+0

설명이 명확하지 않았기 때문에 내부 루프가 필요하다고 가정했습니다 (for 루프로 가정). 루프를 계속해서 ... 나는 그것을 다른 것으로 변환하는 어떤 시점도 보지 못한다. – Maximas

관련 문제