[Python Bootcamp] Day6

Yul·2024년 10월 3일

Python Bootcamp

목록 보기
7/7
post-thumbnail

1. 배운 것

  • 함수 정의
  • while ~ :
    • while 뒤의 조건이 참이면 반복을 실행하고, 아니면 루프를 끝낸다.
    • for와의 비교 :
forwhile
for (item) in [list_of items]:while Something is ture:
do Something to each itemdo something repeatedly
  • 리스트 내부의 각 item에 대하여 무언가를 해야할 경우, for 루프가 좋고
  • 어떤 item을 반복하는 것이 아니라 특정 작업을 설정한 조건이 맞지 않을 때까지 반복하는 것은 while 루프가 좋음.

  • while not ~:
    • 뒤의 조건이 거짓이면 반복을 실행하고, 참이면 루프를 끝낸다.



장애물 높이, 위치와 골의 위치가 모두 바뀔 경우

def turn_right():
    turn_left()
    turn_left()
    turn_left()
def jump():
    turn_left()
    while wall_on_right():
        if front_is_clear():
            move()
        else:
            turn_left()
    turn_right()
    move()
    turn_right() 
while not at_goal():
    if front_is_clear():
        move()
    else:
        jump()

2. 프로젝트 : 미로탈출

def turn_right():
    turn_left()
    turn_left()
    turn_left()
while not at_goal():
    if front_is_clear()&right_is_clear():
        turn_right()
        move()
    elif front_is_clear()&wall_on_right():
        move()
    elif wall_in_front()&right_is_clear():
        turn_right()
        move()
    else:
        while wall_in_front():
            turn_left()
        move()
profile
이것저것 공부하는 중

0개의 댓글