|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import json as j
def creat():
with open(r'c:\users\30614\desktop\python\account.txt','r') as file_open:
account_1=file_open.read()
account_2=j.loads(account_1)
prompt='please,enter your aoccunt name:'
name=input(prompt)
while name in account_2:
prompt='please,change anonther account name:'
name=input(prompt)
else:
pass
passwd=input('please,enter your passwd:')
check(passwd)
account_2[name]=passwd
file_open.close()
with open(r'c:\users\30614\desktop\python\account.txt','w') as file_open_2:
account_3=j.dumps(account_2)
file_open_2.write(account_3)
def check(passwd):
if len(passwd)<=6:
passwd=input('your password length is too short,please,enter another one:')
check(passwd)
else:
return passwd
creat()
再把密码储存到文件中的时候,发现个问题。在红字处,当输出密码过短时,应该是重新输入一个长的。
please,enter your aoccunt name:jojo
please,change anonther account name:jojo
please,change anonther account name:jfjlkdfgjkf
please,enter your passwd:888
your password length is too short,please,enter another one:7897978986796
以上为运行结果
但在txt文件中
{"jojo": "jidfjodfj", "jfjlkdfgjkf": "888"}
还是以短的那次保存的。
我理解这是局部变量的关系,所以到这里该怎么改,让check()中的passwd出去
是我对return的理解错了么 |
|