Searching for a value in a two-dimensional python array

a marqué ce sujet comme résolu.

Hello, I’m looking to make a project I have to use a two-dimensional table, in this table I have to find precise values. In this short code I try to find the value 6 but I can’t. Thank you in advance for your help

#!/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()

Hi, there are a few things you could do to improve your code but most importantly you should unroll it step by step on paper as the example is short.
Don’t make any assumption on what happens (especially about your Y variable) and you should see your mistake pretty fast.

Ce sujet est verrouillé.