codecademy python excercise 5.Pull it Together - 如何将trip_cost()相加

时间:2017-01-27 11:22:12

标签: python python-3.x machine-learning

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

"哎呀,再试一次。 trip_cost(' Los Angeles',6)引发了一个错误:全局名称' plain_ride_cost'没有定义"

(每当我指向"保存和提交"要检查时,它会在括号中为我提供列表中不同的名称城市以及错误备注中逗号后的另一个数字。)

但到目前为止我尝试了一些不同的方法,但对我来说并不适用。 任何人都可以帮我解决这个问题吗?:

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)

1 个答案:

答案 0 :(得分:0)

您已将您的功能命名为错误。

你在trip_cost()返回时称它为plain_ride_cost(“Lost Angeles”)。

但它应该是plane_ride_cost()

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

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="menu">
  <li><a href="#home" onclick="toggle(" newBill ")"> New Bill</a>
  </li>
</ul>
<form name="billnew" id="newBill">
  Order ID :
  <br>
  <input class="textBox" type="text" name="billid" id="order_id" />
  <!--More form fields below.-->
</form>