def login(username, password): f = open("sample2", "r") for line in f: line_list = line.split(":") if line_list[0] == username and line_list[1] == password: return True return False def register(username, password): f = open("sample2", "a") temp = username + ":" + password f.write(temp) f.close() def main(): t = input("1:登陆 2:注册") if t == "1": user = input("请输入用户名") psw = input("请输入") r = login(user, psw) if r: print("登陆成功") else: print("登陆失败") elif t == "2": print("注册")