Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
# Created a dictionary with the cost data.
cities = {
'paris': [200, 20, 200],
'london': [250, 30, 120],
'dubai': [370, 15, 80],
'mumbai': [450, 10, 70]
}
# Define cost function
import math
def cost_of_trip(city, days):
flight = cities[city][0]
hotel = cities[city][1]
car = cities[city][2]
weeks = math.ceil(days/7)
cost = flight + (hotel * days) + (car * weeks)
return cost
print (cost_of_trip('paris', 7))
print (cost_of_trip('london', 7))
print (cost_of_trip('dubai', 7))
print (cost_of_trip('mumbai', 7))
# See vacation costs for all locations simultaneously
output_template = "The cost of a {} day trip to {} is ${}"
for key in cities:
days = 14
cost_of_trip(key, days)
print(output_template.format(days, key, cost_of_trip(key, days)))
# Calculate max stay for budget at one place
budget = 1000
i = 1
output = 'The max stay is {} days'
while cost_of_trip('mumbai', i) < budget:
i += 1
if cost_of_trip('mumbai', i) >= budget:
print (output.format(i-1))
# Calculate max stay for budget (simultaneous)
budget = 2000
i = 1
output = 'The longest you can stay in {} for {} is {} days'
for key in cities:
while cost_of_trip(key, i) < budget:
i += 1
if cost_of_trip(key, i) >= budget:
print (output.format(key, budget, i-1))
!pip install jovian --upgrade --quiet