ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
print(repr(1e16), repr(1e15 + 0.3), 1e16 == 10**16, 1e16 + 1 == 1e16)
- A. 1e+16 1000000000000000.2 True True
- B. 1e+16 1000000000000000.3 True True
- C. 1e+16 1000000000000000.2 False True
- D. 1e+16 1000000000000000.2 True False
Correct answer: A. 1e+16 1000000000000000.2 True True
Near 1e16 the gap between adjacent doubles is 2, so adding 1 rounds back to 1e16. repr shows the shortest string that round-trips, which is why 1e15 + 0.3 prints as ...0.2 rather than the decimal value you typed.
More Python Programming questions
- What is printed? python print(10 -2, 10.0 -2, 1000 10, 2 -1 4)
- What is printed? python print(bool(0.0), bool(-0.0), bool(float('nan')), bool(' '), bool('0'), bool(0j))
- What is printed? python s1 = 'u00e9' s2 = 'eu0301' print(s1 == s2, len(s1), len(s2), len(s2.encode()), s2 == 'eu0301')
- What is printed? python print(len('héllo'.encode('utf-8')), len('héllo'.encode('utf-16')), len('héllo'))
- What is printed? python print('abc' < 'abd', 'Z' < 'a', '10' < '9', [10] < [9], (1, 'b') < (1, 'a'))
- What is printed on the second line? python print(''.join(sorted('banana'))) print(sorted('Banana', key=str.lower)) print(sorted(['b10'…