Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
!pip install jovian --upgrade --quiet
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.
class City:
def __init__(self,rf,hpd,wcr,na):
self.return_flight = rf
self.hotel_per_day = hpd
self.weekly_car_rental = wcr
self.name = na
Paris=City(200,20,200,"Paris")
London = City(250,30,120,"London")
Dubai = City(370,15,80,"Dubai")
Mumbai = City(450,10,70,"Mumbai")
Cities = [Paris,London,Dubai,Mumbai]
import math
def cost_of_trip(flight,hotel_cost,car_rent,num_of_days=0):
return flight*2+hotel_cost*num_of_days+car_rent*math.ceil(num_of_days/7)
def days_to_visit(days):
min_cost_di = {}
for city in Cities:
cost=cost_of_trip(city.return_flight,city.hotel_per_day,city.weekly_car_rental,days)
if min_cost_di.get(cost) is None:
min_cost_di[cost]=[]
min_cost_di[cost].append(city.name)
min_cost = min(list(min_cost_di.keys()))
return min_cost_di[min_cost],min_cost
# print(min_cost_di)
# For 1 week long trip
city,min_cost = days_to_visit(1)
print(*city,min_cost)
Paris 620