python中Pizza Shop函数的问题

python中Pizza Shop函数的问题,python,Python,我的比萨饼店代码有问题 下面是平地机将通过函数传递的示例输入之一 >>>cost_calculator([], ["ham", "anchovy"], drinks=["tub", "tub"], coupon=0.1) 35.61 []代表比萨饼,第二个[“火腿”、“凤尾鱼”]是有配料的比萨饼 让我困惑的一个主要问题是我如何将[]表示为比萨饼,价格为13美元。我有一个字典占位符,但这不起作用,因为[]是不可散列的。我面临的另一个问题是,我将如何处理列表中不知何故包含的浇头。

我的比萨饼店代码有问题

下面是平地机将通过函数传递的示例输入之一

>>>cost_calculator([], ["ham", "anchovy"], drinks=["tub", "tub"], coupon=0.1)
35.61
[]代表比萨饼,第二个[“火腿”、“凤尾鱼”]是有配料的比萨饼

让我困惑的一个主要问题是我如何将[]表示为比萨饼,价格为13美元。我有一个字典占位符,但这不起作用,因为[]是不可散列的。我面临的另一个问题是,我将如何处理列表中不知何故包含的浇头。我的函数签名也是不正确的,我在过去多次遇到过这个问题,如果有人能给我指出一个资源的方向来解释它们,我将非常感激。不过,我对词典的用法相当有信心

def cost_calculator(x,wings,drinks,coupon): 
    total_cost = 0
    x = {[]:13}
    Price_of_drinks = {"small": 2.00, "medum":3.00,"large":3.50,"tub":3.75}
    Price_of_wings = {10:5.00,20:9.00,40:17.50,100:48.00}
    Price_of_toppings = {"pepperoni":1.00,"mushroom":0.50,"olive":0.50,"anchovy":2.00,"ham":1.50}
    if x in iter
        total_cost += x[[]]
        if "pepperoni" in x
            total_cost += 1.00
        if "mushroom" in x
            total_cost += 0.50
        if "olive" in x
            total_cost += 0.50
        if "anchovy" in x
            total_cost += 2.00
        if "ham" in x
            total_cost += 1.50
    if wings in iter
        total_cost += Price_of_wings['wings']
    if drinks in iter:
        total_cost += Price_of_drinks['drinks']
    if wings in iter:
        total_cost += Price_of_wings['wings']
    if coupon in iter
        total_cost= total_cost - (total_cost*coupon)
    total_cost *= 1.0625
    round(total_cost,2)
    return total_cost
我只是在寻找一个指向正确方向的指针,如果你觉得我的问题不对劲,一定要编辑。我知道我的知识非常基础,所以指针意义重大

def cost_calculator(x, wings, drinks, coupon): 
    total_cost = 0

    Price_of_drinks = {"small": 2.00, "medum":3.00,"large":3.50,"tub":3.75}
    Price_of_wings = {10:5.00,20:9.00,40:17.50,100:48.00}
    Price_of_toppings = {"pepperoni":1.00,"mushroom":0.50,"olive":0.50,"anchovy":2.00,"ham":1.50}
    Price_of_pizza = {"mypizza":13}
迭代列表
x
,我将
x
中的每个元素称为
pizza

    for pizza in x:

        total_cost += Price_of_pizza[pizza] #Single pizza alone

    print("Cost after adding single pizza with no topping: ", total_cost) #13

    total_cost += Price_of_pizza[pizza] #Going to add pizza price and then toppings in the next loop you see

    print("Cost after adding another single pizza with topping whose price is going to be added later ", total_cost) #13 + 13

    for topping in wings:

        total_cost += Price_of_toppings[topping]

    print("Cost after adding single pizza with no topping + single pizza with two toppings requested ", total_cost) #13 + 13 + 1 + 2

    for drinksize in drinks:

        total_cost += Price_of_drinks[drinksize]

    print("Cost after adding drinks ", total_cost) #13 + 13 + 1 + 2 + 3.75 + 3.75 = 37.0

    total_cost = total_cost - total_cost*coupon #37.0 - 37.0*0.1 = 33.3

    print("Cost after discount ", total_cost)




    round(total_cost,2)
    return total_cost


cost_calculator(['mypizza'], ["ham", "anchovy"], drinks=["tub", "tub"], coupon=0.1)

你能解释一下为什么你的价格是35.61美元吗?因为我认为这是一个比萨饼(13美元)加火腿(1.5美元)+凤尾鱼(2.0美元)+两桶(3.75 X 2),不等于35美元。61@Abhishek这是一个例子,它有1。比萨饼2.比萨饼,但要配火腿和凤尾鱼3。2杯饮料,两杯4。一张10%的优惠券我已经把它放进了价格里,我想我知道了优惠券是怎么运作的,但是其他的都搞糊涂了,尤其是比萨饼,我怎么能为一张空的名单定价呢?所以它是13+1.5+2+(3.75 X 2)是的?你的空[]能有超过一个比萨饼吗?它是13+(1.5+2+13)(3.75*2),有10%的优惠券