ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(1.0 == 1, 1.5 // 0.5, 1.5 % 0.4, 2.0 ** -1074 > 0, 2.0 ** -1075 == 0)
- A. True 3.0 0.1 True True
- B. True 3.0 0.29999999999999993 False True
- C. True 3.0 0.29999999999999993 True True
- D. False 3.0 0.29999999999999993 True True
Correct answer: C. True 3.0 0.29999999999999993 True True
1.5 // 0.5 is exactly 3.0. 1.5 % 0.4 comes out just under 0.3 because 0.4 is stored a bit above its decimal value. 2 to the power -1074 is the smallest subnormal, while -1075 is a tie that rounds to zero.
More Python Programming questions
- What is printed? python print(float.fromhex('0x1p-2'), 0.25 == float.fromhex('0x1p-2'), float.fromhex('0x1.8p1'))
- What is printed? python print(divmod(10, 3)[::-1], divmod(-10, 3)[::-1], divmod(10, -3)[::-1])
- What is printed? python print(-5 % 3 == 1, 5 % -3 == -1, -5 // -3, 5 // -3)
- What is printed? python s = 'a-bc d' print(s.replace('-', ' ').replace('', ' ').split(), s.translate({45: None}))
- What is printed? python print('abc'.index('c') + 'abc'.rindex('a'), 'aXbXc'.rsplit('X', 1), 'a b'.title())
- What is printed? python import string print(string.asciilowercase.index('z'), string.digits[::-1][:3], string.asciiuppercase[25] +…