#!/usr/bin/env python
#-*-coding:utf-8-*-
Count = 0
Flag = 0
#提示用户需要做什么操作
option = Int (Input (" Hint: The number 1 is the registered user, the number 2 is the login system, select: "))
If option = 1:
user = input (" Please enter user name: ")
passwd = input (" Please enter password: ")
f = open ("User.txt", "a")
F.write ("%s:%s\n"% (user,passwd))
F.close ()
elif option = = 2:
While Coun T < 3:
user = input ("Enter login name:")
passwd = input ("Please enter password:")
Userpasslist = [I.strip () for I in open (' User.txt ', ' R '). ReadLines ()] #按行读取文件内容, and go to the space.
for I in userpasslist:
Username = i.split (': ') [0]
Paasword = I.split (': ') [1]
If user = = Username and passwd = = Paasword:
flag = 1
Break
If Flag = = 1:
Break
Else:
Count + = 1
If flag = = 1:
Print ("Login Successful")
Else:
Print ("Login failed")
Else:
Print ("Input error, SX")
1.python Language Implementation user logon program