购物系统功能点如下:
0)登录功能:
1. 输入账号密码正确后,可以登录成功(用户登录商城后,可以有欢迎提醒)
2. 输入账号正确,密码错误时,登录失败提示:密码错误
2. 输入的账号不存在时,应提示:用户不存在
1)钱包功能:充值,给当前用户充值
1. 每个用户随机初始化余额, 自行添加一些商品
2)菜单功能:
1. 购买商品,购买商品以后要扣除钱包金额,如果钱包金额不够时,则需提醒用户
3) 退出功能:退出系统时,打印本次购买的商品 及 剩余金额
1 user_info = {} 2 user_info[1] = {"name":"张三","pwd":"159753","surplus":0} 3 user_info[2] = {"name":"李琦","pwd":"852456","surplus":0} 4 user_info[3] = {"name":"王五","pwd":"753852","surplus":0} 5 user_info[5] = {"name":"chj","pwd":"951258","surplus":0} 6 print("==================账号登录============================") 7 user_name = input("请输入用户名:").strip() 8 user_pwd = input("请输入密码:").strip() 9 flag = False 10 userid = "" 11 for key in user_info: 12 # print(key) 13 if user_info[key]['name']== user_name: 14 if user_pwd == user_info[key]['pwd']: 15 print("==================账号登录成功============================") 16 print("登录成功") 17 print("==================商城欢迎提醒============================") 18 print("欢迎%s登录本商城"% (user_name)) 19 print("==================账号充值页面============================") 20 userid = key 21 user_info[userid]['surplus'] = int(input("请输入充值金额:").strip()) 22 print("当前账户余额:", user_info[userid]['surplus'] ) 23 else: 24 print("==================账号登录失败============================") 25 print("用户密码错误") 26 exit() 27 flag = True 28 break 29 if flag == False: 30 print("==================账号不存在============================") 31 print("用户不存在") 32 exit() 33 # print(user_info) 34 fruit_info = {} 35 fruit_info["玩具"] = 100 36 fruit_info["糖果"] = 20 37 fruit_info["洗衣液"] = 50 38 fruit_info["电器"] = 200 39 fruit_info["日用品"] = 30 40 # print(fruit_info) 41 print("商品信息:",fruit_info) 42 fruit = input("请选择需要的商品:").strip() 43 if fruit_info[fruit] <= user_info[userid]['surplus']: 44 print("购买成功") 45 print("==================购买商品明细如下============================") 46 user_info[userid]['surplus']=user_info[userid]['surplus']-fruit_info[fruit] 47 print("您购买的商品是:", fruit) 48 print("当前账户余额为:", user_info[userid]['surplus']) 49 exit() 50 else: 51 print("==================余额不足提醒============================") 52 print("账号钱包金额不足,请及时充值!")