Error: plane_ride_cost('Charlotte') raised an error: maximum recursion depth exceeded in cmp


I have looked through the help for similar posts and still haven't gotten anywhere with getting the correct answer.
This is the exercise I am stuck on

My code seems to work fine except for the plane_ride_cost(city) function which throws up this error message whether I include the final function or not:

"plane_ride_cost('Charlotte') raised an error: maximum recursion depth exceeded in cmp"

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"
    return plane_ride_cost(city)

def rental_car_cost(days):
    day_charge = 40
    total_charge = 40 * days
    if days >= 7:
        total_charge -= 50
    elif 3 <= days < 7:
        total_charge -= 20
    return total_charge
def trip_cost(days, city):
    return rental_car_cost(8) + hotel_cost(8) + plane_ride_cost(city)

Could someone please help point me in the right direction to solve this?




Your code is looking great. There's only a small problem with it, and I'll let you decide what the solution is!

In your plane_ride_cost(city): block, you're comparing strings, i.e. the string variable city, which is passed to your function.

Now, are we trying to compare the string "city", or rather, the string contained in the variable city?

Think about which one you should be comparing in your conditional statements. Also, in this case it is fine to return an int in quotation marks because python sees them as the same thing as long as the whole string is numbers. However, it is good practice to return raw ints instead of strings. (in other words, no need for those quotation marks on the ints you return, just return the number - hint hint :wink:)

Hope this helps your understanding!



Thank you so much for the help, it is all sorted now :slight_smile:


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