ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(float('0.1') + float('0.2') == 0.3, float('0.30000000000000004') == 0.1 + 0.2, repr(float('0.30000000000000004')), 0.1 + 0.2 == float(repr(0.1 + 0.2)))- A. False True 0.3 True
- B. True True 0.30000000000000004 True
- C. False True 0.30000000000000004 True
- D. False False 0.30000000000000004 True
Correct answer: C. False True 0.30000000000000004 True
0.1 + 0.2 is the double 0.30000000000000004, which is not the double for 0.3. repr gives the shortest string that round-trips, so converting it back gives the same value.
More Python Programming questions
- What is printed? python s = 'hello' print(s.index('l'), s.rindex('l'), s.find('z'), s.count('l'))
- What is printed? python print(int(str(264) 0 + '7') 2, len(str(7 100)), 7 100 % 10)
- What is printed? python from itertools import product print(list(map(''.join, product('ab', repeat=2))))
- What is printed? python print(sum(range(10 6)) % 1000, sum(range(1, 11)) // 5)
- What is printed? python print(('a' 'b' 'c').upper(), 'x' 'y' 2, ('%d' % 3) 2)
- What is printed? python print(1e16 == 1016, 1e16 + 1 == 1016 + 1, 1e16 + 2 == 1016 + 2, int(1e16) + 1)