ggunel
(ggunel)
#1
Hello,I can find the least amount (540),but can not write code to show which city it is.How can I add city to this line of codes?
Thank you
def vacation_plan(flight,hotel_cost,car_rent):
cost_of_trip = flight+(hotel_cost*7)+car_rent
cost_of_trip=math.ceil(cost_of_trip)
return cost_of_trip
cities=(Paris,London,Dubai,Mumbai)
Paris = vacation_plan(200,20,200)
London = vacation_plan(250,30,120)
Dubai = vacation_plan(370,15,80)
Mumbai = vacation_plan(450,10,70)
least_amount_of_money=min(cities)
You cannot find the city name with directly with min()
function.
- Try to create a new function which gives you the min cost and city name.
- Or you can can replace the
set (cities)
you made with list
or dictionaries
.
azad32406
(azad azad)
#3
import math
cities={
‘Paris’:vacation_plan(200,20,200),
‘London’:vacation_plan(250,30,120),
‘Dubai’:vacation_plan(370,15,80),
‘Mumbai’:vacation_plan(450,10,70),
}
#Step 1: Convert dictionary keys and values into lists.
key_list=list(cities.keys())
print(key_list)
val_list=list(cities.values())
print(val_list)
#Step 2: Find the matching index from value list.
city=val_list.index(min(val_list))
print (city)
key_list[city]