Validation error details
📖 Scenario: You are building a simple REST API that accepts user data. You want to check if the data is valid and show clear error messages when it is not.
🎯 Goal: Create a Python dictionary with user data, set a validation rule, check the data against the rule, and print detailed error messages if the data is invalid.
📋 What You'll Learn
Create a dictionary called
user_data with keys name and age and exact values 'Alice' and 17Create a variable called
min_age and set it to 18Use an
if statement to check if user_data['age'] is less than min_age and create an error message string called error_messagePrint the
error_message string💡 Why This Matters
🌍 Real World
APIs often need to check if user input is correct and show clear error messages to help users fix mistakes.
💼 Career
Understanding validation and error messages is important for backend developers, API designers, and anyone working with user input.
Progress0 / 4 steps