ProgrammingVery hardTCS NQT · Accenture
What is printed?
What is printed?
print(10 ** -1 == 0.1, 10 ** 0.5 == 10 ** (1 / 2), int(10 ** 0.5) ** 2 == 10, round(10 ** 0.5 * 10 ** 0.5, 9))
- A. True True True 10.0
- B. True False False 10
- C. True True False 10.0
- D. True True False 9.0
Correct answer: C. True True False 10.0
int() truncates 3.16 to 3, and 3 squared is 9, not 10. Multiplying the float square roots gives 10.0 after rounding, while 10 ** -1 is the same double as the literal 0.1.
More Python Programming questions
- What is printed? python from functools import cmptokey print(sorted(['10', '9', '2'], key=cmptokey(lambda a, b: int(a) - int(b))))
- What is printed? python print(1 << 31 >> 31, (1 << 31) >> 31 == 1, -1 >> 31, -231 >> 31)
- What is printed? python print('1' + '2' 3, '1' 2 + '2', len('ab' 0 + 'c' 3), 'x' 2 == 'xx')
- What is printed? python from math import gcd, lcm print(gcd(-12, 18), gcd(0, 0), lcm(4, 6), gcd(2100, 650) == 250)
- What is printed? python print(0.5 == 1/2, 0.1 + 0.4 == 0.5, 0.25 + 0.25 == 0.5, 0.7 + 0.1 == 0.8)
- What is printed? python x = 255 print(x.tobytes(2, 'little'), int.frombytes(b'x01x02', 'little'), (258).tobytes(2, 'big').hex())