实验7
class User: def __init__(self, name, password='111111', status='1'): self.name = name self.password = password self.status = status def info(self): if self.status=='1': print(f'用户名:{self.name},密码:{self.password},账号正常') else: print(f'用户名:{self.name},密码:{self.password},账号封禁') def modify_password(self): for i in range(3): oldpassword=input('请输入旧密码:') if oldpassword==self.password: newpassword=input('输入新密码:') print('修改成功') break elif i==2: print('账户已锁,稍后再试') self.status='0' elif oldpassword!=self.password: continue class Admin(User): def __init__(self, name='admin', password=999999, status=1): super().__init__(name,password,status) def info(self): super().info() def reset_password(self,user): user.password=input('请输入你要修改的密码:') def ban_user(self,user): if user.status=='0': print('封禁账户') def unblock_user(self,user): if user=='1': print('解封账户')
from user import User, Admin u1 = User('野兽前辈', '114514', '1') u1.info() u1.modify_password() u1.info() admin1 = Admin('admin', '999999', '1') admin1.info() admin1.reset_password(u1) admin1.ban_user(u1) u1.info() admin1.unblock_user(u1) u1.info()