1 def out(): 2 username=input("请输入用户名:\n") 3 password=input("请输入密码:\n") 4 return username,password 5 def registered(): 6 username,password=out() 7 temp=username+"|"+password 8 with open(file="log.txt",mode="w",encoding="utf-8") as f: 9 f.write(temp) 10 def login(): 11 username,password=out() 12 with open(file="log.txt",mode="r",encoding="utf-8") as f: 13 lists=f.read().split("|") 14 if username==lists[0] and password==lists[1]: 15 return True 16 else: 17 print("你登录的账户有误,请重新登录") 18 def profile(): 19 with open(file="log.txt",mode="r",encoding="utf-8") as f: 20 lists=f.read().split("|") 21 print("欢迎访问{0}个人主页".format(lists[0])) 22 def main(): 23 while True: 24 try: 25 f=int(input("1、注册 2、登录 \n")) 26 if f==1: 27 registered() 28 elif f==2: 29 if login()==True: 30 profile() 31 else: 32 print("请输入正确的账户密码") 33 else: 34 break 35 except: 36 continue 37 38 if __name__ == '__main__': 39 main()
 
                    
                     
                    
                 
                    
                 
                
            
         
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号