Hey, You Never Know!: What's wrong with this code?

  1. Hey, You Never Know!

Error Message:
" Oops, try again. trip_cost('Los Angeles', 0, 0) raised an error: unsupported operand type(s) for +: 'int' and 'function' "

I don't exactly see what the error message is trying to tell me. What's wrong with my code?

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


Consider rewriting this part of your code:

You're overthinking it.


Aside from the fact that spending_money thing indeed does not an alone function for it, I'm concerned about defining the function inside another function definition (spending_money inside of trip_cost). It kind of makes the code messy.


Defining a function inside another function is not necessarily a bad thing, although in this instance it is indeed not the best way to go.


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