← 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"))
- A.order-1 order-2 order-3
- B.order-1 order-2 order-2
- C.order-1 order-1 order-2
- 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 →