Pull it together


def hotel_cost(days):
return 140 * days

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

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

def trip_cost(city, days):
city = "Charlotte"
days = 7
return city + days

Above is the code I got during the exercises. I get an error that states "Oops, try again. trip_cost('Los Angeles', 5) raised an error: cannot concatenate 'str' and 'int' objects." I've tried adding data type identifiers and a whole slew of changes to the trip_cost function. Any help would be appreciated.


city + days
is not the same as
city, days


The error message is a bit misleading. It's true that the trip_cost function given above attempts to put a string with an int. However, that's not what the function is meant to do. 'trip_cost' is supposed to call the other functions using its' arguments 'city' and 'days'. Also, by hard-coding 'city' and days', the function loses it's ability to be dynamic which is why it mentions the error about LA. Codecademy tests for both Charlotte and LA.

To fix the error, try returning the sum of the other functions when 'city' and 'days' are passed through them.

Hope this helps! If not, feel free to reply and I'll try to go more in-depth.


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