实验七
作者:互联网
1 class User: 2 def __init__(self, name, password='111111', status='1'): # 构造新账户 3 self.name = name 4 self.password = password 5 self.status = status 6 7 def info(self): 8 if self.status=='1': 9 print(f'用户名:{self.name},密码:{self.password},账号正常') 10 else: 11 print(f'用户名:{self.name},密码:{self.password},账号封禁') 12 13 def modify_password(self): 14 for i in range(3): 15 oldpassword=input('请输入旧密码') 16 if oldpassword==self.password: 17 newpassword=input('输入新密码:') 18 print('修改成功') 19 elif i==2: 20 print('账户已锁,稍后再试') 21 self.status='0' 22 elif oldpassword!=self.password: 23 continue 24 25 26 27 class Admin(User): 28 def __init__(self, name='admin', password=999999, status=1): # 构造新账户 29 super().__init__(name,password,status) 30 31 def info(self): 32 super().info() 33 34 def reset_password(self,user): 35 a=input('请输入你要修改的密码') 36 user.password=a 37 38 def ban_user(self,user): 39 if user.status=='0': 40 print('封禁账户') 41 42 def unblock_user(self,user): 43 if user=='1': 44 print('解封账户') 45 46 u1 = User('账户a', '5555', '1') 47 u1.info() 48 u1.modify_password() 49 u1.info() 50 51 admin1 = Admin('管理员', '999999', '1') 52 admin1.info() 53 54 admin1.reset_password(u1) 55 admin1.ban_user(u1) 56 u1.info() 57 admin1.unlock_user(u1) 58 u1.info()
标签:info,self,u1,实验,user,password,def 来源: https://www.cnblogs.com/lffwrx1121/p/16355965.html