LearnPy Hub
← Exceptions problems
Hard

A Family of Validation Errors

Define ValidationError(Exception) with subclasses MissingField, BadAge and BadEmail. Read records name,age,email until END; a field may be empty. Check in that order: empty name or email → MissingField, age not a whole number from 0 to 120 → BadAge, email without exactly one @ or without a dot after it → BadEmail. Print ok NAME or ErrorClass: message for each record, then counts per error class (alphabetical) for classes that happened.

Input

Lines, then END.

Output

Lines.

Sample 1

Input
Mim,15,mim@mail.com
,20,a@b.com
Rafi,200,r@x.org
Sara,30,sara.mail.com
END
Output
ok Mim
MissingField: name and email are required
BadAge: bad age '200'
BadEmail: bad email sara.mail.com
BadAge 1
BadEmail 1
MissingField 1

Sample 2

Input
Tom,1,t@t.io
END
Output
ok Tom
solution.py
Output appears here
A Family of Validation Errors · Python practice problem · LearnPy Hub