개인적인 공부/Python

day 6-2 python (반복문)

karatejin 2023. 3. 1. 15:34

def move_it():
    move()
    turn_left()

move_it()

move()

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

def move_around():
    move()
    turn_right()

move_around()

for locate in range(5):
    move_it()

    move_it()

    move_around()

    move_around()

move()

만들어진 기능인 move() 와 turn_left() 를 def 함수를 써서 기능을 만든 다음 for 반복문을 5번 반복하고 마지막 move()를 사용하여 위치시키게 함.

 

더 짧게 하기

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

for arrive in range(6):
    move()
    turn_left()
    move()
    turn_right()
    move()
    turn_right()
    move()
    turn_left()