Sign-Up Desk

Python for AIMedium+10 XP+10

Sign-Up Desk

A club checks every new username before it's saved.

Write two functions:

  1. clean_username(name) removes spaces from both ends and makes the name lowercase. Then:
    • if the cleaned name is empty, raise ValueError("username is empty")
    • if it has more than 10 characters, raise ValueError("username is too long")
    • otherwise return the cleaned name
  2. sign_up(names) runs clean_username on every name in order. It returns a dictionary:
    • "accepted": the list of cleaned names that worked
    • "refused": the list of error messages, as text, for the ones that didn't

Examples

names = [" Ana ", "", "Bartholomew"]
returns {'accepted': ['ana'], 'refused': ['username is empty', 'username is too long']}
name = " MAYA "
returns 'maya'

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run