ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
a = 1e308
b = a * 10
print(b, -b, b - b if False else 0, b > a, b == float('inf'))- A. inf -inf 0 False True
- B. inf inf 1 True True
- C. nan -inf 0 True True
- D. inf -inf 0 True True
Correct answer: D. inf -inf 0 True True
Multiplying a large finite float by 10 overflows to inf, and negating it gives -inf. Infinity compares greater than any finite float, so both comparisons are True.
More Python Programming questions
- What is printed? python import math print(math.sqrt(16), math.sqrt(2) 2 == 2, math.isqrt(2) 2 == 2, math.pow(2, 0.5) == 2 0.5)
- What is printed? python print(int(0.1 10) == 1, int(0.7 10), int(4.35 100), round(4.35 100))
- What is printed? python print(len(str(264)), 264 // 1019, 264 % 1019, len(str(264 - 1)))
- What is printed? python print(-7 // 2 2 + -7 % 2 == -7, 7 // -2 -2 + 7 % -2 == 7, -(-7 // 2))
- What is printed? python x = 0b1011 print(bin(x << 3), bin(x >> 1), x << 3 >> 3 == x, bin(~x & 0b1111))
- What is printed? python print(3 'ab' == 'ab' 3, 'ab' 3 == 'aba' + 'bab', [0] 3 == [0, 0, 0], ['a'] 2 == 'aa')