即使条件为false,while循环仍在运行

igetnqfo  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(305)

最近我在做一个tic tac toe项目,但是有一些问题:

intro()

row_top = [' ','|',' ','|',' ']
line = ['-','-','-','-','-']
row_mid = [' ','|',' ','|',' ']
row_low = [' ','|',' ','|',' ']

default = (' ' in row_top or ' ' in row_mid or ' ' in row_low)

p1 = True

while default:

    while p1 :

        p1c = int(input('P1 turn! insert the position you want to place the marker:'))

        if inserter_1(p1c) != 'Error':
            display()
            p1 = False

    while not p1:

        p2c = int(input('P2 turn! insert the position you want to place the marker:'))

        if inserter_2(p2c) != 'Error':
            display()
            p1 = True

winner_check()

函数的作用是:将空格字符串的值更改为“x”或“o”,然后display()函数打印出电路板。
即使display()函数显示电路板已填充(这意味着所有行中都没有“”),它仍然要求输入。
真正令人困惑的是,默认条件肯定是假的,我甚至尝试添加一个从1到9的数字列表,并在玩家每次输入时删除一个数字,但仍然不起作用。
任何帮助都将不胜感激。非常感谢你!

aemubtdh

aemubtdh1#

这里有一个小测验,你认为表达式的计算频率是多少?当代码达到默认值=。你似乎认为违约每次都会被重新评估,但它永远都是真实的,因为它从未改变过。尝试用while循环中使用的表达式替换默认值

相关问题