🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: API Design: all 15 questions

Quiz: API Design · Question 7 of 15

What does this print? (code)

What does this print?

seen = {}
count = 0
def create_order(key):
    global count
    if key in seen:
        return seen[key]
    count += 1
    seen[key] = "order-" + str(count)
    return seen[key]
print(create_order("a"), create_order("a"), create_order("b"))
  1. A.order-1 order-2 order-3
  2. B.order-1 order-2 order-2
  3. C.order-1 order-1 order-2
  4. D.order-1 order-1 order-1
Answer & explanation

Correct answer: order-1 order-1 order-2

The second call with key "a" replays the saved result; key "b" creates the second order.

Can you get the rest right without peeking?

Take the timed Quiz: API Design quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →