我需要找到订单的折扣我使用以下代码将订单号的字符串输入到字典中,然后使用 sum() 来查找订单的总数但是如果有一个,我希望有一个优惠折扣- 1 and one-3 and (one-4 or one-5 or one-6) 但是在条件块之后,当我想将它相乘时,我收到一个未绑定错误
def compute_cost(order):
"""
Function 2: compute_cost(order)
Parameters: order (String)
Return: Final cost of order
"""
numcount = {}
orderlist = map(int, order)
for i in orderlist:
if numcount.get(i):
numcount[i] += 1
else:
numcount[i] = 1
for i in numcount:
if i == 1:
numcount[i] = numcount[i]*4.25
elif i == 2:
numcount[i] = numcount[i]*2.50
elif i == 3:
numcount[i] = numcount[i]*2.00
elif i == 4:
numcount[i] = numcount[i]*1.25
elif i == 5:
numcount[i] = numcount[i]*1.50
elif i == 6:
numcount[i] = numcount[i]*1.75
elif i == 7:
numcount[i] = numcount[i]*3.75
else:
return print("Your order has a number outside of the range (1:7)")
order_total = sum(numcount.values())
if(numcount[1] == 1 and
numcount[3] == 1 and
(numcount[4] == 1 or
numcount[5] == 1 or
numcount[6] == 1)):
discount1 = 0.20
order_total1 = order_total*discount1
return order_total1
请帮助我谢谢您的时间和精力
编辑 如果您有更好的方法让我找到值并将它们保存在字典中,我也愿意接受建设性的批评