停下来,不要重复循环?python

停下来,不要重复循环?python,python,while-loop,Python,While Loop,我有一个问题,我的代码在我不想重复语句的时候却不断重复语句 这是我的密码: def gameMake(): while emptySp(): #already written (checks if the space is available for the user to put in their token) print("Player 1") mycol = input("Please choose a column (1-" + str(co

我有一个问题,我的代码在我不想重复语句的时候却不断重复语句

这是我的密码:

def gameMake():

    while emptySp(): #already written (checks if the space is available for the user to put in their token)


        print("Player 1")
        mycol = input("Please choose a column (1-" + str(columns))

        if coluser == columns:
            mycol = input("Please choose a column to place your piece in (1-" + str(columns))

        elif:
            rowuse = rows


            while x >= 1:
                if board[x][coluser] == board[r][c]
                    board[x][coluser] == PONE #PONE = "o" (the token)


                else:

                    i = 0
                    i = i + 1
输出和我得到的示例:(输入的板是5x5)

代码应该接受数字1-5作为有效的列号,然后使用我已经创建的board函数打印出当前的board!如果是1-5以外的任何数字,则应重新提示用户!我的代码出了什么问题?为什么会有索引错误


谢谢大家!

这里的问题是,您没有检查数字是否在1-X范围内,您只是检查数字是否>=1


您可能希望更新while语句,以便在显示的示例输入/输出中读取
而x>=1和x,看起来您总是以最内部的
if
子句结束。 这里,
board[x][coluser]==PONE
正在执行比较,而不是赋值,因此它的计算结果为true或false,但不会改变程序其余部分中的任何内容。所以
emptySp()
总是返回true,因为没有任何更改。
第二,什么是“用win函数检查任何win”?win功能是什么?同样,在
if
子句中,代码没有任何部分被更改,因此无论是什么原因导致
emptySp()
第一次计算为true,都将保持不变。

在代码中
i
的确切含义是什么?将其设置为零,然后向其添加1。在末尾添加一个
if语句
,检查列是否大于5。如果是,请打断。其他内容中前两个语句的目的是什么?您首先设置
i=0
,然后将其递增,但下次再次输入
else
时,
i
将首先重置为0。一个问题可能是python中的列表具有基于零的索引,而不是基于一的索引<代码>线路板行=[0,0,0,0,0]
具有有效的索引
线路板行[0]
线路板行[4]
<代码>线路板排[5]超出范围。因此,当您请求
并接受
1
时,您可能需要在代码中的某个位置将其转换为
0
。如果您能提供真实的代码就好了,因为您提供的代码与您编写的代码不一样,例如。G用户输入的提示是
请选择一列(1-5
(无
,最后)-因此我们如何相信您某些重要部分也没有更改?好的,我明白您的意思了!我将如何将PONE分配给该元素?我还将#Check for win函数注释放在那里,因为我将添加我的函数,在确保我的当前代码正常工作后,检查玩家是否获胜!赋值运算符是
=
,比较运算符是
=
Player 1 
Please choose a column (1-5): 1
Player 1 
Please choose a column (1-5): 2
Player 1 
Please choose a column (1-5):3
Player 1 
Please choose a column (1-5): 4
Player 1 
Please choose a column (1-5): 5


IndexError: list index out of range