ProgrammingVery hardProduct company OA
What is printed?
What is printed?
def bucket(x, w):
return x // w, x % w, int(x / w), -(-x // w)
print(bucket(-7, 3), bucket(7, -3))- A. (-3, 2, -2, -2) (-2, 1, -2, -3)
- B. (-2, -1, -2, -3) (-2, 1, -2, -3)
- C. (-3, 2, -2, -2) (-3, -2, -2, -2)
- D. (-3, 2, -2, -3) (-3, -2, -2, -2)
Correct answer: C. (-3, 2, -2, -2) (-3, -2, -2, -2)
// floors toward −∞ and % takes the sign of the divisor so that x == (x // w) * w + x % w. −7 // 3 = −3 with remainder 2; int(−2.33) truncates to −2; −(7 // 3) = −2 is the ceiling idiom. For 7 and −3: 7 // −3 = −3, 7 % −3 = −2 (sign of −3), int(−2.33) = −2 and −(−7 // −3) = −(2) = −2. The (−2, −1, …) options are C-style truncating division.
More Python Programming questions
- What is printed? python d = {"b": 1, "a": 2, "c": 3} d["a"] = 9 d.update(b=7, d=4) d["c"] = d.pop("c") d.setdefault("a", 0) e = {d, "b"…
- What is printed? python a = [1, 2]; b = a; c = a[:] t = (a, c) a += [3] b = b + [4] c = 2 print(t[0] is a, b is a, t[1] is c, len(t[0])…
- What is printed? python a = list(range(8)) b = a[::2] a[1::2] = b[::-1] a[2:5] = [] del a[-2:] b[0] = 99 print(a, b)
- What is printed? python class Meter: unit = "m" def init(self): self.dict["v"] = 1 def getattr(self, name): return name.upper() def…
- What is printed? python def counter(): n = 0 def inc(k=1): nonlocal n n += k return n return inc c1, c2 = counter(), counter() g = (c1(i)…
- What is printed? python def f(): out = [] for i in range(4): try: if i == 1: continue if i == 2: raise KeyError(i) if i == 3: return out…