Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Exercise - Data Analysis for Vacation Planning
You're planning a leisure trip (vacation) and you need to decide which city you want to visit. You have shortlisted 4 cities, and identified the cost of the return flight, daily hotel cost and a weekly car rental cost (a car has to be rented for full weeks, even if you return the car before a week ends).
City | Return Flight ($ ) | Hotel per day ($ ) | Weekly Car Rental ($ ) |
---|---|---|---|
Paris | 200 | 20 | 200 |
London | 250 | 30 | 120 |
Dubai | 370 | 15 | 80 |
Mumbai | 450 | 10 | 70 |
Answer the following questions using the data above:
- If you're planning a 1-week long trip, which city should you visit to spend the least amount of money?
- How does the answer to the previous question change if you change the duration of the trip to 4 days, 10 days or 2 weeks?
- If your total budget for the trip is
$1000
, which city should you visit to maximize the duration of your trip? Which city should you visit if you want to minimize the duration? - How does the answer to the previous question change if your budget is
$600
,$2000
or$1500
?
Hint: To answer these questions, it will help to define a function cost_of_trip
with relevant inputs like flight cost, hotel rate, car rental rate and duration of the trip. You may find the math.ceil
function useful for calculating the total cost of car rental.
matrix= [{'city':'Paris','flight':200,'hotel':20,'car':200},
{'city':'London','flight':250,'hotel':30,'car':120},
{'city':'Dubai','flight':370,'hotel':15,'car':80},
{'city':'Mumbai','flight':450,'hotel':10,'car':70},
]
import math
def cost_of_trip(cost_flight,cost_hotel,cost_car,duration): #duration in days
time_week=math.ceil(duration/7) #duration in weeks
cost=cost_flight+cost_hotel*duration+cost_car*time_week
return cost
duration=4 #in days
matrix_total=dict() #this dictionary will contain the total amount of each trip, and the name of the city.
for trip in matrix:
place=trip['city']
c_flight=trip['flight']
c_hotel=trip['hotel']
c_car=trip['car']
total_cost=cost_of_trip(c_flight,c_hotel,c_car,duration) #calculation of the cost of each trip using the def function.
print('The total cost of the trip in {} for {} days is ${}'.format(place,duration,total_cost))
matrix_total[total_cost]=place #this is made to reverse the order. The key will be the amount of the trip, the value
#will be the city.
The total cost of the trip in Paris for 4 days is $480
The total cost of the trip in London for 4 days is $490
The total cost of the trip in Dubai for 4 days is $510
The total cost of the trip in Mumbai for 4 days is $560
print(matrix_total)
{480: 'Paris', 490: 'London', 510: 'Dubai', 560: 'Mumbai'}