Taking a vacation help, stuck on the last part


#1



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


Not sure what I am supposed to do for this instruction:

It is completely valid to call the hotel_cost(nights) function with the variable days. Just like the example above where we call double(n) with the variable a, we pass the value of days to the new function in the argument nights.


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(city, days):
    return sum  (rental_car_cost(days), hotel_cost(days), plane_ride_cost(city))


Getting this error:
Oops, try again. trip_cost('Los Angeles', 3) raised an error: sum expected at most 2 arguments, got 3


#2

sum() is a list function, so if you wish to use it, write the arguments in a list.

return sum([ ... ])

#3

What about this error?


#4

return sum([rental_car_cost(days), hotel_cost(days), plane_ride_cost(city)])

#5

wow thank you! That's all I was missing huh? lol I feel so stupid now


#6

Don't sweat the small stuff. We all make mistakes. Learn from it and carry on.


#7

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):
    rental = 40 * days
    if days >= 7:
        rental -= 50
    elif days >= 3:
        rental -= 20
    return rental
def extra(spending_money):
    return 50 * spending_money
    
def trip_cost(city, days, spending_money):
    return sum ([rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + extra(spending_money)])

I keep getting stuck also. I've looked at all the other posts and still can't figure this out. I keep getting "Oops, try again. trip_cost('Los Angeles', 2, 40) returned 2835 instead of the correct value 875" If I keep hitting Save & Submit, I get the same error just different city and different outcomes. I've been trying to work on this on and off for awhile now.


#8

Not in the instructions, and neither is this,

The sum() example we worked out above is not meant as submission code, and should not be copied. Your code above is adding, so remove,

sum([   and   ])

The code should look like this:

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

#10

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