编写程序 - 打印购物小票.

"""
功能:打印购物小票
作者:雷云腾
日期:2021年11月4日
"""

# 输入部分
discount = 0.8 # 8折优惠
price1 = float(input("输入运动衫单价:"))
amount1 = int(input('输入运动衫购买数量:'))
price2 = float(input("输入网球鞋单价:"))
amount2 = int(input('输入网球鞋购买数量:'))
price3 = float(input("输入网球拍单价:"))
amount3 = int(input('输入网球拍购买数量:'))
payment = float(input('顾客实际交费:'))

# 处理部分
money = (price1 * amount1 + price2 * amount2 + price3 * amount3) * discount # 计算购物金额
change = payment - money; # 计算找钱
points = int(money // 33); # 计算购物积分

# 输出部分
print('***************消费单**************')
print('%-8s%-6s%-6s%-6s' %('购买物品', '单价', '数量', '金额'))
print('%-8s%-8.2f%-8d%-8.2f' %('运动衫', price1, amount1, price1 * amount1))
print('%-8s%-8.2f%-8d%-8.2f' %('网球鞋', price2, amount2, price2 * amount2))
print('%-8s%-8.2f%-8d%-8.2f' %('网球拍', price3, amount3, price3 * amount3))
print('***********************************')
print('折扣:{}折'.format(int(discount * 10)))
print('消费总金额:¥{}'.format(round(money, 2)))
print('实际交费:¥{}'.format(payment))
print('找钱:¥{}'.format(round(change, 2)))
print('本次购物所获得的积分:{}'.format(points))
————————————————

猜你喜欢

转载自blog.csdn.net/m0_62491934/article/details/121150205