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

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

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

  1. intro()
  2. row_top = [' ','|',' ','|',' ']
  3. line = ['-','-','-','-','-']
  4. row_mid = [' ','|',' ','|',' ']
  5. row_low = [' ','|',' ','|',' ']
  6. default = (' ' in row_top or ' ' in row_mid or ' ' in row_low)
  7. p1 = True
  8. while default:
  9. while p1 :
  10. p1c = int(input('P1 turn! insert the position you want to place the marker:'))
  11. if inserter_1(p1c) != 'Error':
  12. display()
  13. p1 = False
  14. while not p1:
  15. p2c = int(input('P2 turn! insert the position you want to place the marker:'))
  16. if inserter_2(p2c) != 'Error':
  17. display()
  18. p1 = True
  19. winner_check()

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

aemubtdh

aemubtdh1#

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

相关问题