Beginner
Validate a reply and say what is wrong
Write validate(data, spec) where data is a dictionary and spec maps field names to "string", "integer" or "boolean". Return a list of problems, in the order of spec.
A field that is not in data gives "<name>: missing". A field of the wrong type gives "<name>: expected <wanted>, got <found>", where the found type is one of string, integer, boolean or other. Remember that True is not an integer here. A good reply gives [].
What Check tests
- A good reply gives no problems
- A missing field
- A wrong type
- True is not an integer
- Several problems, in spec order
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.