Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I: Vacation Cost Calculator (20 points) You are a travel agent and have been tasked with making reservations for a large group of people

Part I: Vacation Cost Calculator (20 points)

You are a travel agent and have been tasked with making reservations for a large group of people with a fixed budget staying at a resort hotel for a week. Each kind of room (Normal, Double, King, Suite) has a fixed price to rent for the week.

Complete the function vacation calculator that takes arguments in the following order:

CSE 101 Spring 2018 Lab #8 Page 1

1. room prices: A dictionary that maps a type of room (a string) to the price of the room (an integer). 2. budget: An integer value that represents the maximum amount of money the group will spend for the

hotel stay.

3. reservations: A list of sub-lists wherein the first element of a sub-list contains the type of room being reserved, and the second element is the desired count of rooms of that type. For example, the sub-list [King, 3]wouldindicatethat3Kingroomsaredesired.

The function iterates over the reservations list, extracting the room type and room count of each reservation. Room types can appear multiple times in the list. Then, the function looks up the price of the desired room using the room prices dictionary and computes what it would cost to reserve the desired number of rooms. You may assume that the room type in the reservation always has a corresponding price in room prices. If there is money left in the budget to accept the reservation, the function (i) appends the sub-list to a result list and (ii) subtracts the cost of the reservation from the budget. If a certain reservation in reservations list does not fit within the remaining budget, the function skips over that reservation and moves on to the next one in the list.

At the end, the function returns two values in a tuple: the total spent on the vacation, followed by the list of reservations that were accepted by the resort.

Examples:

Function Call

Return Values

vacation calculator([{Normal: 70, Double: 105, King: 195, Suite: 249}, 543, [[Normal, 1], [Suite, 2], [Double, 2], [Normal, 1], [King, 3]]])

(350, [[Normal, 1], [Double, 2], [Normal, 1]]) 

vacation calculator([{Normal: 72, Double: 133, King: 192, Suite: 246}, 255, [[King, 3], [Suite, 1], [King, 1], [Normal, 1], [King, 2], [Double, 3], [Suite, 3]]])

(246, [[Suite, 1]]) 

vacation calculator([{Normal: 85, Double: 148, King: 190, Suite: 239}, 319, [[Suite, 1], [Double, 1], [Normal, 2], [Double, 2], [Double, 2], [Suite, 2]]])

(239, [[Suite, 1]]) 
In python please and this is an 101 course so please use beginner codes.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions