ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(1 - 0.9 == 0.1, round(1 - 0.9, 1) == 0.1, 1 - 0.9 > 0.09, 1 - 0.9)
- A. True True True 0.1
- B. False False True 0.1
- C. False True False 0.09999999999999998
- D. False True True 0.09999999999999998
Correct answer: D. False True True 0.09999999999999998
1 - 0.9 is a little below 0.1 in binary, so the direct equality fails. Rounding to one decimal recovers 0.1, and the difference is still greater than 0.09.
More Python Programming questions
- What is printed? python print(len('a1b22c333'.split('2')), ''.join(c for c in 'a1b22c333' if c.isdigit()), len('a1b22c333'))
- What is printed? python print(0.1 + 0.1 + 0.1 == 0.3, 0.1 3, 0.3 / 0.1, int(0.3 / 0.1))
- What is printed? python print(format(0.5, '.0f'), format(1.5, '.0f'), format(2.5, '.0f'), format(-0.5, '.0f'))
- What is printed? python print('ab' 2 == 'abab', 'ab' 0 == '', 'a' 2 + 'b' 0 == 'aa', ('x' 2).count('xx'))
- What is printed? python print(int('٣٣') 2, '٣٣'.isdigit(), '٣٣'.isascii(), '3' == '٣')
- What is printed? python import math print(math.gcd(0, -5), math.gcd(-4, -6), math.lcm(0, 5), math.lcm(-4, 6))