PY-21
Validate a Small Record
Task
Write validate_record(record). A record is a dictionary with three required
keys: id, value, and split. The function returns (valid, reason), where
valid is a Boolean and reason explains the result.
Check the requirements in this exact order:
- Check for the required keys in the order
id,value,split. If one is missing, return(False, "missing <key>")immediately. - An
idmust not be an empty string. Otherwise return(False, "empty id"). valuemust be between 0 and 100, including both boundaries. Otherwise return(False, "value out of range").splitmust be either"train"or"test". Otherwise return(False, "unknown split").
If all checks pass, return (True, "ok"). Inputs use the stated field types,
and the record must not be changed.
Example
The second result reports the empty identifier because it is the first failing rule; later fields are not allowed to change that reason.
Your implementation
Edit solution.py and keep this function name and signature:
Return exactly a two-item tuple containing a Boolean and one of the stated
reason strings. Do not print, ask for input, or mutate record.