如何纠正函数的输出?

时间:2017-08-08 19:16:16

标签: python function if-statement

我正在编写一个能够返回旅行总费用的函数,但每当我放置" Charlotte"以及任何数字作为trip_cost函数的参数。例如,当我输入trip_cost(' Charlotte',6)时,检查正确答案的软件会一直告诉我该函数产生1240而不是1243.

任何人都可以提供有关如何更正以下代码的提示吗?

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

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):
    cost = 40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3 and days < 7:
        cost -= 20
    return cost

def trip_cost(city, days):
    total = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) 
    return total

0 个答案:

没有答案