Python 함수 내에 break나 continue 쓰는 방법 (continue not properly in loop 오류)
조회수 2344회
def inputUser(table, cnt):
x = int(input("다음 수의 x 좌표를 입력하시오 : "))
y = int(input("다음 수의 y 좌표를 입력하시오 : "))
#사용자가 입력한 좌표를 검사한다
if board[x][y] != '':
print("잘못된 위치입니다.")
continue
else:
board[x][y] = 'X'
cnt += 1
def main():
cnt = 0
flag = True
drawBoard(board)
while flag:
inputUser(board, cnt)
flag = computer(board, cnt)
drawBoard(board)
main()
위 코드와 같이 main함수 안에 while문이 있고, inputUser
함수를 main 함수 안에 넣고, inputUser
함수밖에는 while문이 있습니다. 여기서 inputUser 함수를 정의하는 과정에서 inputUser
함수 내에 반복문이 있는 것이 아니기 때문에 continue를 썼을 때 'continue not properly in loop'
오류가 뜨게 됩니다. 이거 혹시 어떻게 해결할 수 있을까요?
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
댓글 입력