day 6-2 python (반복문)

2023. 3. 1. 15:34개인적인 공부/Python

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()

 

'개인적인 공부 > Python' 카테고리의 다른 글

day 6-4 python (while 반복문 장애물)  (0) 2023.03.01
day 6-3 python while 반복문  (0) 2023.03.01
day 6-1 python 함수 (Functions)  (0) 2023.02.28
day 5-6 python (Fizz Buzz)  (0) 2023.02.27
day 5-5 python (짝수 더하기)  (0) 2023.02.27