问题:FoodCorner 家根据订单向客户提供素食和非素食组合。
素食套餐每盘售价 120 卢比,非素食套餐每盘售价 150 卢比。他们的非素食组合非常有名,因为他们的非素食组合比素食组合获得的订单更多。
除了每盘食物的成本外,还根据从餐厅到送货点的距离(以公里为单位)向顾客收取送货上门费用。运费如下:
距离以公里为单位,运费以每公里卢比为单位 前 3 公里为 0 卢比,接下来的 3 公里为 3 卢比,其余为 6 卢比
给定食物类型、数量(盘子数量)以及从餐厅到送货点的距离(以公里为单位),编写一个 Python 程序来计算客户要支付的最终账单金额。
必须使用以下信息来检查客户提供的数据的有效性:
食物类型必须为“V”代表素食,“N”代表非素食。以公里为单位的距离必须大于 0。订购的数量应至少为 1。如果任何输入无效,则应将账单金额视为 -1。
我的解决方案:
def calculate_bill_amount(food_type,quantity_ordered,distance_in_kms):
bill_amount=0.0
if distance_in_kms >= 0.0 and distance_in_kms <= 3.0:
if food_type == "V" and quantity_ordered >= 1:
bill_amount = 120*quantity_ordered
elif food_type =="N" and quantity_ordered >= 1:
bill_amount = 150*quantity_ordered
else:
bill_amount = -1
elif distance_in_kms > 3.0 and distance_in_kms <= 6.0:
if food_type == "V" and quantity_ordered>=1:
bill_amount = 120*quantity_ordered + 3*distance_in_kms
elif food_type == "N" and quantity_ordered>=1:
bill_amount = 150*quantity_ordered + 3*distance_in_kms
else:
bill_amount = -1
elif distance_in_kms > 6.0:
if food_type == "V" and quantity_ordered>=1:
bill_amount = 120*quantity_ordered + 6*distance_in_kms
elif food_type == "N" and quantity_ordered>=1:
bill_amount = 150*quantity_ordered + 6*distance_in_kms
else:
bill_amount = -1
else:
bill_amount = -1
return bill_amount
bill_amount=calculate_bill_amount("N",1,7.0)
print(bill_amount)
慕沐林林
猛跑小猪
德玛西亚99
相关分类