购物小票python语法

购物小票python语法,第1张

购物小票python语法

思路:用python语法 思考脑补购物的小经过和细节 (如会员折购) 总价=单价*数量*(必不可少的公式)(我是菜鸟新人 轻点喷 请多指教)

# 输入部分

discount=0.8 # 8折优惠

price1 = float(input('输入商品1的单价:'))

amount1 = int(input('商品1的购买数量:'))

price2 = float(input('输入商品2的单价:'))

amount2 = int(input('商品2的数量:'))

………………

………………

# 处理部分

money = (price1*amount1+price2*amount2+………………)*discount #计算购物金额

if payment >=money:

     change = payment-money #计算找钱

     points = int(money // 33) # 计算购物积分

# 输出部分

print('*******消费单*******')

print('%-8s%-6s%-6s%-6s'%('购买物品',‘单价’,‘数量’,‘金额’))

print('%-8s%-8.2f%-8d%-8.2f'%('商品1',price1,amount1,price1*amount1))

print('%-8s%-8.2f%-8d%-8.2f'%('商品2',price2,amount2,price2*amount2))

………………

print('*******')

print('折扣:{}折'.format(int(discount*10)))

print('消费总额:¥{}'.format(round(money,2)))

print('实际交费:¥{}'.format(payment))

print('找钱:¥{}'.format(round(change,2)))

print('本次购物所获的积分:{}'.format(points))

else:

       diff = money - payment

       print('温馨提示:钱没给够,还差{}圆。'.format(diff))

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5580871.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存