单价计价宝: 商家套路多,在办卡案例中,
假设优惠如下:
1、总价为178.9,年包价格
2、总价为88.0,月包价格
3、总价为95.0,120天价格
试问哪个更便宜,这时候就要计算单价进行比较了
通过本程序,可以得到详情报表:
序号 总价 数量 单价
[1] 178.9 360*1 0.49694444444444447
[2] 88.0 30*1 2.933333333333333
[3] 95.0 30*4*1 0.7916666666666666
可以直观地看出,年包的价格是最优惠的。
"""
单价计价宝: 商家套路多,在办卡案例中,
假设优惠如下:
1、总价为178.9,年包价格
2、总价为88.0,月包价格
3、总价为95.0,120天价格
试问哪个更便宜,这时候就要计算单价进行比较了
通过本程序,可以得到详情报表:
序号 总价 数量 单价
[1] 178.9 360*1 0.49694444444444447
[2] 88.0 30*1 2.933333333333333
[3] 95.0 30*4*1 0.7916666666666666
可以直观地看出,年包的价格是最优惠的。
@author: yaunsine
@date: 2023-03-03
"""
ls_price = list()
while True:
print('1、加入\n2、舍弃\n3、展示所有\n4、exit')
cmd = int(input('输入指令: '))
if cmd == 1:
dict_price = dict()
sum_price = float(input('总价: '))
cnt = int(input('数量(输入1或0结束): '))
ls_cnt = [cnt]
n = cnt
while cnt > 1:
cnt = int(input('数量(输入1或0结束): '))
n = n * cnt
ls_cnt.append(cnt)
dict_price['总价'] = sum_price
ls_cnt = list(map(str, ls_cnt))
dict_price['数量'] = "*".join(ls_cnt)
dict_price['单价'] = sum_price / n
ls_price.append(dict_price)
elif cmd == 2:
idx = int(input('请输入序号: '))
ls_price.pop(idx+1)
elif cmd == 3:
if len(ls_price) <= 0:
print('*空*')
continue
print("序号\t" + "\t".join(ls_price[0].keys()))
for i, v in enumerate(ls_price):
print_line = '[{0}]\t\t'.format(i+1)
for k in v.keys():
print_line += str(v[k]) + '\t'
print(print_line)
elif cmd == 4:
break