books with three book entries and their authorsrequested_book with the name of the book to searchrequested_book is in books and handle errors with clear messagesJump into concepts and practice - no test required
books with three book entries and their authorsrequested_book with the name of the book to searchrequested_book is in books and handle errors with clear messagesbooks with these exact entries: '1984': 'George Orwell', 'To Kill a Mockingbird': 'Harper Lee', 'The Great Gatsby': 'F. Scott Fitzgerald'Use curly braces {} to create a dictionary with the exact book titles as keys and authors as values.
requested_book and set it to the string 'The Catcher in the Rye'Assign the exact string 'The Catcher in the Rye' to the variable requested_book.
if statement to check if requested_book is in books. If it is, create a variable result with the message "Found: {requested_book} by {author}". If not, set result to the error message "Error: '{requested_book}' not found in the library."Use an if statement to check membership and f-strings to create clear messages.
print statement to display the variable resultUse print(result) to show the message on the screen.
What is the main purpose of human-readable error messages in a REST API?
Which of the following is the correct JSON format for a human-readable error message in a REST API response?
{
"error": {
"code": 404,
"message": "Resource not found"
}
}Given this API response code snippet, what will be the output message?
response = {
"status": 400,
"error": {
"code": "INVALID_INPUT",
"message": "Input value is not valid"
}
}
print(response["error"]["message"])Identify the error in this REST API error response JSON and fix it for proper human-readable message format:
{
error: {
code: 401,
message: 'Unauthorized access'
}
}You want to design a REST API error response that helps users fix input errors quickly. Which approach is best?
{
"error": {
"code": "INVALID_EMAIL",
"message": "Email format is incorrect",
"field": "email",
"suggestion": "Use a valid email like user@example.com"
}
}