Loading...
Loading...
A sign-up form has three lines: name, age and email. Check each field and print one line for each, in this order.
Name: print name: ok, or name: Name is required if it is empty after removing spaces. Age: print age: ok, or age: Age must be a number if it is not a whole number, or age: Age must be between 18 and 100. Email: print email: ok, or email: Email must contain @.
Last, print Form valid if all three are ok, otherwise Form has <count> errors. Use raise ValueError(message) for each rule and one except ValueError as err.
Example 1
Input
Asha 25 asha@example.com
Output
name: ok age: ok email: ok Form valid
Everything is correct.
Example 2
Input
abc asha.example.com
Output
name: Name is required age: Age must be a number email: Email must contain @ Form has 3 errors
Everything is wrong.
Try the problem first. Open one hint at a time.
Write one small check for each field that raises ValueError with its own message. A bad age text needs the message Age must be a number.
Loop over the three fields, run each check inside try, print ok in else, and count the errors in except.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor