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)