user
1 class User: 2 def __init__(self,name='guest',password='111111',statu='1'): 3 4 self.name=name 5 self.password=password 6 self.statu=statu 7 def info(self): 8 if self.statu == '1': 9 print(f'{self.name},{self.password} 账户正常') 10 else: 11 print(f'{self.name},{self.password} 账户被封禁') 12 def modify_password(self): 13 old_password=input('请输入旧密码1:') 14 num=0 15 while True: 16 if old_password == self.password: 17 new_password=input('请输入新密码:') 18 print('密码修改成功') 19 self.password=new_password 20 break 21 elif old_password != self.password: 22 if num<3: 23 print('用户名或密码错误,请重新输入') 24 old_password=input('请输入旧密码2:') 25 num+=1 26 else: 27 print('账户已锁,请稍后再试') 28 self.statu == '0' 29 break 30 31 32 u1 = User('Jack', '202185', '1') 33 u1.info() 34 u1.modify_password() 35 u1.info()
text5:
1 class User: 2 def __init__(self,name='guest',password='111111',statu='1'): 3 4 self.name=name 5 self.password=password 6 self.statu=statu 7 def info(self): 8 if self.statu == '1': 9 print(f'{self.name},{self.password} 账户正常') 10 else: 11 print(f'{self.name},{self.password} 账户被封禁') 12 def modify_password(self): 13 old_password=input('请输入旧密码1:') 14 num=0 15 while True: 16 if old_password == self.password: 17 new_password=input('请输入新密码:') 18 print('密码修改成功') 19 self.password=new_password 20 break 21 elif old_password != self.password: 22 if num<3: 23 print('用户名或密码错误,请重新输入') 24 old_password=input('请输入旧密码2:') 25 num+=1 26 else: 27 print('账户已锁,请稍后再试') 28 self.statu == '0' 29 break 30 class Admin(User): 31 def __init__(self,name='admin',password='999999',statu='1'): 32 33 self.name=name 34 self.password=password 35 self.statu=statu 36 def reset_password(self,User): 37 User.modify_password() 38 def ban_User(self,User): 39 User.statu == '0' 40 def unblock_User(self,User): 41 User.statu == '1' 42 43 44 u1 = User('Jack', '202185', '1') 45 u1.info() 46 u1.modify_password() 47 u1.info() 48 admin1 = Admin('管理员1', '999999', '1') 49 admin1.info() 50 admin1.reset_password(admin1) 51 admin1.ban_User(admin1) 52 admin1.info() 53 admin1.unblock_User(admin1)
实验总结:
我知道我的代码是错的,因为它不能循环判断账号封禁情况。但是不知道该怎么改正
请求大佬帮助,也许可以打在评论区。