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")
  1. A is greater
  2. B is greater
  3. Both A and B
  4. 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,

  1. print("A is greater") if a > b , here 13 is not greater than 15 so condition becomes false
  2. print("=") if a == b , here 13 is not equal to 15 so condition becomes false
  3. 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".

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.