How to use Python functional programming to realize login and registration function
This article will explain in detail how to use Python functional programming to achieve login registration function. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
The details are as follows
Code:
Def login (username, password): "" for user login: param username: user name entered by user: param password: password entered by user: return: true indicates successful login False login failed "" # Open file f = open ('db', 'r') # traverse line by line for line in f: line_list = line.strip () .split (' |') # split if line_list [0] = = username and line_list [1] = = password: return True return Falsedef register (username) Password): "" user registration function: param username: user name: param password: password: return: default returns null "f = open ('db' 'a') # append mode temp ='\ n' + username +'|'+ password f.write (temp) # write to file f.close () # main function def main (): t = input ('1: login 2: register') if t = '1login: user = input (' Please enter user name:') pwd = input ('Please enter password:) r = login (user) Pwd) if r: print ('login successful') else: print ('login failed') elif t = = '2login: user = input (' Please enter user name:') pwd = input ('Please enter password:') print ('registered successfully.') Register (user, pwd) # when the program is running, call the main function main ()
Create a db.txt (store login information) file in the following format:
Effect:
Log in
Register
On "how to use Python functional programming to achieve login registration function" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.