ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
import math
print(0.0 == -0.0, 1 / float('-inf'), 2 ** -1074 / 2 == 0, math.copysign(0.0, -1))- A. True -0.0 False 0.0
- B. False 0.0 True -0.0
- C. True -0.0 True -0.0
- D. True 0.5 True -0.0
Correct answer: C. True -0.0 True -0.0
0.0 and -0.0 compare equal, and dividing a positive number by negative infinity gives -0.0. Halving the smallest subnormal rounds to zero, and copysign reads the sign bit of -0.0.
More Python Programming questions
- What is printed? python try: print(int('')) except ValueError: print('empty') try: print(0.0 / 0) except ZeroDivisionError: print('zero')
- What is printed? python import math try: print(math.sqrt(-1)) except ValueError: print('domain') print(float('nan') 0, math.pow(0, 0))
- What is printed? python print('{:e}'.format(1234.5), '{:.3g}'.format(1234567), '{:g}'.format(0.0001), '{:g}'.format(0.00001))
- What is printed? python print('é'.encode('ascii', 'replace'), 'é'.encode('ascii', 'ignore'), b'hxc3xa9llo'.decode('ascii', 'ignore')…
- What is printed? python print(10 50 // 3 20 % 100, len(bin(10 50)) - 2, (10 50).bitlength())
- What is printed? python print(1 < 2 < 3 == 3.0 != 4, 1 < 2 > 3, (1 < 2) > 3, 'a' < 'b' < 'a')