Learn practical skills, build real-world projects, and advance your career

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).

CityReturn Flight ($)Hotel per day ($)Weekly Car Rental ($)
Paris20020200
London25030120
Dubai3701580
Mumbai4501070

Answer the following questions using the data above:

  1. If you're planning a 1-week long trip, which city should you visit to spend the least amount of money?
  2. 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?
  3. 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?
  4. 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.

import math
Paris = dict(name="Paris",flight=200, hotel=20, car=200)
London = dict(name="London",flight=250, hotel=30, car=120)
Dubai = dict(name="Dubai",flight=370, hotel=15, car=80)
Mumbai = dict(name="Mumbai",flight=450, hotel=10, car=70)

cities = [Paris,London,Dubai,Mumbai]
# Function to return the name of the cheapest holiday destination for X given days
def cheapest_holiday():
    cost_list = []
    days = int(input("How many days would you like to stay for? "))
    for city in cities:
        cost_of_stay = city["flight"] + (city["hotel"] * days) + (city["car"] * math.ceil(days/7))
        cost_list.append(cost_of_stay)
    min_cost = min(cost_list)
    if days ==1:
        print("The minimum cost for a holiday for 1 day is £{}. This would be to {}.".format(min_cost, city ))
    else:
        print("The minimum cost for a holiday for {} days is £{}. This would be to {}.".format(days, min_cost, city))
cheapest_holiday()
How many days would you like to stay for? 1 The minimum cost for a holiday for 1 day is £400. This would be to {'name': 'Mumbai', 'flight': 450, 'hotel': 10, 'car': 70}.