I do not know whether there is a feeling, I clearly learned, why a code does not know where to write.
Beginner function Programming Small partners often need to detect their own learning results, we now write a function to implement login and registration of small programs
def login (Username,password): "For user login:p Aram Username: User entered user name:p Aram Password: User entered password: return:true means log in as Fp=open (' DB ', ' r ') for line in Fp:username_list=line.split (', ') if username_list[ 0] = = Username and Username_list[1]==password:return True return falsedef sign_up (username,password): ' ' User Registration:p Aram Username: User entered the registered user name:p Aram Password: User entered the registration password: return: True indicates successful registration, there is no if judgment, so will not return false! "' Fp=open (' DB ', ' a ') temp= ' \ n ' +username+ ', ' +password fp.write (temp) fp.close () return truedef main (): ' Function entry, select the start of registration, login, exit ' choice=input (' Please enter your choice. A (login), B (sign up), C (exit): ') #选择接下来的步骤 if choice== ' a ': #如果选择登陆执行此代码 print (' You have selected login ') user=input (' Please lose into your username: ') pwd=input (' Please enter your password: ') r=login (user,pwd) if R:print (' login successful ') Else: Print (' Login failed ') elif choice== ' B ': #如果选择注册执行此代码 print (' You have selected sign up) ' User=input (' Please enter the username you want to register: ') pwd=input (' Please enter the password you want to register: ') r=sign_up (user,pwd) if R:print (' register Requirements! ') print (' Congratulations! ' + ' \ n ' + ' register through! ') elif choice== ' C ': #如果选择退出执行此代码 print (' You have selected C (exit) ') main () #运行main函数
It is important to note that:
(1), we need to create a TXT file named db in the IDE:
Right-click the root folder: Select new--Select File
Then enter a name for the database (this is called DB for convenience), select OK
File type is text (TXT), select OK
(2), usually when we are in open (' DB '), we need to append the opening type later, we use the read-only (R) and append mode to open the file (a) in the instance. A query form is attached below:
Python Programming: Functional programming for sign-in and registration