mardi 29 octobre 2019

Multiple if conditions, without nesting

I have a sample piece of code below that I need some help on. The code sets the 'outcome' variable to False in the beginning and only should become True if all the 'if' conditions are met. Is there a more efficient way of doing this? I am trying to avoid nested 'if' statements.

Thanks!

    outcome = False

    while True:
        if a != b:
            print("Error - 01")
            break

        if a["test_1"] != "test_value":
            print("Error - 02")
            break

        if "test_2" not in a:
            print("Error - 03")
            break

        if "test_3" != "is long data string":
            print("Error - 04")
            break

        outcome = True
        break

Aucun commentaire:

Enregistrer un commentaire