ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(0.1 * 3 == 0.3, 0.1 * 3 == 3 * 0.1, round(0.1 * 3, 1) == 0.3, 1 - 0.9 == 0.1)
- A. False False True False
- B. False True False True
- C. False True True False
- D. True True True False
Correct answer: C. False True True False
0.1 * 3 and 3 * 0.1 give the same rounded double, which is not 0.3. round() to one decimal recovers 0.3. The subtraction 1 - 0.9 is about 0.09999999999999998, so it is not equal to 0.1.
More Python Programming questions
- What is printed? python print('%s' % [1, 'a'], '%r' % 'a', '%5.2s|' % 'hello', '%c' % 65)
- What is printed? python print(hash(1.5) == hash(3/2), hash(True) == hash(1), {0: 'x', False: 'y'}, len({1: 'a', True: 'b', 1.0: 'c'}))
- What is printed? python print(min(3, 2.0, True), max(1, 1.0), max(1.0, 1))
- What is printed? python print(253 == float(253), 253 + 1 == float(253 + 1), 253 + 2 == float(253 + 2))
- What is printed? python s = 'atbnc' print(len(s), s.split(), s.split('n'), repr(s.split()[0]))
- What is printed? python from fractions import Fraction print(Fraction(3, 6), Fraction('0.75'), Fraction(0.75), Fraction(1, 3) +…