username_list = []
prize_dict = {
'0': "芭比娃娃",
'1': "变形金刚",
'2': "psp游戏机",
'3': "奥特曼",
'4': "遥控飞机",
'5': "chongqiwawa",
} shopping_car_dict = {} def inp_username_pwd():
username_inp = input('请输入你的用户名:')
pwd_inp = input('请输入你的密码:') return username_inp, pwd_inp def login():
print('欢迎来到登录功能')
if username_list:
print('已经登录,请勿重复登录')
return count = 0
while count < 3:
username_inp, pwd_inp = inp_username_pwd() with open('user_info.txt', 'r', encoding='utf8') as fr:
for user_info in fr:
user_info = user_info.strip()
username, pwd = user_info.split(':') if username == username_inp and pwd == pwd_inp:
print('登录成功')
username_list.append(username_inp)
return else:
print('账号密码错误') count += 1 def register():
print('欢迎来到注册功能') username_inp, pwd_inp = inp_username_pwd() with open('user_info.txt', 'a', encoding='utf8') as fa:
fa.write(f'{username_inp}:{pwd_inp}\n') def logout():
print('欢迎来到注销功能') if not username_list:
print('请登录后使用该功能')
return username_list.clear() def shopping():
print('欢迎来到Nick集团消费功能') if not username_list:
print('请登录后使用该功能')
return print('''
0 芭比娃娃
1 变形金刚
2 psp游戏机
3 奥特曼
4 遥控飞机
5 chongqiwawa
''') prize_choice = input('请输入你需要购买的商品编号:')
prize_name = prize_dict[prize_choice] if prize_name in shopping_car_dict:
shopping_car_dict[prize_name] += 1
else:
shopping_car_dict[prize_name] = 1 print(f'消费成功{prize_name},当前购物车情况为{shopping_car_dict}') def shopping_car():
print('恭喜剁手成功功能') if not username_list:
print('请登录后使用该功能')
return print(f'恭喜你购物成功:{shopping_car_dict}') shopping_car_dict.clear() func_dict = {
'1': login,
'2': register,
'3': logout,
'4': shopping,
'5': shopping_car,
} while True:
print('''
1 登录
2 注册
3 注销
4 购物
5 购物车
q 退出
''')
func_choice = input('请选择你要选择的功能(输入q退出):')
if func_choice == 'q':
break if func_choice not in func_dict:
print('傻逼,英文看不懂正常,还看不懂阿拉伯数字')
continue func_dict[func_choice]()

最新文章

  1. linux下用Apache一个IP多个域名建虚拟主机
  2. java课后作业5
  3. iOS学习04C语言数组
  4. 解决 Eclipse 项目有红感叹号的方法
  5. 编写高质量代码改善C#程序的157个建议[匿名类型、Lambda、延迟求值和主动求值]
  6. 泛型之Dictionary
  7. Scrum Meeting---Ten(2015-11-5)
  8. ExtJs之文本框及数字输入
  9. Linux 文件/文件夹操作命令
  10. Xcode 7.3.1的模拟器路径
  11. Python全栈开发之MySQL(二)------navicate和python操作MySQL
  12. [AngularJS + Webpack] Production Setup
  13. SQL FOR XML PATH 用法
  14. HDU 3046Pleasant sheep and big big wolf(切最小网络流)
  15. css画三角形,梯形
  16. Codeforces 754A Lesha and array splitting(简单贪心)
  17. C语言程序设计第二次作业1
  18. [Swift]LeetCode264.丑数 II | Ugly Number II
  19. string赋值和操作
  20. Eclipse+Maven整合开发Java项目(二)➣webapp3.0以上的Maven项目

热门文章

  1. TCP/IP网络协议初识
  2. MongoDB学习笔记(六、MongoDB复制集与分片)
  3. 关于定义序列化器时,read_only和write_only有什么作用
  4. 搞定vscode编写java(手把手篇)
  5. 软件测试价值提升之路- 第二章&quot;价值实现的起点&quot;读书笔记
  6. sql server多表关联update
  7. 多线程八 Lock
  8. (转)深入解析TensorFlow中滑动平均模型与代码实现
  9. PHP中发送qq邮件
  10. Java - 变量常量数据类型