ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(f'{0.1:.20f}'[:12], f'{2/3:.3f}', f'{1e22:.0f}', f'{1e23:.0f}')- A. 0.1000000000 0.667 10000000000000000000000 100000000000000000000000
- B. 0.1000000000 0.667 10000000000000000000000 99999999999999991611392
- C. 0.1000000000 0.666 10000000000000000000000 99999999999999991611392
- D. 0.1000000000 0.667 1e+22 100000000000000000000000
Correct answer: B. 0.1000000000 0.667 10000000000000000000000 99999999999999991611392
Formatting with .0f shows the exact value stored in the double. 1e22 is exact, but 1e23 is stored as 99999999999999991611392, so the printed digits differ from the decimal you typed.
More Python Programming questions
- 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)
- What is printed? python a = [1, 2] b = a 2 b[0] = 9 c = a + a c[2] = 7 print(a, b, c)
- What is printed on the first line? python grid = [[0] 2] 2 grid[0][0] = 1 print(grid) g2 = [[0] 2 for in range(2)] g2[0][0] = 1 print(g2)
- What is printed? python t = (1, [2]) t[1].append(3) print(t, len(t)) try: t[0] = 5 except TypeError as e: print(type(e).name)