python习题:登录注册小程序

登录注册程序:

#1、账号/密码/密码确认
#2、非空
#3、已经存在的不能注册
all_user = {'niuhanyang':'123456','tlx':'123456'}
while True:
username = input('username:').strip()
pwd = input('pwd:').strip()
cpwd = input('cpwd:').strip()
if username and pwd and cpwd:
if username in all_user:
print('用户名已经存在,请重新输入')
else:
if pwd==cpwd:
all_user[username]=pwd
print('注册成功!')
break
else:
print('两次输入的密码不一致')
else:
print('账号/密码/确认密码不能为空')

#登录程序
# 1、非空
# 2、如果输入的用户名不存在,要提示
#3、输入账号密码
while True:
username = input('username:').strip()
pwd = input('pwd:').strip()
if username and pwd:
if username in all_user:
src_pwd = all_user[username]
if src_pwd == pwd:
print('欢迎登录')
break
else:
print('密码输入错误!')
else:
print('输入的用户不存在')
else:
print('账号/密码不能为空')
原文地址:https://www.cnblogs.com/blackbird0423/p/8203451.html