python登陆,注册小程序
1 def login(username,password): 2 ''' 3 用于用户登录 4 :param username: 用户输入用户名 5 :param password: 用户输入密码 6 :return: True表示登陆成功 7 ''' 8 f = open("db","r") 9 for line in f:#一行一行检测 10 line_list = line.strip().split("|") 11 if line_list[0] == username and line_list[1] == password: 12 return True 13 14 def register(username,password): 15 ''' 16 用户注册 17 :param username: 用户名 18 :param password: 密码 19 :return: 默认返回None 20 ''' 21 f = open("db", "a") 22 temp = "\n" + username + "|" +password 23 f.write(temp) 24 f.close() 25 26 def main(): 27 t = input("1:登陆 2:注册") 28 if t == "1": 29 user = input("请输入用户名:") 30 pwd = input("请输入密码:") 31 r = login(user,pwd) 32 if r: 33 print("登陆成功") 34 else: 35 print("登陆失败") 36 elif t == '2': 37 user = input("请输入用户名:") 38 pwd = input("请输入密码:") 39 register(user,pwd) 40 main()