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


#1

Hi,
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


#Hotel
def hotel_cost(nights):
    return 140 * nights

#Plane
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

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


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


#2

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


#3

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!

THX!!


#4

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


#5

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