ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(int(2.9999999999999996), float('1e400'), -float('1e400'), 1e308 * 10 == float('inf'))- A. 2 inf -inf False
- B. 3 inf -inf True
- C. 2 inf -inf True
- D. 2 1e400 -1e400 True
Correct answer: C. 2 inf -inf True
2.9999999999999996 is the largest double below 3, so int truncates it to 2. Literals that overflow a double become infinity, and multiplying a huge finite float by 10 also overflows to inf.
More Python Programming questions
- What is printed? python print(10 % 3.5, -10 % 3.5, 10 // 3.5, round(-1.5), round(0.5) + round(1.5))
- What is printed? python print(divmod(7.5, 2), 7.5 % -2, -7.5 // 2)
- What is printed? python print(f'{0.1:.20f}'[:12], f'{2/3:.3f}', f'{1e22:.0f}', f'{1e23:.0f}')
- What is printed? python print(float(' 10.5 '), float('infinity'), float('-nan') != float('-nan'), float('10'))
- What is printed? python print(len(bytes(3)), bytes([65, 66]) == b'AB', bytearray(b'ab') == b'ab', type(b'a'[0]).name)
- What is printed? python s = 'abc' t = s s += 'd' print(s, t, s is t)