注册
def register():
registor_count = 0
while registor_count < 3:
username_inp = input('输入用户名:')
userpwd_inp = input('输入密码:')
re_userpwd_inp = input('再次输入密码:')
if userpwd_inp == re_userpwd_inp:
with open('user_info.txt','a',encoding = 'utf8') as fa:
fa.write(f'{username_inp}:{userpwd_inp}
')
print('注册成功')
break
else:
registor_count += 1
print('密码不同')
continue
登录
def login():
username_inp = input('输入用户名:')
userpwd_inp = input('输入密码:')
with open('user_info.txt','r',encoding='utf8') as fr:
for user_info in fr:
user_name,user_pwd =user_info.split(':')
if (user_name.strip() == username_inp and user_pwd.strip() == userpwd_inp):
print('登录成功')
break
else:
print('登录失败')
猜年龄
def guess_age():
age = 18
guess_count = 0
while guess_count < 3:
guess_age = int(input('你猜的年龄:'))
guess_count += 1
if guess_age > age:
print('猜大了')
elif guess_age < age:
print('猜小了')
else:
print('猜对了')
break
else:
print('呵呵 牛逼 牛逼')
选择奖品
def prize():
prize_dict = {
'1':'奖品1',
'2':'奖品2',
'3':'奖品3',
'4':'奖品4'
}
print(prize_dict)
prize_choice = input('选择一个奖品:')
if prize_choice in prize_dict:
print(f"你选择了一个{prize_dict.get(prize_choice)}")
else:
print('没有该商品')
def menu():
register()
login()
guess_age()
prize()
menu()