question 79 Dictionaries & Sets · medium
Check user records from an API
An API returns users as a dictionary from user ID to a record. Before importing them, check each record and print one line per problem: <id>: missing email when there is no email key or it is blank, <id>: bad email when the email has no @, <id>: missing age when there is no age key, and <id>: age <n> out of range when the age is below 13 or above 120. A user can have an email problem and an age problem. Finish with <k> of <n> users valid.
Input
users, a dictionary from user ID to a dictionary that may hold "email" (text) and "age" (a whole number)Printsthe problem lines in user order (email before age), then
<k> of <n> users validValid ages13 to 120, both included
Examplesthe starter's users print problems for U02, U03 and U04, then
1 of 4 users validExpected output6 lines
- 1U02: missing email
- 2U02: age 9 out of range
- 3U03: missing email
- 4U04: bad email
- 5U04: age 130 out of range
- 61 of 4 users valid