所以我一直无法检查数字0是否在另一个列表中的一组列表中.这些行构成了我正在制作的pacman类型游戏的迷宫,所以这一点就是检查pacman是否已经吃掉了所有的硬币.
这是我的代码:
row1 =[3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3] row2 =[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] row3 =[1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1] row4 =[1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1] row5 =[1,0,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,0,1] row6 =[1,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1] row7 =[1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1] row8 =[1,0,0,0,0,1,0,1,1,1,1,1,0,1,0,0,0,0,1] row9 =[1,1,1,1,0,1,0,0,0,1,0,0,0,1,0,1,1,1,1] row10=[3,3,3,1,0,1,1,1,0,1,0,1,1,1,0,1,3,3,3] row11=[3,3,3,1,0,1,0,0,0,0,0,0,0,1,0,1,3,3,3] row12=[3,3,3,1,0,1,0,1,4,4,4,1,0,1,0,1,3,3,3] row13=[1,1,1,1,0,1,0,1,3,3,3,1,0,1,0,1,1,1,1] row14=[3,3,3,3,0,0,0,1,3,3,3,1,0,0,0,3,3,3,3] row15=[1,1,1,1,0,1,0,1,5,5,5,1,0,1,0,1,1,1,1] row16=[3,3,3,1,0,1,0,3,3,3,3,3,0,1,0,1,3,3,3] row17=[3,3,3,1,0,1,0,1,1,1,1,1,0,1,0,1,3,3,3] row18=[3,3,3,1,0,1,0,1,1,1,1,1,0,1,0,1,3,3,3] row19=[1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1] row20=[1,0,0,0,0,1,1,1,0,1,0,1,1,1,0,0,0,0,1] row21=[1,0,1,1,0,0,0,0,0,3,0,0,0,0,0,1,1,0,1] row22=[1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1] row23=[1,2,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,2,1] row24=[1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,0,1] row25=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1] row26=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] maze = [row1,row2,row3,row4,row5,row6,row7,row8,row9,row10,row11,row12, row13,row14,row15,row16,row17,row18,row19,row20,row21,row22, row23,row24,row25,row26]
所以我试过if 0 not in maze:
但是if语句将执行0是否在(迷宫)中.
任何帮助将不胜感激,谢谢.
你必须遍历每个列表maze
并检查是否有0:
if not any(0 in i for i in maze): ...
该any()
函数的优点在于它maze
一旦找到0 就会停止循环.