KnowledgeBoat Logo

Computer Science

What will be the output of the following code?

import math
x = 100
print(x>0 and math.sqrt(x))
  1. True
  2. 1
  3. 10
  4. 10.0

Python Modules

2 Likes

Answer

10.0

Reason — The code first imports the math module to access mathematical functions. It then assigns the value 100 to the variable x. The print statement checks whether x > 0, which is True because x is 100. Since the and operator is used, and the first condition is True, the code proceeds to evaluate math.sqrt(x), which calculates the square root of x. The square root of 100 is 10.0, so the print statement outputs 10.0.

Answered By

3 Likes


Related Questions