我正在寻找一个必须使用二维表的项目,在该表中我必须找到精确的值。在这段短代码中,我尝试找到值6,但我找不到。预先感谢您的帮助
#!/usr/bin/python3
from math import *
import sys
bord = [[1, 2, 3], [4, 5, 6]]
def main():
x = 0
y = 0
while(x < 2):
while(y < 3):
print(bord[x][y])
if (bord[x][y] == 5):
print("here")
y = y + 1
x = x + 1
main()
您的代码中必须初始化的问题不是循环
bord = [[1, 2, 3], [4, 5, 6]]
def main():
x = 0
while(x < 2):
y = 0
while(y < 3):
if (bord[x][y] == 5):
print("here")
y = y + 1
x = x + 1
main()
现在,您仅循环第一个内部列表
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句