为什么我的for循环无法多次运行?

时间:2019-06-09 13:22:47

标签: python

我有一个for循环,应该运行10次,但它只运行两次。 我正在尝试将输入与i进行比较,如果输入为false,则返回false。

我猜想它与if语句有关,但idk为什么会发生?

def p_move(player1, player2):
    for i in range(10): <-- runs ten times
        print (playerMove, (str(i))) <-- I used this to see how many times it run but it just gave me I being 0 (so it ran one time)

        if (str(playerMove)) == str(i):
            if board[i] == (player2):
                board[i] = (board[i])
                print_board()
                return ("\nThat space is taken, your turn has been)

                else:
                    board[i] = (player1)
                    print_board()
                    return print_board()

        else:
            return False

1 个答案:

答案 0 :(得分:0)

返回中断功能。这就是循环仅执行一次的原因。

参考:what is the difference between return and break in python?