#609 · Errors and exceptions · Intermediate · 80 XP · about 16 min
A sign-up form sends each person as a dictionary of text, such as {'name': ' Asha ', 'age': '15', 'email': 'Asha@School.org'}. Write check_records(records) that returns a tuple (good, problems):
good is a list of the clean records, in order. Each is a new dictionary with the keys 'name', 'age' and 'email': the name without spaces around it, the age as an int, and the email without spaces around it and in lower case.problems is a list of messages, one for each record that is not good, such as 'record 2: age is not a number'. Records are numbered from 1.Check each record in this order, and report only its first problem:
'record 3: missing age'. Check name, then age, then email.'record 3: name is empty'.int() cannot read: 'record 3: age is not a number'.'record 3: age out of range'.@: 'record 3: bad email'.check_records([ {'name': ' Asha ', 'age': '15', 'email': 'Asha@School.org'}, {'name': 'Ben', 'age': 'ten', 'email': 'ben@mail.com'}, {'name': 'Cara', 'email': 'cara@mail.com'}, ]) # returns ([{'name': 'Asha', 'age': 15, 'email': 'asha@school.org'}], # ['record 2: age is not a number', 'record 3: missing age'])
First solves only, ranked by stars and then time.