用Python编写一个简单的超市收银系统,功能包括收银员登录、商品编号输入、数量输入、总价计算、打折(例如第2件9折、每月的8号、18号、28号商品8.5折)的流程图
时间: 2023-07-04 13:14:54 浏览: 87
很抱歉,我是一名语言模型,无法呈现流程图。不过我可以给你提供一个Python代码框架供你参考:
```
# 超市收银系统
# 商品清单
goods = {'1001': {'name': '可乐', 'price': 3.0},
'1002': {'name': '矿泉水', 'price': 2.0},
'1003': {'name': '薯片', 'price': 5.0},
'1004': {'name': '巧克力', 'price': 10.0},
'1005': {'name': '饼干', 'price': 4.0}}
# 打折信息
discount_info = {'second': 0.9, 'day': [8, 18, 28], 'month': 0.85}
# 收银员信息
cashiers = {'001': '123456', '002': '654321'}
# 登录
def login():
while True:
cashier_id = input('请输入收银员编号:')
password = input('请输入密码:')
if cashier_id in cashiers and password == cashiers[cashier_id]:
print('登录成功!')
return cashier_id
else:
print('登录失败,请重新输入!')
# 商品编号输入
def input_goods():
while True:
goods_id = input('请输入商品编号:')
if goods_id in goods:
return goods_id
else:
print('商品编号不存在,请重新输入!')
# 数量输入
def input_quantity():
while True:
quantity = input('请输入数量:')
if quantity.isdigit():
return int(quantity)
else:
print('请输入数字!')
# 根据打折信息计算折扣
def calculate_discount(total_price, goods_count, discount_info):
# 第2件9折
if goods_count >= 2:
total_price *= discount_info['second']
# 每月的8号、18号、28号商品8.5折
import datetime
today = datetime.date.today()
if today.day in discount_info['day']:
total_price *= discount_info['month']
return total_price
# 收银
def checkout():
goods_list = []
while True:
goods_id = input_goods()
quantity = input_quantity()
goods_price = goods[goods_id]['price']
goods_total_price = goods_price * quantity
goods_list.append({'id': goods_id, 'name': goods[goods_id]['name'], 'price': goods_price, 'quantity': quantity, 'total_price': goods_total_price})
is_continue = input('是否继续扫描(Y/N)?')
if is_continue.lower() == 'n':
break
# 计算总价
total_price = sum([goods['total_price'] for goods in goods_list])
print('总价:', total_price)
# 计算折扣
goods_count = sum([goods['quantity'] for goods in goods_list])
discount_price = calculate_discount(total_price, goods_count, discount_info)
print('折扣后总价:', discount_price)
# 主程序
cashier_id = login()
checkout()
```
这个代码框架可以实现收银系统的主要功能,你可以根据你的具体情况进行修改和完善。