← Quiz: Routing Algorithms: all 10 questions
Quiz: Routing Algorithms · Question 9 of 10
What does this print? (code)
What does this print?
cost = {"Y": 3, "Z": 1}
their = {"Y": 2, "Z": 6}
best = min(cost, key=lambda v: cost[v] + their[v])
print(best, cost[best] + their[best])
- A.Z 7
- B.Z 1
- C.Y 5
- D.Y 2
Answer & explanation
Correct answer: Y 5
Y gives 3 + 2 = 5 and Z gives 1 + 6 = 7, so Y wins with 5.
Can you get the rest right without peeking?
Take the timed Quiz: Routing Algorithms quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →