This code below is not working, However, I have checked it in parts by pars of each cost


#1



trip_cost('Charlotte', 6) raised an error: maximum recursion depth exceeded in cmp


It should deliver the output result.


def plane_ride_cost(city):
    if city== 'Charlotte' :
        return 183
    if city== 'Tampa' :
        return 220
    if city== 'Pittsburgh' :
        return 222
    if city == 'Los Angeles':
        return 475
    plane_ride_cost('city')
    # Cost of lflying to a city. This code is verified in Jupyter! It works.
    
def hotel_cost(nights):
    return 140*nights
    
    # Cost of staying in a hotel. This code is verified in Jupyter! It works.
    
    
def rental_car_cost(days):
    if days<3:
        cost = 40*days
    if days>=7:
        cost = 40*days - 50
    elif days>=3:
        cost = 40*days - 20
    return cost

def trip_cost(city, days):
    return rental_car_cost(days) +  plane_ride_cost('city') + 140*days


#2

A function that always calls itself is an infinite loop - however, due to how Python is implemented, you can only keep track of so many calls on the stack, so after many thousand calls it crashes.


#3

Firstly,c wishing you Happy New Year!

could you suggest some modificationa?
I still did not understand how it calls itself!
Best Regards,
Mihir NAKHARE


#4

I think the issue is line 10 (if I counted right). Calling "plane_ride_cost('city')" is part of it's own function's definition (hence previous reply about the infinite loop). Hope that makes sense (and that I'm right, lol)
Happy New Year!


#5

Thank you very much! Now it works!


#6

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