当前位置: 移动技术网 > IT编程>脚本编程>Python > python 函数 之 用户注册register()

python 函数 之 用户注册register()

2019年06月09日  | 移动技术网IT编程  | 我要评论
db_path='db.txt'  #定义默认文件路径,方便修改
def get_uname():
while true:
uname=input('请输入用户名:').strip()
if uname.isalpha():
with open(r'%s' %(db_path),'r',encoding='utf-8') as f:
for i in f:
unifo=i.strip('\n').split(',')
print (unifo) #查看查找过程
if uname==unifo[0]:

print('用户已存在,请重新输入')
break
else:
return uname
else:
print ('用户名必须是中文或字母')
def get_pwd():
while true:
pwd1=input('请输入密码:').strip()
pwd2=input('请再次输入密码:').strip()
if pwd1 == pwd2:
return pwd1
else:
print('两次输入的密码不一致,请重新输入...')
def get_bal():
while true:
bal=input('请输入余额:')
if bal.isdecimal():
return bal
else:
print ('钱是数字,傻逼 。。。')
def file_hanle(uname, pwd, bal):
with open(r'%s' %(db_path),'a',encoding='utf-8') as f:
f.write('%s,%s,%s\n' %(uname, pwd, bal))
def register():
uname = get_uname() # 拿到合法的用户名
pwd = get_pwd() # 拿到合法的密码
bal = get_bal() # 拿到合法的余额
file_hanle(uname, pwd, bal) # 写入文件

register()

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网