Put it together - cannot concatenate 'str' and 'NoneType' objects


I've got stucked here... been looking for the error but can't find it! some help pls!!!

Here is the link to the exercise (pull it together) https://www.codecademy.com/courses/python-beginner-P5YtY/1/4?curriculum_id=4f89dab3d788890003000096#

Here goes the error code "Oops, try again. trip_cost('Pittsburgh', 1) raised an error: cannot concatenate 'str' and 'NoneType' objects"

I thought it should work properly

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 (days * 40) - 50
    elif days >= 3:
        return (days * 40) - 20
        return days * 40

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


the exercise calls the function:

trip_cost('Pittsburgh', 1)

with the city as first argument, and the number of days as argument

Now look at your function parametrs


yes! as soon as i posted the problem I've thought that was te problem... indeed i change the order of arguments and it worked!!

I think that while checking the exercise guys from codeacademy should use a try and exept cicle...

indeed there is no way to know in witch order the check will call the arguments of the function!



the instructions:

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

if the parameters are given in this order in the instructions, you can expect the arguments to be in the same order


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