5. Pull it together


#1



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

Oops, try again. trip_cost('Charlotte', 5) raised an error: unsupported operand type(s) for +: 'int' and 'NoneType'

I'm trying to figure out what I'm doing wrong, can anyone please explain it to me? Thanks

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):
    total = days * 40
    if days >= 7 :
        total = total - 50
    elif days >= 3 and days < 7 :
        total = (days * 40) - 20
    return total
    
def trip_cost(city, days):
    return hotel_cost(days) + plane_ride_cost(days) + rental_car_cost(days)


#2

Hi, @ricardot66 ,

Note that the plane_ride_cost function takes a string as an argument, which should be the name of a city ...

def plane_ride_cost(city):

Here, within the trip_cost function, you are passing it days, instead, which will be an integer, and this will ultimately raise an error ...

return hotel_cost(days) + plane_ride_cost(days) + rental_car_cost(days)

#3

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