注册函数
def zhuce():
'''注册功能'''
count = 0
while count < 3:
name_inp = input('请输入注册名:')
pwd_inp = input('请输入密码:')
pwd_inp2 = input('请确认密码:')
if not pwd_inp == pwd_inp2:
count += 1
print('两次密码输入不一致,请重新输入!')
continue
with open('info.txt', 'a', encoding='utf-8') as fa:
fa.write(F'{name_inp}:{pwd_inp}\n')
print('注册成功!')
break
登录函数
def denglu():
'''登录功能'''
count = 0
while count < 3:
d_name_inp = input('请输入登录名:')
d_pwd_inp = input('请输入密码:')
with open('info.txt', 'r', encoding='utf-8') as fr:
for info in fr:
name, pwd = info.split(':')
if name.strip() == d_name_inp and pwd.strip() == d_pwd_inp:
print('登录成功。')
count = 999
break
else:
print('密码不正确,请重新输入')
count += 1
猜年龄函数
def cai():
'''猜年龄'''
age = 23
count = 0
while count < 3:
i = input('请输入年龄:')
if not i.isdigit():
print('请输入正确的数字')
continue
inp = int(i)
if inp < age:
print('猜小了')
elif inp > age:
print('猜大了')
else:
print('猜对了!')
dic = {1: '切割', 2: '加工', 3: '焊接', 4: '装配'}
print(f'{dic},请选择奖品并输入序号')
choice_count = 0
while choice_count < 2:
inp = input('请选择奖品:')
if not ((inp.isdigit()) and (inp in ['1', '2', '3', '4'])):
print('请输入正确序号并选择奖品')
continue
inp_t = int(inp)
for i in dic:
if i == inp_t:
print('您获得了', dic[i])
break
choice_count += 1
game_end = input('您的奖品选择完毕,请输入‘Y’或‘y’退出游戏:')
if game_end == 'Y' or game_end == 'y':
print('游戏结束')
break
else:
choice_count = 0
print('重新开始游戏请继续\n')
count += 1
else:
print('您的机会用完,游戏结束')
print(
'1:注册',
'2:登录',
'3:猜年龄',
'4:退出'
)
while True:
inp_a = input('请选择项目,并输入相应序号:')
if not ((inp_a.isdigit()) and (inp_a in ['1', '2', '3', '4'])):
print('请输入正确序号')
continue
in_inp = int(inp_a)
if in_inp == 1:
zhuce()
elif in_inp == 2:
denglu()
elif in_inp == 3:
cai()
elif inp_a == 4:
break