python/리스트

숫자이동[1단계]

june__Park 2021. 2. 28. 00:05
# 숫자이동[1단계]
# 1. 숫자2는 캐릭터이다.
# 2. 숫자1을 입력하면, 캐릭터가 왼쪽으로
#    숫자2를 입력하면, 캐릭터가 오른쪽으로 이동한다.
# 3. 단, 좌우 끝에 도달했을 때, 예외처리를 해야한다.

game = [0, 0, 2, 0, 0, 0, 0]

player = 0
i = 0
while i < 7:
    if game[i] == 2:
        player = i
    i = i + 1

while True:
    game[player] = 2
    print(game)
    mov = int(input("1) 왼쪽, 2) 오른쪽, 3) 종료"))
    if mov == 1:
        if player == 0:
            print("끝에 도달하였습니다. 더이상 갈 수 없습니다.")
            continue
        game[player] = 0
        player -= 1
    if mov == 2:
        if player == 6:
            print("끝에 도달하였습니다. 더이상 갈 수 없습니다.")
            continue
        game[player] = 0
        player += 1
    if mov == 3:
        break