Pull it together question


#1



https://www.codecademy.com/courses/python-beginner-P5YtY/1/4?curriculum_id=4f89dab3d788890003000096#


Oops, try again. trip_cost('Charlotte', 0) raised an error: unsupported operand type(s) for -: 'str' and 'int'

it does not work with that order in the last function (days, city) howver, it works if the order is (city, days) I dont get why!

Replace this line with your 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
def rental_car_cost(days):
    if days>=7:
        return 40*days - 50
    elif days>=3:
        return 40*days - 20
    else:
        return 40*days
def trip_cost(days, city):
    return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)


#2

Hi @juanarcila ,

The instructions include the following ...

Below your existing code, define a function called trip_cost that takes two arguments, city and days.

Codecademy is expecting you have the parameters city and days in that order in the function header. When Codecademy's submission correctness test (SCT) tested your trip_cost function, passing it arguments in the expected order, the unsupported operand type(s) for -: 'str' and 'int' error was raised.

Before you make the necessary correction, try to figure out why having the order of the parameters switched in the function header led to the particular error message that it did. Although the first impression might be that the error message has no relationship to the order of the parameters, there actually is a connection.


#3

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