The registered user python function register ()

db_path = 'db.txt' # define the default file path, easy to modify 
DEF get_uname ():
the while True:
uname = the INPUT ( 'Please enter your user name:') Strip ().
IF uname.isalpha ():
with Open (r '% S'% (DB_PATH), 'R & lt', encoding = 'UTF-. 8') AS F:
for I in F:
. unifo = i.strip ( '\ n-') Split ( ',')
Print (unifo ) # View the discovery process
IF uname == unifo [0]:

Print ( 'user already exists, please re-enter')
BREAK
the else:
return uname
the else:
Print ( 'user name must be Chinese or the letter')
DEF get_pwd ():
while True:
pwd1 = input ( 'Enter password:') strip ().
pwd2 = input ( 'Please enter the password again:') Strip ().
IF pwd1 == pwd2:
return pwd1
the else:
Print ( 'password twice inconsistent input, please re-enter ...')
DEF get_bal ():
the while True:
BAL = the iNPUT ( 'Please enter the balance:')
IF bal.isdecimal ():
return BAL
the else:
Print ( 'money is digital, sucker ...')
DEF file_hanle (uname, pwd, BAL):
with Open ( R & lt '% S'% (DB_PATH), 'A', encoding = 'UTF-. 8') AS F:
f.write ( '% S,% S,% S \ n-'% (the uname, pwd, BAL))
the Register DEF ():
uname = get_uname () # get valid user name
pwd = get_pwd () # get a legitimate password
bal = get_bal () # get a legitimate balance
file_hanle (uname, pwd,bal) # write to file

register()

Guess you like

Origin www.cnblogs.com/mylu/p/10990684.html