0
Why this python code print only 1 and not 3
num = 7 if num >3: print("1") if num < 5: print ("2") If num == 7: print ("3")
2 ответов
+ 1
Because
if num==7:
is inside
if num < 5:
If num < 5 is not true, it won't execute what's inside it even if it's true.
If it would be like
num = 7
if num >3:
print("1")
if num < 5:
print ("2")
If num == 7:
print ("3")
Or:
if num >3:
print("1")
if num < 5:
print ("2")
If num == 7:
print ("3")
It would print both.
I believe the exact point of this excercise is to show that indentation(spaces or tabs before portion of code) are important, cuz they determine dependency between portions of code.
0
cause its greater than 3 and equal to 7. Look at the code