ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
inventory = {"pen": 3, "ink": 0}
inventory["pad"] = inventory.get("pad", 0) + 5
inventory.update(ink=2)
print(sorted(inventory), sum(inventory.values()), "ink" in inventory and inventory["ink"] > 1)- A. ['pen', 'ink', 'pad'] 10 True
- B. ['ink', 'pad', 'pen'] 8 True
- C. ['ink', 'pad', 'pen'] 10 True
- D. ['ink', 'pad', 'pen'] 10 False
Correct answer: C. ['ink', 'pad', 'pen'] 10 True
sorted on a dict sorts its keys. After adding pad = 5 and setting ink = 2, the values are 3 + 2 + 5 = 10.
More Python Programming questions
- What is printed? python def area(w, h=None): if h is None: h = w return w h print(area(3), area(3, 4), area(h=2, w=5), area([2, 6]))
- What is printed? python q = [1, 2, 3] stack = [1, 2, 3] print(q.pop(0), stack.pop(), q, stack, q + stack)
- What is printed? python s = "2024-01-15" y, m, d = map(int, s.split("-")) print(y + m + d, f"{d:02d}/{m:02d}/{y}", s[5:7] == "01")
- What is printed? python scores = [("a", 50), ("b", 80), ("c", 65)] passed = [n for n, s in scores if s >= 60] top = max(scores, key=lambda…
- What is printed? python x = 7 kind = "even" if x % 2 == 0 else "odd" sign = "pos" if x > 0 else "zero" if x == 0 else "neg" print(kind…
- What is printed? python count = 0 for i in range(1, 4): for j in range(i): if (i + j) % 2: continue count += 1 print(count, i, j)