Collect Every Form Error

Medium ⏱ 12 min 57% acceptance ★★★★☆ 4.2
A signup form needs name (non-empty), age (int-parseable, 18+), and email (contains '@'). Write validate(form) — a dict of strings — returning a list of ALL failure messages ('bad name', 'bad age', 'bad email'), not just the first. Use try/except around the age parse; empty list means valid.

Examples

Example 1
Input
validate({'name': '', 'age': 'xx', 'email': 'a@b.c'})
Output
['bad name', 'bad age']
Explanation

Two independent failures are both reported.

Constraints

  • Report all errors, in name/age/email order.
  • Age must parse AND be >= 18.

Topics

Exception Handlingvalidation aggregation

Companies

MetaSalesforceServiceNow

Hints

Hint 1

Each check appends independently — no early return.

Hint 2

The int() call needs its own try/except.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.