Python second "if statement" negates first one

You should use if-elif-else statement instead. Currently, your code is performing

x = 3
if x == 3: # This will be True, so test = "True"
    test="True"
if x == 5: # This will be also tested because it is a new if statement. It will return False, so it will enter else statement where sets test = "Inconclusive"
    test="False"
else:
    test="Inconclusive"

Instead use:

x = 3
if x == 3: # Will be true, so test = "True"
    test="True"
elif x == 5: # As first if was already True, this won't run, neither will else statement
    test="False"
else:
    test="Inconclusive"

print(test)

Leave a Comment