选择奖品函数
def register():
'''注册'''
print('注册')
for i in range(3):
usename_inp = input('请输入您的用户名:')
pwd_inp = input('请输入您的密码:')
pwd1_inp = input('请再次输入密码:')
if not pwd_inp == pwd1_inp:
print('输入错误,请重新输入')
continue
with open('用户信息.txt', 'a+', encoding='utf-8') as fa:
fa.write(f'{usename_inp}:{pwd_inp}\n')
print('注册成功')
break
def login():
'''登录'''
print('登录')
count=0
while count<3:
usename_inp = input('请输入你的用户名:')
pwd_inp = input('请输入你的密码:')
with open(r'C:\Users\Administrator\PycharmProjects\untitled1\用户信息.txt', 'r', encoding='utf8') as fr:
for i in fr:
i = i.strip('\n')
# print(i)
i = i.split(':')
# print(i)
usename_inp_lis, pwd_inp_lis = i
# print(usename_inp_lis,pwd_inp_lis)
if usename_inp == usename_inp_lis and pwd_inp == pwd_inp_lis:
print('登录成功')
count=3
guess()
break
else:
print('登录失败')
count+=1
def guess():
'''猜谜'''
age = 20
num=0
while num<3:
print('友情提醒:要输数字')
age_in=input('请输入年龄:')
if age_in.isdigit():
age_in=int(age_in)
if age_in == age:
print('猜对了')
prize()
break
else:
print('猜错了')
num += 1
else:
num+=1
if num == 3:
j = 1
n = 3
while j <= 4:
inp = input('想继续玩吗?想玩请输入y,不想玩请输入x:')
if inp in ['y', 'Y']:
num = 0
break
elif inp in ['x', 'X']:
break
else:
if j == 4:
break
print(f'耍我呢吧,再给你{n}次机会')
n -= 1
j += 1
def prize():
'''选礼物'''
prize_dic={
'0':'iphone8',
'1':'小米',
'2':'华为',
'3':'oppo'
}
prize_lis='''
0:iphone8
1:小米
2:华为
3:oppo
'''
count=0
prize={}
while count<2:
print(prize_lis)
prize_inp = input('请选择你想要的礼物编号:')
if prize_inp.isdigit():
prize_inp = prize_dic[prize_inp]
if prize_inp in prize:
prize[prize_inp] += 1
else:
prize[prize_inp] = 1
else:
if count==1:
print('傻逼')
break
print('请输入数字')
count+=1
if len(prize)==0:
print('一个礼物都没有,叫你瞎几把输,lowbee👀')
elif len(prize)==1:
if list(prize.values())[0]==1:
print(f'谁叫你瞎输的,你只获得了一部{list(prize.keys())[0]}')
else:
print(f'恭喜你获得了{list(prize.keys())[0]}两部,不过你要两部手机干啥?')
else:
print(f'恭喜你获得了{list(prize.keys())[0]}和{list(prize.keys())[1]},人生赢家啊!')
register()
login()