Python:便利店订单账单小票信息生成

Hello,基于Python生成便利店订单账单小票信息;

import datetime
import random
import string


def generate_order_id():
    current_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
    random_str = ''.join(random.choices(string.ascii_uppercase + string.digits, k=4))
    order_id = f"4575{current_time}_{random_str}"
    return order_id


def print_bill(store_name, order_id, products):
    print(f"便利店名:{store_name}")
    print(f"订单号为:{order_id}")
    print("-" * 40)

    total_quantity = 0
    grand_total = 0

    for product_name, unit_price, quantity in products:
        total_price = unit_price * quantity
        total_quantity += quantity
        grand_total += total_price
        print(f"{product_name:<20}{unit_price:>10.2f}{quantity:>10}{total_price:>10.2f}")

    print("-" * 40)
    print(f"商品件数:{total_quantity}")
    print("-" * 40)
    print(f"合计:{grand_total:.2f}")
    print(f"微信支付:{grand_total:.2f}")
    print(f"找零:0.00")


# 商品列表
products = [
    ("红枣桂圆豆浆", 5, 2),
    ("浓乳冰面包", 8.9, 2),
    ("冰皮月亮巧克力", 9.9, 2),
    ("爆浆泡芙", 7.9, 3),
    ("巴斯克芝士蛋糕", 8.9, 1)
]

# 生成并打印账单信息
store_name = "FUGOU(大悦广场店)"
order_id = generate_order_id()
print_bill(store_name, order_id, products)

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值