question 94 Fundamentals Integration · easy
Check a hotel booking
A hotel's booking form sends a dictionary. Before confirming, check it and return the list of problems, in this order: the room type isn't one the hotel has; the number of nights isn't 1 to 14; the number of guests isn't at least 1 or is more than the room holds. An empty list means the booking is fine.
Function
booking_problems(booking)bookinga dictionary with
"room", "nights" and "guests"Rooms
CAPACITY = {"single": 1, "double": 2, "suite": 4} (given)Messages
"unknown room <room>", "nights must be 1-14", "too many guests for <room>" or "at least 1 guest"Rulethe guest check against capacity only happens for a known room
Examples
callbooking_problems({'room': 'double', 'nights': 3, 'guests': 3})returns['too many guests for double']
callbooking_problems({'room': 'single', 'nights': 2, 'guests': 1})returns[]
callbooking_problems({'room': 'loft', 'nights': 0, 'guests': 2})returns['unknown room loft', 'nights must be 1-14']