Read first
Task 52
Tally attendance with a dictionary
A dictionary counts things: start each key at 0, then add 1 for every name you see. `dict.get(key, 0)` keeps the first look-up from failing.
Task
Task: Tally attendance with a dictionary. What does this program print?
The editor already contains a starting point. Change it until every check passes — the Next task button unlocks when it does.
What you start with
present = ["Ali", "Sara", "Ali", "Hina", "Ali", "Sara"]
counts = {}
for name in present:
counts[name] = counts.get(name, 0) + 1
for name in sorted(counts):
print(name, "=", counts[name])
Python
1 automatic check Capstone: five small programs
Code editor
Ctrl + Enter runs
Run your code to see the output and the checks.
Your result
Submit your code to see results
Write your code in the middle column and press Run code.
Next task (pass every check first)
Hint
Ask yourself: Task: Tally attendance with a dictionary. What does this program print?