1. 运输距离(distance)
2. 每公里运费(fare)
3. 货物重量(weight)
4. 目的地区域编码(ID)
5. 续重费用(如果有的话)
6. 是否有折扣或特殊费率
def calculate_freight(fare, distance, weight, ID):
初始化运费为0
total_cost = 0
根据距离计算折扣
if distance < 250:
discount = 1.00
elif distance < 500:
discount = 0.98
elif distance < 1000:
discount = 0.95
elif distance < 2000:
discount = 0.92
elif distance < 3000:
discount = 0.90
else:
discount = 0.85
计算基础运费
base_cost = distance * fare
根据区域编码和重量计算续重费用
if ID == '01':
if weight <= 2:
additional_cost = 0
else:
additional_cost = int(13 + (weight - 2) * 3)
elif ID == '02':
if weight <= 2:
additional_cost = 0
else:
additional_cost = int(12 + (weight - 2) * 3)
elif ID == '03':
if weight <= 2:
additional_cost = 0
else:
additional_cost = int(14 + (weight - 2) * 3)
else:
print("地区编号错误")
return
计算总运费
total_cost = base_cost * discount + additional_cost
return total_cost
从用户输入获取运费、距离、重量和区域编码
fare = float(input("请输入每公里运费:"))
distance = float(input("请输入运输的距离:"))
weight = int(input("请输入快递的重量(kg):"))
ID = input("输入地区编号:")
计算并打印总运费
total_freight = calculate_freight(fare, distance, weight, ID)
print(f"总运费为 {total_freight:.2f} 元!")
这个程序会根据用户输入的每公里运费、运输距离、快递重量和地区编号来计算总运费。如果有续重费用或者特殊的折扣政策,也可以在这个基础上进行扩展。
请注意,这个程序是一个简化的示例,实际的运费计算可能会更加复杂,并且需要考虑更多的变量,例如不同的运输方式、货物类型、起始点和目的地的具体位置等。如果有更详细的需求,可以进一步定制这个程序