5 | Pulling It Together


#1

Hi! I need a bit of help here.

So, I enter what I believe to be is the correct code, but rather, I get this error message:
"Oops, try again. trip_cost('Tampa', 6) raised an error: cannot concatenate 'str' and 'NoneType' objects"

What exactly am I doing wrong?
Here's my code for reference:

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


#2

Hi to your function

def trip_cost(days, city):

try to put first city then days


#3

I have the same problem


#4

Hi you should post your code.


#5

This is my code , it works

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


#6

heres my code..if you guys find any mistakes please notify me...thnks in advance

my code starts here

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):
sum = hotel_cost(days) + Plane_ride_cost(city) + rental_car_cost(days)
return trip_cost


#7

u should put in the end " return sum" to return how much cost, not the function :wink:


#8

SI there a reason why you have to put the variable containing a string first?


#9

Hi it's just the lesson that want you to put it in this order. But if you run it outside codecademy you could put it any order you want but for example if you put it like that

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

you will call it like that

trip_cost(5, "Los Angeles")

you will put first the days then the city


#11