Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python functional programming to realize login and registration function

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report