Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
codecademy python练习5.把它放在一起-如何计算旅行成本()_Python_Python 3.x_Machine Learning - Fatal编程技术网

codecademy python练习5.把它放在一起-如何计算旅行成本()

codecademy python练习5.把它放在一起-如何计算旅行成本(),python,python-3.x,machine-learning,Python,Python 3.x,Machine Learning,我不知道如何对最后一个函数中的参数求和:trip_cost() 我得到的不是我键入的内容,而是一个错误,上面写着: “哦,再试一次。旅行费用('Los Angeles',6)引发错误:未定义全局名称'plain\u ride\u cost'” (每次我指向“Save And Submmit”进行检查时,它都会在括号中给我一个与列表中城市不同的名称,并在错误注释中逗号后给我另一个数字。) 但到目前为止,我已经尝试了一些不同的方法,但它对我不起作用。 谁能帮我度过这一关吗 def hotel_cos

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

“哦,再试一次。旅行费用('Los Angeles',6)引发错误:未定义全局名称'plain\u ride\u cost'”

(每次我指向“Save And 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)
def酒店成本(夜):
返回140*晚
def飞机驾驶费用(城市):
如果城市==“夏洛特”:
返回183
elif city==“坦帕”:
返回220
elif city==“匹兹堡”:
返回222
elif city==“洛杉矶”:
返回475
其他:
打印(“未知成本”)
def租车费用(天):
费用=40*天
如果天数>=3且天数=7:
成本-=50
退货成本
其他:
退货成本
def差旅费用(城市,天数):
返回酒店费用(天)+普通乘车费用(“洛杉矶”)+租车费用(天)

您将函数命名错误

在你的旅行成本()回报中,你称之为普通的旅行成本(“迷失的洛杉矶”)

然而,这应该是飞机费用()

将最后一个方法更改为此

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

您将函数命名错误

在你的旅行成本()回报中,你称之为普通的旅行成本(“迷失的洛杉矶”)

然而,这应该是飞机费用()

将最后一个方法更改为此

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

plain\u-ride\u-cost!=飞机驾驶费用
普通驾驶费用!=飞机驾驶费用