当前位置:网站首页>Register login 1
Register login 1
2022-04-22 02:00:00 【Right ear to refuel】
2.2: Write a program to realize user registration ( Register in file ), You can log in. ( The login information comes from the file ) # Tips : while True: msg = """ 0 sign out 1 Sign in 2 register """ print(msg) cmd = input(' Please enter the command number >>: ').strip() if not cmd.isdigit(): print(' You must enter a number for the command number , silly ass ') continue if cmd == '0': break elif cmd == '1': # Login function code ( additional : You can nest previous loops , Three wrong input exits are introduced ) # print(f" The account password entered by the user is :{name},{passward}") # 2, Read the user's data from the file for verification tag=True namelist = {} while tag: with open(" Account password book ", "r", encoding="utf-8") as f: for line in f: a,b,c=line.strip().split(":") # res = f.read().strip() # a,b = res.split(":") namelist[a]=line.strip().split(":") # print(f" The account password stored in the file is :{a},{b},{c}") # namelist=dict(set(namelist)) print(namelist) name = input(" Please enter your account number :").strip() print(namelist[name]) if name in namelist: count = 0 while count < 3: passward = input(" Please enter your password :").strip() if passward in namelist[name]: print(" Landing successful ") tag = False break else: print(f" Login failed , Please input the password again , Do you have {2-count}") count+=1 # else: # print(" Incorrect account number , Please re-enter " # ) break elif cmd == '2': # Register function code username = input(" Please enter a user name :").strip() passward=input(" Please input a password :").strip() with open(" Account password book ","a+",encoding="utf-8")as f: f.write("%s:%s:%d"%(username,passward,1,)) f.write("\n") else: print(' The command you entered does not exist ') # reflection : The above if Whether the function of branching can be realized in other more elegant ways
Code thinking : Two big structures : Sign in and sign up . Registration is to send information through w The mode is written into the account password file , Login is through r Mode read information . This is just a big direction . When using the cycle to read the information of the account password book, the pointer is at the end , So you need to put the read data into a dictionary . Finally, just check whether the account number is in the dictionary . utilize while Cycle to control the number of reads , This code does not realize the function of account locking
版权声明
本文为[Right ear to refuel]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211528165758.html
边栏推荐
- Android four components interview
- Advanced C language formula 41: analysis of classical problems of memory operation I
- MySQL -- master slave synchronization
- 判断是否为平方数的和
- QT程序打包成一个exe可执行文件
- Good news, Jingzhun GPS Beidou timing system helps South Asia electronic management system
- Profiteering method of blind box project
- Ezreal--将一个动画切割为四动作动画成功---New Unity Project (3).
- What is the role of proxy IP in the Internet?
- Advanced formula 44 of C language: the secret of function parameters (Part 1)
猜你喜欢

Method for extracting middle layer output of CNN model

Pycharm implements the setting of Automatic Parameter annotation identification

Bluemoon target penetration test
![[DFS] [pruning] kittens climb mountains](/img/38/4b314acf4bec81c173abab19c91bb7.png)
[DFS] [pruning] kittens climb mountains

In depth understanding Construction mode of thread synchronization in. Net (1) user mode construction

树、二叉树和森林的转换

Advanced formula 43 of C language: the meaning of function

kubernetes gvk显示现象

什么智能合约?dapp合约系统定制技术原理分析

Bsides-vancouver-2018-workshop target penetration test
随机推荐
Leetcode 203. Remove linked list elements
【DFS】【剪枝】数独(简单版)
[编程题]简单错误记录
Precise timing, GPS Beidou satellite timing synchronization clock system ceiling
MySQL -- master slave synchronization
[FAQ] Anaconda prompt reports an error. Solving environment: failed
[programming question] water bottle
stack和queue
16进制转换
【查看已经安装的包和命令是由哪个包提供的】
The idea window cannot be found in multi screen mode
The purpose of software testing, why do you do software testing?
Advanced formula 44 of C language: the secret of function parameters (Part 1)
Time and current time judgment in MySQL database
DEJA_ Vu3d - cesium feature set 013 - military plotting Series 7: regular polygon
Transformation of trees, binary trees and forests
QT program is packaged into an EXE executable file
[Lua program to control the mobile phone to chat] - it is used to keep the number. You can put down your hand for automatic chat and keep the number
喜讯,京准GPS北斗对时系统助力南亚电子管理系统
GreenDao的使用;