Given a dictionary of login attempts logins = {'alice': 3, 'bob': 50, 'charlie': 5}.
Nopal Securities technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Given a dictionary of login attempts logins = {'alice': 3, 'bob': 50, 'charlie': 5}. Which code snippet correctly prints the username and count for users with strictly more than 10 attempts?
Show answer & explanation
Answer: C. for user, count in logins.items():
if count > 10:
print(user, count)
logins.items() yields (key, value) pairs. Filtering with count > 10 prints both the user and attempt count for matching records.
Step-by-step Derivation:
Step 1: Accessing both key and value requires dictionary.items().
Step 2: Condition strictly greater than 10 is 'count > 10'.
Step 3: Option C correctly implements this logic.