codecademy python excercise 5.Pull it Together语言 - how to sum



我不知道如何在最后一个函数中对参数求和:trip_cost()而不是我输入的内容,我得到一个错误说:

"哎呀,再试一次。trip_cost('洛杉矶',6) 引发错误:未定义全局名称'plain_ride_cost'

(每次我指向"保存和Submmit"进行检查时,它都会在括号中给我一个与列表中不同的城市名称,并在错误注释中的逗号后面加上另一个数字。

但是到目前为止我已经尝试了一些不同的方法,但它对我不起作用。谁能帮我完成这个?

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
    else:
        print("unkown costs")
def rental_car_cost(days): 
    cost = 40 * days
    if days >= 3 and days <7: 
        cost -= 20
        return cost
        print cost
    elif days >= 7:
        cost -= 50
        return cost
    else:
        return cost
def trip_cost(city, days):
    return hotel_cost(days) + plain_ride_cost("Los Angeles") + rental_car_cost(days)

你给函数命名错误。

你在trip_cost()申报表中称它为plain_ride_cost("失落的天使")。

但是它应该是plane_ride_cost()

将最后一种方法更改为此方法。

def trip_cost(city, days):
return hotel_cost(days) + plane_ride_cost("Los Angeles") + rental_car_cost(days)

最新更新