python第三天作业

设计一个程序,完成(英雄)商品的购买(界面就是第一天打印的界面)
展示商品信息(折扣)->输入商品价格->输入购买数量->提示付款
输入付款金额->打印购买小票(扩展)

# 定义商品信息和折扣
goods = {'英雄笔记本': 5999, '英雄鼠标': 399, '英雄键盘': 899}
discount = {'满1000减100': 1000, '满2000减300': 2000, '满5000减1000': 5000}

# 展示商品信息和折扣
print('欢迎来到英雄商城!')
print('我们的商品有:')
for name, price in goods.items():
    print(name, price)
print('我们的折扣有:')
for name, amount in discount.items():
    print(name, amount)

# 输入商品价格和购买数量
name = input('请输入要购买的商品名称:')
price = goods.get(name)
if price is None:
    print('没有这个商品!')
else:
    quantity = int(input('请输入要购买的数量:'))

    # 计算总价和折扣后的价格
    total_price = price * quantity
    discount_price = total_price
    for name, amount in discount.items():
        if total_price >= amount:
            discount_price -= amount
    print('总价为:', total_price)
    print('折扣后的价格为:', discount_price)

    # 输入付款金额并判断是否足够
    while True:
        payment = int(input('请输入付款金额:'))
        if payment < discount_price:
            print('付款金额不足,请重新输入!')
        else:
            break

    # 打印购买小票
    change = payment - discount_price
    print('购买成功!')
    print('找零为:', change)
    print('购买小票:')
    print('商品名称:', name)
    print('商品单价:', price)
    print('购买数量:', quantity)
    print('总价:', total_price)
    print('折扣后的价格:', discount_price)
    print('付款金额:', payment)
    print('找零:', change)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值