|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #设置满减活动,打折活动的选项
- while 1:
- while True:
- commodity = int(input("请输入商品货号:"))
- price = float(input("请输入商品单价:"))
- if(price < 0):
- print("输入不合法!")
- amount = int(input("请输入商品数量:"))
- total_price = price * amount
- print("原价:",total_price)
- print("1.一件8.8折,俩件7.8折")
- print("2.满500减100,满800减200,满1000减300")
- sale = int(input("请输入折扣活动:"))
- i = 0
-
- #结算收银
-
- #打折活动
- if sale == 1:
- if amount >= 1:
- total_price1 = total_price * 0.88
- if amount >= 2:
- total_price1 = total_price * 0.78
- print("折后价:",total_price1)
- #满减活动
- if sale == 2:
- if (total_price >= 500) :
- i += 100
- total_price1 = total_price - i
-
- if (total_price >= 800) :
- i += 100
- total_price1 = total_price - i
- if (total_price >= 1000) :
- i += 100
- total_price1 = total_price - i
- print("折后价:",total_price1)
-
-
-
- else :
- total_price1 = total_price
- print(total_price1)
- payment = int(input("请输入付款金额:"))
- margin = payment - total_price1
- if (margin >= 0):
- print("找零:",str(margin))
- else:
- print("余额不足!")
- mylog = open('recode.log', mode = 'a',encoding='utf-8')
- for i in range(1):
- print(total_price, file=mylog)
- mylog.close()
- break
复制代码
半夜睡不着,代码全部帮你敲好了,大改了一下
- while True:
- while True:
- commodity = input("请输入商品货号(输入Esc退出程序):")
- if commodity == 'Esc':
- break
- price = input("请输入商品单价:")
- if not price.isdigit() or not commodity.isdigit() or float(price) <= 0 : # 判断输入是否为数字 和 是否大于零
- print("输入不合法!请重新输入!")
- continue
- break
- if commodity == 'Esc':
- break
- while True:
- amount = input("请输入商品数量:")
- if not amount.isdigit() and int(amount) < 0: # 判断输入是否为数字 和 是否大于零
- print("输入不合法!请重新输入!")
- else:
- amount = int(amount)
- total_price = float(price) * amount
- temp = str(int(total_price))
- break
- print("总价:%.2f"%total_price)
- print("现在本店有两种活动,输入1,2进行选择~")
- print("1.十件8.8折,十五件7.8折")
- print("2.满500减100,满800减200,满1000减300")
- while True:
- sale = input("请输入折扣活动:")
- if sale != '2' and sale != '1':
- print("输入不合法!请重新输入1 或 2 !")
- continue
- break
- # 打折活动
- if sale == '1':
- if amount >= 15:
- total_price = total_price * 0.78
- elif amount >= 10:
- total_price = total_price * 0.88
- print("活动1折后价:%.2f"%total_price)
- # 满减活动
- elif sale == '2':
- if total_price >= 1000:
- total_price -= 300
- elif total_price >= 800:
- total_price -= 200
- elif total_price >= 500:
- total_price -= 100
- print(total_price)
- print("活动2折后价:%.2f"%total_price)
- elif int(total_price) == int(temp):
- print('不满足活动条件,未参与活动!')
- sale = 0
- while True:
- try:
- payment = int(input("请输入付款金额:"))
- break
- except ValueError:
- print('输入不合法!请重新输入!')
- margin = payment - total_price
- if margin >= 0:
- print("找零:", margin)
- else:
- print(f"还差{-margin}元,已记账")
- goods = '|商品货号:{:^3} |商品单价:{:^3} |商品数量:{:^3} |原价:{:^5} |参与活动:{:^2} |活动后价格:{:^5} |实付款:{:^5} |找零或欠账:{:^5}\n'\
- .format(commodity,price,amount,temp,sale,total_price,payment,margin)
- with open('Goods.txt','a',encoding='utf-8') as f:
- f.write(goods)
复制代码
如果帮助到你了 给个最佳吧~ 
|
|