codecademy python exercise 5.汇总如何计算出行成本()

2024-04-26 18:14:16 发布

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

我不知道如何对最后一个函数中的参数求和:trip\u cost() 我得到的不是我键入的内容,而是一个错误:

“哦,再试一次。trip\u 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)

Tags: 名称cityreturndef错误dayshotelcost
1条回答
网友
1楼 · 发布于 2024-04-26 18:14:16

您将函数命名错误。你知道吗

在你的旅行费用()回报中,你称之为普通的骑行费用(“失落的洛杉矶”)。你知道吗

但是应该是飞机费用()

将最后一个方法更改为此方法。你知道吗

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

相关问题 更多 >