Find out the output of the following (Python)
x=3
if x > 2 or x < 5 and x = = 6 :
print (“ok”)
else:
print (“no output”)
Answers
Answered by
5
Answer:
no output
Explanation:
since x= 3
and in the condition u have specified that it must equal to 6 by putting a and operator with x==6
therefore it will directly jump to else statement
Answered by
2
Answer:
ok
Explanation:
In python AND operator is solved before OR operator**
Since x = 3
- Condition 1 (x>2): True
- Condition 2 (x<5): True
- Condition 3 (x==6): False
First operator is AND**
It will see Condition 2 AND Condition 3
True AND False = False
Second operator is OR**
It will see Condition 1 OR Answer of First operator*
True OR False = True
Therefore it will run the code in the if statement which prints ok
Hope this helps
Attachments:

Similar questions