ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(abs(-2**63) == 2**63, abs(-0.0) == 0.0, abs(-2.5) // 1, -2.5 // 1 * -1)
- A. True True 2.0 2.0
- B. False True 2.0 3.0
- C. True False 2.0 3.0
- D. True True 2.0 3.0
Correct answer: D. True True 2.0 3.0
abs of a negative int gives its magnitude, and abs(-2.5) // 1 is 2.0. In -2.5 // 1 * -1 the floor division gives -3.0 first, and the multiplication by -1 makes it 3.0.
More Python Programming questions
- What is printed on the second line? python import math print(math.gcd(12, 18, 24), math.gcd(), math.lcm(), math.lcm(4, 0, 9))…
- Which line is printed? python print(divmod(270, 106)[1] == 270 % 106, divmod(-270, 106)[1] == (-270) % 106, (-270) // 106 == -(270 // 106)…
- What is printed? python from collections import Counter print(Counter('mississippi').mostcommon(3))
- What is printed? python from functools import lrucache @lrucache(None) def total(xs): return sum(xs) try: print(total([1, 2, 3])) except…
- What is printed? python import bisect print(bisect.bisectleft(range(100), True, key=lambda x: x x >= 50))
- What is printed? python n = 30 s = [True] (n + 1) s[0] = s[1] = False for i in range(2, int(n 0.5) + 1): if s[i]: s[i i::i] = [False]…