如何摆脱附加到另一个列表中的额外值 [英] How do I get rid of the extra value that is being appended into another list

查看:59
本文介绍了如何摆脱附加到另一个列表中的额外值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户希望他们的订单成为交货时,我似乎无法弄清楚为什么order_cost()函数中有额外的三个。当我调用此函数时,额外的三个会影响订单的总成本,并显示为$ 23.00而不是$ 20.00,这是此订单的正确成本。请有人帮我找到这个问题的根源,谢谢。

I cannot seem to figure out why there is an extra three in the order_cost() function when the user wants their order to be a delivery. When I call this function the extra three affects the total cost of the order and displays it to be $23.00 instead of $20.00 which is the correct cost for this order. Can someone help me find the root of this problem please, thanks.

DELIVERY_CHARGE = ['Delivery', 3.00]
customer_order_list = [["Meat lovers", 8.50],["Hawaiian", 8.50]]

delivery = input("Would like your order to be a delivery?, Please enter yes or no ")

def order_cost():
  if delivery == "yes":
    customer_order_list.append(DELIVERY_CHARGE)
    customer_order_cost = [price[1] for price in customer_order_list]
    print(customer_order_cost)
    total_cost = sum(customer_order_cost)
  else:
    customer_order_cost = [price[1] for price in customer_order_list]
    print(customer_order_cost)
    total_cost = sum(customer_order_cost) 
  return total_cost

order_cost()





我尝试过:



由于我无法弄清楚是什么导致了这个问题我决定从订单的总成本中扣除3,如果客户想要一个交货单以确保额外的三个没有不会影响订单的实际真实总成本,因此它是准确的te,导致总成本为$ 20.00而不是$ 23.00



What I have tried:

Since I couldn't figure out what was causing this problem I just decided to deduct 3 form the total cost of the order if the customer wanted a delivery order to make sure the extra three doesn't affect the actual true total cost of the order and so that it's accurate, resulting in the total cost to be $20.00 instead of $23.00

DELIVERY_CHARGE = ['Delivery', 3.00]
customer_order_list = [["Meat lovers", 8.50],["Hawaiian", 8.50]]

delivery = input("Would like your order to be a delivery?, Please enter yes or no ")

def order_cost():
  if delivery == "yes":
    customer_order_list.append(DELIVERY_CHARGE)
    customer_order_cost = [price[1] for price in customer_order_list]
    print(customer_order_cost)
    total_cost = sum(customer_order_cost) - 3
  else:
    customer_order_cost = [price[1] for price in customer_order_list]
    print(customer_order_cost)
    total_cost = sum(customer_order_cost) 
  return total_cost

order_cost()

推荐答案

23.00而不是


20.00这是此订单的正确成本。请有人帮我找到这个问题的根源,谢谢。

20.00 which is the correct cost for this order. Can someone help me find the root of this problem please, thanks.
DELIVERY_CHARGE = ['Delivery', 3.00]
customer_order_list = [["Meat lovers", 8.50],["Hawaiian", 8.50]]

delivery = input("Would like your order to be a delivery?, Please enter yes or no ")

def order_cost():
  if delivery == "yes":
    customer_order_list.append(DELIVERY_CHARGE)
    customer_order_cost = [price[1] for price in customer_order_list]
    print(customer_order_cost)
    total_cost = sum(customer_order_cost)
  else:
    customer_order_cost = [price[1] for price in customer_order_list]
    print(customer_order_cost)
    total_cost = sum(customer_order_cost) 
  return total_cost

order_cost()





我尝试过:



由于我无法弄清楚是什么导致了这个问题我决定从订单的总成本中扣除3,如果客户想要一个交货单以确保额外的三个没有不会影响订单的实际真实总成本,因此它是准确的te,导致总成本为



What I have tried:

Since I couldn't figure out what was causing this problem I just decided to deduct 3 form the total cost of the order if the customer wanted a delivery order to make sure the extra three doesn't affect the actual true total cost of the order and so that it's accurate, resulting in the total cost to be


20.00而不是


这篇关于如何摆脱附加到另一个列表中的额外值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆