ProgrammingVery hardJEE Advanced · CAT placement
What is printed?
What is printed?
print(sorted([0.5, -0.0, 0.0, -1]))
- A. [-1, 0.0, -0.0, 0.25]
- B. [-1, -0.0, 0.5, 0.0]
- C. [0.5, -0.0, 0.0, -1]
- D. [-1, -0.0, 0.0, 0.5]
Correct answer: D. [-1, -0.0, 0.0, 0.5]
-0.0 and 0.0 compare equal, so sorted keeps their input order: -0.0 came first. Printing shows the sign of the zero, but the sort does not treat the two zeros differently.
More Python Programming questions
- What is printed? python x = 10 16 print(float(x) == x, float(x + 1) == x, x + 1.0 == x, (x + 1) - x)
- What is printed? python print('%5s|%-5s|' % ('ab', 'cd'))
- What is printed? python print(len('%-8.3f|' % 3.14159), len('%08.3f' % -3.14159), '%08.3f' % -3.14159)
- What is printed? python import math print(math.prod([]), math.prod(range(1, 6)), math.lcm(range(1, 6)), math.lcm())
- What is printed? python print(list('ab') + ['c'] 2, 'ab' + 'c' 2, ('a',) 2)
- What is printed? python print(10 18 // 7 7 + 10 18 % 7 == 10 18, (-10 18) // 7 7 + (-10 18) % 7 == -10 18, -10 18 % 7 == (-10) 18 % 7)