Python Programming: Functional programming for sign-in and registration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.