Home »
MCQs »
Python MCQs
What will be the output of the following Python code? Question 6
39. What will be the output of the following Python code?
a = 13
b = 15
print("A is greater") if a > b else print("=") if a == b else print("B is greater")
- A is greater
- B is greater
- Both A and B
- None of the mentioned above
Answer: B) B is greater
Explanation:
In the above code, the assign value for a = 13 and b = 15. There are three conditions mentioned in the code,
- print("A is greater") if a > b , here 13 is not greater than 15 so condition becomes false
- print("=") if a == b , here 13 is not equal to 15 so condition becomes false
- else print("B is greater"), condition 1 and 2 will not be true so program control will switch to else part and output will be "B is greater".