0
Is this correct?
x=7 if x>5: print("bigger than 5") if x>3: print("bigger than 3") >>> bigger than 5 >>> biggrt than 3
2 Answers
+ 1
Change position of 3 and 5 otherwise 4 will not be seen.
First if checks > 5 so only numbers higher are treated in the loop. 4 < 5 so the loop ends there.
Why not try it out in the code playground and see for yourself?
+ 1
It is correct but kind of pointless because if x is bigger than 5, it will always be bigger than 3. Note that because of the indentation lines 4 and 5 will only be executed if x is bigger than 5. If you want to check if x is bigger than 3 even if it is not bigger than 5, you need to change the indentation:
x=7
if x>5:
print("bigger than 5")
if x>3:
print("bigger than 3")
If you want to check if x is bigger than 3 ONLY if it is not bigger than 5, use "elif x>3:" instead.