mercredi 13 janvier 2021

Python3 : How to check, out of multiple if statements, at least one if statement is run?

I know the question doesn't really make sense to you. Let me show you an example below.

        if_group:
            if i == 0:
                answer[i][j] += check(matrix, i, j, "down")
            if j == 0:
                answer[i][j] += check(matrix, i, j, "right")
            if i == len(matrix) - 1:
                answer[i][j] += check(matrix, i, j, "up")
            if j == len(matrix[i]) - 1:
                answer[i][j] += check(matrix, i, j, "left")
        else:
            do something

Let's say, if at least one of those 4 if statements inside the if_group is run, then skip the else statement. However, if none of those if statements is run, then execute the else statement.

Aucun commentaire:

Enregistrer un commentaire