2016-12-31 149 views
-3
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 flying 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 # Discount 
    elif days>=3: 
     cost = 40*days - 20 # Discount 
    return cost 

# cost of renting a car. 

def trip_cost(city, days, spending_money): 
    return rental_car_cost(days) + plane_ride_cost('city') + hotel_cost(days) 
#total cost 

它显示以下错误。运行代码时发现错误

trip_cost('Tampa', 0, 0) raised an error: maximum recursion depth exceeded in cmp 

现在我已经在Jupyter中单独运行每个代码,它运行良好。但不是一个代码。

回答

3

你调用它自己内部此功能:

def plane_ride_cost(city): 
    if city== 'Charlotte' : 
    .... 
    plane_ride_cost('city') 

这是一个无限循环。幸运的是,python解释器在此之前停止并引发递归异常。

解决您可能需要删除该行(什么是应该做反正?'city'没有有效city