Exercise Data Analysis on Vacation Planning

I have a question on the exercise for data analysis on vacation planning. How are we reaching to an equation of duration from the budget given? I Have checked few of the logic, but per my understanding the calculations are wrong in those cases.

Unable to wrap my head around some logic apart from the one I have mentioned below:

import math

def best_duration(return_flight_cost, hotel_per_day_cost, weekly_car_rental, budget):
duration = math.ceil((budget - return_flight_cost) / (hotel_per_day_cost + math.ceil(weekly_car_rental / 7)))
return duration

budget_for_trip = int(input(‘Enter the amount you would like to spend for your vacation:’))

duration_for_paris = best_duration(200, 20, 200, budget_for_trip)
duration_for_london = best_duration(250, 30, 120, budget_for_trip)
duration_for_dubai = best_duration(370, 15, 80, budget_for_trip)
duration_for_mumbai = best_duration(450, 10, 70, budget_for_trip)

minimum_duration = min(duration_for_paris, duration_for_london, duration_for_dubai, duration_for_mumbai)
maximum_duration = max(duration_for_paris, duration_for_london, duration_for_dubai, duration_for_mumbai)

if minimum_duration == duration_for_paris:
print(f’Under the budget of ${budget_for_trip} best city to visit for minimum duration is “Paris”.’)
if minimum_duration == duration_for_london:
print(f’Under the budget of ${budget_for_trip} best city to visit for minimum duration is “London”.’)
if minimum_duration == duration_for_dubai:
print(f’Under the budget of ${budget_for_trip} best city to visit for minimum duration is “Dubai”.’)
if minimum_duration == duration_for_mumbai:
print(f’Under the budget of ${budget_for_trip} best city to visit for minimum duration is “Mumbai”.’)

if maximum_duration == duration_for_paris:
print(f’Under the budget of ${budget_for_trip} best city to visit for maximum duration is “Paris”.’)
if maximum_duration == duration_for_london:
print(f’Under the budget of ${budget_for_trip} best city to visit for maximum duration is “London”.’)
if maximum_duration == duration_for_dubai:
print(f’Under the budget of ${budget_for_trip} best city to visit for maximum duration is “Dubai”.’)
if maximum_duration == duration_for_mumbai:
print(f’Under the budget of ${budget_for_trip} best city to visit for maximum duration is “Mumbai”.’)

Umm, it would be helpful if you wrote your code in the code format.
You can do that by highlighting the text and pressing ctrl+shift+c.

Irrespective, let me try and go through your question.

Thank you Himani for replying. I am only confused with the problem, as the factors hotel per day and weekly car rental do not have same multiplier we are using the math.ceil function for duration in first case where we are calculating the expenditure for the place with minimum cost for certain number of days. But when we calculate the same problem with the expenditure fixed and duration as variable things would change drastically. So what I did, I calculated the duration in weeks and then suggested the place with minimum and maximum duration which would be more than one city. That is my concern for the problem. I have seen others approaching the problem with different angles, but that seems like an incorrect approach to me. I just want to understand the logic to approach the problem, from there on we can write the code.

Can you send me the link to where this question was? I don’t remember from which optional exercise did this question belong.

aakashns/python-functions-and-scope - Jovian is the link. Please check and although I got an Idea of the logic that I may have to use in this case. I will implement that today and try to approach the problem in different ways. Thank you for the support, but please let me know your approach towards the problem as well. Would appreciate your help.

Sorry for so much delay did your other logic work?

For me, (For the first and second parts)I would create a function that takes the input number of days for the vacation, calculates costs for all cities with the same number of days, and returns the city with the minimal cost.
(For the third part), I’d create a function that takes the budget and then returns the number of days, by calculating costs for each day for each city for minimizing and maximizing the num of days.