Failed to solve this problem. Please, Can anybody suggest solution?

this is the question:
You’re planning a vacation, and you need to decide which city you want to visit. You have shortlisted four cities and identified the return flight cost, daily hotel cost, and weekly car rental cost. While renting a car, you need to pay for entire weeks, even if you return the car sooner.

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:

  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 trip’s duration to four days, ten days or two 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.

My answer is :
Data = {City : [‘Paris’,‘London’,‘Dubai’,‘Mumbai’]
Return_Flight : [200,250,370,450]
Hotel_per_day : [20,30,15,10]
Weekly_Car_Rental : [200,120,80,70]
Duration_of_the_trip : input(int)}

One_Week >= 7

if Duration_of_the_trip > One_Week:
print(Weekly_Car_Rental = 2 * Weekly_Car_Rental

def cost_of_trip(City,Return_Flight,Hotel_per_day,Weekly_Car_Rental,Duration_of_the_trip):
total_cost_of_trip = Return_Flight + Hotel_per_day * Duration_of_the_trip + Weekly_Car_Rental

def cost_of_trip()

I have tried many ways but failed to do.

1 Like

To solve this you are going to need to define the cost_of_trip function. The cost of the trip is going to depend upon the duration of the trip in days. So in stating the problem in plain English, the total cost is going to be:

cost of the flight + (cost of hotel * duration in days) + (cost of car * duration in weeks)

To get the duration in weeks, you need to figure out how many weeks there are in the duration. For example: 1 - 7 days is 1 week, 8 - 14 days is 2 weeks, etc. The way to get this value is to divide the number of days by 7 and then round it up to the nearest integer value. This is where the math.ceil function is useful. the result of math.ceil(1 / 7) will be 1, math.ceil(8 / 7) will be 2 and so on.

Hope this helps you get started in solving the problem.


Thank you @fuzzyray .