언어/파이썬

[부트캠프] for 과 while 반복문 - 6일차

앨리스.W 2023. 5. 5. 15:56

for문 

def turn_right():
    turn_left()
    turn_left()
    turn_left()
    
def jump():
    move()
    turn_left()
    move()
    turn_right()
    move()
    turn_right()
    move()
    turn_left()

#6번 반복하기
for step in range(6):
    jump()

while문 안에 if문 쓰기

def turn_right():
    turn_left()
    turn_left()
    turn_left()

 #무한 루프를 방지하기 위해 벽부터 찾는다
while front_is_clear():
    move()
turn_left()


while not at_goal():
    #오른쪽벽에 없으면
    if right_is_clear():
        turn_right()
        move()
    #오른쪽벽이 있고 앞에 벽에 없으면
    elif front_is_clear():
        move()
    else:
        turn_left()​

 

참고사이트

https://reeborg.ca/reeborg.html?lang=en&mode=python&menu=worlds%2Fmenus%2Freeborg_intro_en.json&name=Maze&url=worlds%2Ftutorial_en%2Fmaze1.json 

메모

이번건 좀 어려운거 같다. 내가 힌트를 안보고 해서 그런것도 있겠지만..

열심히 해야겠다!

반응형