-2

I'm making a model for vacation costs in a code academy exercise, and I have three functions defined so far, rental_car_costs with the argument days, hotel_cost with the argument nights, and plane_ride_cost with the argument of city. The code looks like this:

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

    def plane_ride_cost(city):
        return plane_ride_cost(city)
        if "Charlotte":
            return 183
        elif "Tampa":
            return 220
        elif "Pittsburgh":
            return 222
        elif "Los Angeles":
            return 475

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

All that works and I have no problem with it, but I want to make a function called trip_cost, and I keep getting a maximum recursion depth exceeded. The code looks like this

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

I pass the value of nights to days, and just in case I've tried substituting nights in anyway, but I still get the exact same error message. What am I doing wrong, and what does maximum depth recursion exceeded mean?

Shubham
  • 2,847
  • 4
  • 24
  • 37
  • Welcome to stackoverflow. Your question lacks details. Read this: http://stackoverflow.com/help/how-to-ask – Shubham Jul 25 '16 at 11:46
  • I took away the "return hotel_cost(days)" , which is what was stated as being the problem, but now it says "plane_ride_cost('Charlotte') raised an error: maximum recursion depth exceeded" I tried taking away the "return plane_ride_cost(city), and putting it below the rest of the function, but when I do that it says that tampa returns 183 instead of it's proper value of 220. – Nertfertsatwork Jul 25 '16 at 20:57

2 Answers2

0

This should work:

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_car_cost = 40 * days
    if days >= 7:
        rental_car_cost -= 50
    elif days >= 3:
        rental_car_cost -= 20
    return rental_car_cost
Shubham
  • 2,847
  • 4
  • 24
  • 37
  • I didn't see this at first and got pissy from what I thought was the lack of an answer. Thanks very much – Nertfertsatwork Jul 26 '16 at 03:31
  • I get this error now "trip_cost('Los Angeles', 8) raised an error: unsupported operand type(s) for -=: 'str' and 'int'" and everything is the exact same as you put it in and my code for trip cost looks like this- def trip_cost(days, city): return hotel_cost(days) + rental_car_cost(city) + plane_ride_cost(city) return trip_cost and I've tried it as return trip_cost and return trip_cost(days, nights) – Nertfertsatwork Jul 26 '16 at 03:45
0
    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
        else: 
            return 475
    def rental_car_cost(days):
        if days >= 7:
            return (40 * days) - 50
        elif days >= 3:
            return (40 * days) - 20
        elif days < 3:
            return (40 * days)
        else:
            return 0       
    def trip_cost(city, days):
        return (hotel_cost(days) + plane_ride_cost(city) +         rental_car_cost(days))
        return trip_cost

this answer worked.