获取python程序中参数顺序混乱的错误

2024-10-06 19:16:07 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行以下代码时,得到如下错误:

 trip_cost should take exactly three parameters: city, days, and spending_money (in that order).

下面的代码具有与前面所述相同的参数顺序。但仍然得到同样的错误,即使它返回1995年的旅行费用

def plane_ride_cost(city):
    if city == "Charlotte":
       return 183
    elif city == "Tampa":
        return 220

    elif city == "Pittsburgh":
        return 222
    elif city == "LosAngeles":
        return 475

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

def hotel_cost(nights):
    return 140 * nights

def money(spending_money):
    return spending_money

def trip_cost(city,days,spending_money):

    total_trip_cost = plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days) + money(spending_money)
    return total_trip_cost

print trip_cost("LosAngeles",5,600)

Tags: 代码cityreturnifdef错误dayscost