ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
import math print(math.gcd(-12, 18), math.gcd(12, -18), math.lcm(-4, 6), math.gcd(0, 0))
- A. 6 6 12 1
- B. 6 6 12 0
- C. 6 6 6 0
- D. 6 6 24 0
Correct answer: B. 6 6 12 0
gcd always returns a non-negative value, so the signs of the inputs do not matter. lcm(-4, 6) is 12, and gcd(0, 0) is defined as 0.
More Python Programming questions
- What is printed? python def digitssum(n): return sum(int(c) for c in str(abs(n))) print(digitssum(-9075), digitssum(1020), digitssum(0))
- What is printed? python x = 1020 + 1 y = float(x) print(int(y) == x, int(y) - x, y == 1020, float(x) == y)
- What is printed? python import math print(math.floor(1e300) == 10300, math.floor(1e300) == int(1e300), round(1e300) == 10300)
- What is printed? python print(0.1 + 0.2 != 0.3, (0.1 + 0.2) - 0.3 < 1e-16, abs((0.1 + 0.2) - 0.3) <= 5e-17)
- What is printed? python print(max('zebra', 'Zebra'), min('a', 'B'), sorted('bA', key=ord)[0], 'bA' > 'Ab')
- What is printed? python print([1, 2] < [1, 2, 0], [1, 2] < [1, 3, 0], (1, 2) < (1, 2, 0), 'ab' < 'abc')