ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(0.1 + 0.1 + 0.1 == 0.3, 0.1 * 3, 0.3 / 0.1, int(0.3 / 0.1))
- A. False 0.3 3.0 3
- B. False 0.30000000000000004 3.0 3
- C. False 0.30000000000000004 2.9999999999999996 2
- D. True 0.30000000000000004 2.9999999999999996 2
Correct answer: C. False 0.30000000000000004 2.9999999999999996 2
Adding 0.1 three times gives 0.30000000000000004, so the first check is False. Dividing 0.3 by 0.1 gives 2.9999999999999996 because 0.3 is slightly below its ideal value, so int truncates to 2.
More Python Programming questions
- 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))
- What is printed? python print(len('%.3f' % 260), '%.3f' % 260, '%.0f' % 1e20)
- What is printed? python print(round(1e16 + 2), round(9.5), round(10.5), round(-9.5))