ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
import math
print(f'{-0.0}', -0.0 == 0.0, math.copysign(1, -0.0))- A. -0.0 True 0.0
- B. -0.0 True -1.0
- C. -0.0 False -1.0
- D. -0.0 True 2.0
Correct answer: B. -0.0 True -1.0
IEEE 754 keeps a signed zero, so -0.0 prints with its sign but still compares equal to 0.0. copysign reads the sign bit directly, which is why it returns -1.0 here.
More Python Programming questions
- What is printed? python print(1 == 1.0, hash(1) == hash(1.0), {1: 'a'}[1.0], True + 1.0)
- What is printed? python print(sorted([3, -3, 2, -2, 1], key=abs))
- What is printed? python print(f'{-1.5:+.1f}', f'{0.5:.0f}', f'{1.5:.0f}', f'{-0.04:.1f}')
- What is printed? python print(format('x', '>4') + '|' + format(3.14159, '^9.2f') + '|' + format(42, '+') + '|' + format(1234567, ','))
- What is printed? python print('%d%%' % 50, '%x' % 255, '%o' % 8, '%e' % 12345.678)
- What is printed? python print(-(264) >> 3, -(264) // 8, -(264) % 10)