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