trip_cost('Charlotte', 6) raised an error: unsupported operand type(s) for -=: 'str' and 'int'


#1

PLZ Help

My code is >>>

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

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

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

Error is >>> trip_cost('Charlotte', 6) raised an error: unsupported operand type(s) for -=: 'str' and 'int'
Whats wrong ?


#2

Hi @wan2ted123,

You have the function parameters in the wrong order here ...

def trip_cost(days, city):

Codecademy expects city to be first and days to be second. The message reveals that when the function was called for testing purposes, as follows, it raised an error ...

trip_cost('Charlotte', 6)

#3

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