#定义用户字典,用于验证登录
user = {"root": {"passwd": "123", "money": 1000},"admin": {"passwd": "admin", "money": 1000}}
#定义商品字典
product = {'f001': {"name": "apple", "price": 2.5},
'f002': {"name": "banana", "price": 3.5},
'f003': {"name": "grape", "price": 4.5},
'f004':{"name":"fork","price":18},
'f005':{"name":"sheep","price":25}}
print("-" * 50)
print('#' + "{0:^42}".format("欢迎登录三乐购物系统") + '#')
print("-" * 50)
print("温馨提示,输入quit退出系统")
#展示商品函数
def product_list():
print("商品列表")
for i, j in product.items():
print(f"编号:{i},名称:{j['name']},单价:{j['price']}")
#菜单栏
def menu():
print("菜单栏".center(40, "-"))
print("输入1查看商品列表".center(43))
print("输入2查看购物车 ".center(43))
print("输入3进行购买 ".center(43))
print("输入4结算 ".center(43))
print("输入5退出系统 ".center(43))
print("-" * 43)
#购物车
def cart():
global sum_price
print("购物车".center(40, "*"))
print("已购买的商品:")
python实现控制台购物系统
最新推荐文章于 2023-05-04 09:45:40 发布