Survey answers with the same key twice
Predict the output · Medium · §4.1 By name, not by number
Survey answers are stored in a dictionary. Each key is a (name, question number) tuple, and each value is a score from 1 to 5. Because mina answered question 1 again, the same key went in twice. Predict the output without running the code.
Code
answers = {("mina", 1): 4, ("jun", 1): 2,
("mina", 2): 5, ("mina", 1): 3}
print(answers[("mina", 1)])
print(answers[("mina", 2)] + answers[("jun", 1)])Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.