Pull it all together


#1

Hey guys, there is something I don’t understand. If I layout the arguments in the trip_cost function like this:
def trip_cost(city, days):
then the code works. however if I lay them out like this:
def trip_cost(days, city):
AND change the order of the return statement so that the functions with days as parameters are in front of the one with city as a parameter, my code doesn’t work and I was wondering why.

This is my code:

def hotel_cost(nights):
return 140*nights

def plane_ride_cost(city):
if city == “Charlotte”:
return 183
elif city == “Tampa”:
return 220
elif city == “Pittsburgh”:
return 222
elif city == “Los Angeles”:
return 475
else:
return 0

def rental_car_cost(days):
price = 40*days
if days >= 7:
return price - 50
elif days >= 3 and days < 7:
return price - 20
return price

def trip_cost(city, days):
return plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days)

Thanks all

#2

to verify the code works correctly, there are test cases. The test cases for this exercise involve function calls for trip_cost. The first argument will be the city (for example “Tampa”) and the second argument the number of days

so you need to have your function parameters in the right order to make it work


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.