ProgrammingModeratePython · GATE DA
What is printed?
What is printed?
print(7 // 2, -7 // 2, 7 % -3, divmod(-7, 2), 2 ** -1)
- A. 3 -3 1 (-3, -1) 0.5
- B. 3 -4 1 (-4, 1) 0
- C. 3 -4 -2 (-3, -1) 0.5
- D. 3 -4 -2 (-4, 1) 0.5
Correct answer: D. 3 -4 -2 (-4, 1) 0.5
// floors, so -7//2 = -4; the % result takes the sign of the divisor (7 % -3 = -2); divmod(-7, 2) = (-4, 1); 2**-1 is the float 0.5.
More Python Programming questions
- What is printed? python print({x % 3 for x in range(10)}, {x: x x for x in range(3)})
- What is printed? python def f(): try: return 'a' finally: print('f', end=' ') print(f())
- What is printed? python def g(): x = yield 1 print('got', x) y = yield x 2 print('got', y) it = g() print(next(it)) print(it.send(5)) try…
- What is printed? python def mk(): n = 0 def inc(): nonlocal n n += 1 return n return inc a, b = mk(), mk() print(a(), a(), b(), a())
- What is printed? python class C: v = [] n = 0 def add(self, x): self.v.append(x) self.n += 1 a, b = C(), C() a.add(1); b.add(2); b.add(3)…
- What is printed? python print(1 < 2 < 3, 3 > 2 > 2, 1 == 1 in [1], not 1 == 2, 2 3 2)