Python 连接四:请求输入而不打印

Python 连接四:请求输入而不打印,python,Python,我正在做一个连接四型游戏。我正在尝试设置游戏的简单可玩性。我没有得到一个错误,但当我想要它打印出电路板时,它会一直将我发送到输入中。当我为列输入一个数字时,它不会打印任何内容,它只会给我另一个应该填写的输入,这会一直持续到我退出程序。。我正试图远离课堂,因为我还不太擅长编程。我想知道为什么会发生这种情况,以及如何解决它,或者我是否只需要重新编程整个事情 a = [" ", " ", " ", " ", " ", " ", " "] b = [" ", " ", " ", " ", " ", "

我正在做一个连接四型游戏。我正在尝试设置游戏的简单可玩性。我没有得到一个错误,但当我想要它打印出电路板时,它会一直将我发送到输入中。当我为列输入一个数字时,它不会打印任何内容,它只会给我另一个应该填写的输入,这会一直持续到我退出程序。。我正试图远离课堂,因为我还不太擅长编程。我想知道为什么会发生这种情况,以及如何解决它,或者我是否只需要重新编程整个事情

a = [" ", " ", " ", " ", " ", " ", " "]
b = [" ", " ", " ", " ", " ", " ", " "]
c = [" ", " ", " ", " ", " ", " ", " "]
d = [" ", " ", " ", " ", " ", " ", " "]
e = [" ", " ", " ", " ", " ", " ", " "]
f = [" ", " ", " ", " ", " ", " ", " "]
board = [a, b, c, d, e, f] # sets up the board
print("What is player 1's name?")
player1 = input()
print("What is player 2's name?")
player2 = input()
plays = 0


def print_board(): # prints the board
    p = 0
    for x in board:
        for i in x:
            print(i, end=" | ")
        print()
        p += 1
        if p != 6:
            print("- "*15)
        else:
            print()


def win(): # defines a boolean if one player has won
    i = 0
    k = 0
    while i != 5:
        while k != 6:
            if board[i][k] == "o" or board[i][k] == "x":
                if board[i+1][k] == board[i][k] == board[i+2][k] == board[i+3][k]:
                    return False
                elif board[i][k] == board[i][k+1] == board[i][k+2] == board[i][k+3]:
                    return False
                elif board[i][k] == board[i+1][k+1] == board[i+2][k+2] == board[i+3][k+3]:
                    return False
                elif board[i][k] == board[i-1][k-1] == board[i-2][k-2] == board[i-3][k-3]:
                    return False
            else:
                return True


def play(): # defines the part you play.
    if plays % 2 == 0:
        player = "o"
    else:
        player = "x"
    print_board()
    x = int(input("Where would you like to put your chip?"))
    i = 0
    while i < 5:
        if board[i][x] == " ":
            if board[i+1][x] == "x" or board[i+1][x] == "o":
                board[i][x] = player
    print_board()
    if win():
        print(player+" won!")
    play()

play() # runs the script
a=[,,,,,,,,,,,]
b=[,,,,,,,,,,,,,,]
c=[,,,,,,,,,,,,,,]
d=[,,,,,,,,,,,,,,]
e=[,,,,,,,,,,,,,,]
f=[,,,,,,,,,,,,,,,]
董事会=[a、b、c、d、e、f]#设置董事会
打印(“玩家1的名字是什么?”)
player1=输入()
打印(“玩家2的名字是什么?”)
player2=输入()
播放=0
def print_board():#打印电路板
p=0
对于板上的x:
对于x中的i:
打印(i,end=“|”)
打印()
p+=1
如果p!=6:
打印(“-”*15)
其他:
打印()
def win():#定义一个布尔值,如果一个玩家赢了
i=0
k=0
而我5:
而k!=6:
如果板[i][k]==“o”或板[i][k]==“x”:
如果板[i+1][k]==板[i][k]==板[i+2][k]==板[i+3][k]:
返回错误
elif板[i][k]==板[i][k+1]==板[i][k+2]==板[i][k+3]:
返回错误
elif板[i][k]==板[i+1][k+1]==板[i+2][k+2]==板[i+3][k+3]:
返回错误
elif板[i][k]==板[i-1][k-1]==板[i-2][k-2]==板[i-3][k-3]:
返回错误
其他:
返回真值
def play():#定义您扮演的角色。
如果播放%2==0:
player=“o”
其他:
player=“x”
印刷电路板()
x=int(输入(“您想把芯片放在哪里?”)
i=0
当我<5时:
如果电路板[i][x]==“”:
如果板[i+1][x]==“x”或板[i+1][x]==“o”:
棋盘[i][x]=玩家
印刷电路板()
如果赢了():
打印(玩家+“赢了!”)
play()
play()#运行脚本

在您的游戏循环中尝试此方法-希望它也能帮助您修复赢取检查:

def play(): # defines the part you play.
    plays = 0
    while True:
        if plays % 2 == 0:
            player = "o"
        else:
            player = "x"
        x = int(input("Where would you like to put your chip?"))
        i = 0
        for i in range(5):
            if board[i][x] == " ":
                if board[i+1][x] == "x" or board[i+1][x] == "o":
                    board[i][x] = player
        else:
            board[5][x] = player

        print_board()
        #if win():
        #    print(player+" won!")
        #    break
        plays += 1

print_board()

play() # runs the script

我注释掉了win检查,因为它还不起作用

它不要求输入,你有一个无限循环,而我<5-我从不递增。实际上,你的所有循环都没有递增检查值,你的run函数不需要打印两次棋盘,在调用play()之前先进行初始打印然后在输入后只在循环中显示一次通常在这样的游戏中,play函数实际上是一个无限循环,一旦满足赢的标准就会中断,而不是在结束时调用它