我目前正试图解决一个有关比萨饼店的编码问题。它意味着接受多个参数(从1到多个参数),并将每个参数的固定成本相加以返回一定的成本。我的问题是,当前的代码有什么问题,它不能循环遍历数据。我制作了一个函数、一个字典和一个for循环来遍历数据。所有这些都是用python编写的。
def cost_calculator(*x, wings, drinks, coupon):
total_cost = 0 #variable that holds final cost of order
print(total_cost)
pizza_to_price = {"mypizza":13}
drinks_to_price = {"small": 2.00, "medium": 3.00,"large": 3.50,"tub": 3.75}
wings_to_price = {10:5.00, 20:9.00, 40:17.50, 100:48.00}
toppings_to_price = {"pepperoni":1.00, "mushroom":0.50, "olive":0.50, "anchovy":2.00,"ham":1.50}
for pizza in x:
total_cost += 13.00
for topping in wings:
total_cost += wings_to_price[topping]
for size in drinks:
total_cost += drinks_to_price[size]
for discount in coupon:
total_cost = total_cost - (total_cost * coupon)
total_cost *= 1.0625
round(total_cost,2)
return total_cost
回复:我得到的错误是,如果我取消注解所有内容,就会返回一个nonetype值。
2条答案
按热度按时间guicsvcw1#
我不知道这是不是打字错误,但你忘了缩进:
结果:
14.34375
python函数:https://www.w3schools.com/python/python_functions.asppythonMap:https://www.geeksforgeeks.org/python-map-function/
wvt8vs2t2#
我不知道您是否需要,但我对@silverfox代码做了一些编辑: