ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(repr(0.1), repr(1 / 3), repr(2 / 3), repr(1e-7), repr(100.0))
- A. 0.1 0.333333333333333 0.666666666666667 1e-07 100.0
- B. 0.1 0.3333333333333333 0.6666666666666666 1e-07 100.0
- C. 0.1 0.3333333333333333 0.6666666666666666 0.0000001 100.0
- D. 0.1 0.3333333333333333 0.6666666666666666 1e-7 100
Correct answer: B. 0.1 0.3333333333333333 0.6666666666666666 1e-07 100.0
repr gives the shortest string that reads back as the same double, so 1/3 needs 16 digits. Small floats use exponent form with at least two exponent digits, so 1e-7 prints as 1e-07.
More Python Programming questions
- What is printed? python print(0.1 3 != 0.3, abs(0.1 3 - 0.3) < 2-52, abs(0.1 3 - 0.3) < 2-54)
- What is printed? python print(bin(255)[2:].rjust(10, '0'), int('0b' + '1' 8, 2) == 255, int('11111111', 2) + 0 == 255)
- What is printed? python s = 'hello world' print(s.count('o'), s.index('o', 5), s.title().split()[1][::-1])
- What is printed? python print(list(reversed(range(3))), list(range(3))[::-1] == list(reversed(range(3))), list(range(3, 0, -1)))
- What is printed? python print('Python'[::2], 'Python'[1::2], 'Python'[-2::-2])
- What is printed? python x = 3.0 print(x.isinteger(), (3.5).isinteger(), int(x) is x, type(int(x)).name)