程序输入类似13163351415|1801|200|785|300内容,需计算出客户该月费用。
该段内容表示为:手机号|语音时间(秒)|语音基础费率(每分钟)|流量(MB)|流量费率(每KB)
L = "13163351415|1801|200|785|30".split("|") def yuyin(a, b): # 将语音时间换算为分钟,向上取整 if a % 60 == 0: time = a // 60 else: time = a // 60 + 1 # 定于语音收费区间及其费率 qujian = [20, 10, 5, 1, 0] feilv = [0.2, 0.5, 1.5, 1, 0] sum = 0 # 通过从后往前切割,将语音时间按语音收费区间切割,落在对应区间的费率,并进行计算 for i in range(len(qujian)): if time > qujian[i]: sum += (time - qujian[i]) * feilv[i] * b / 10 time -= time - qujian[i] return int(sum) def liuliang(a, b): qujian = [625, 325, 125, 0] LL = [500, 200, 100, 0] sum = 0 if a < 625: for i in range(len(qujian)): if a > qujian[i]: sum += ((a - qujian[i]) + LL[i]) break else: shengyuliuliang = a - qujian[0] if shengyuliuliang % 100 == 0: sum = 500 + (shengyuliuliang // 100) / 2 * 100 + shengyuliuliang % 100 else: sum = 500 + ((shengyuliuliang // 100) / 2 + 1) * 100 # 流量费用=流量(MB)*1024KB / 10KB(以每10KB收费)* 每10KB费用(厘)/ 10 liuliangfeiyong = sum * 1024 / 10 * b / 10 return int(liuliangfeiyong) yuyinfeiyong = yuyin(int(L[1]), int(L[2])) liuliangfeiyong = liuliang(int(L[3]),int(L[4])) print(yuyinfeiyong + liuliangfeiyong)