实验7 类和模块
作者:互联网
task5
class User: def __init__(self,name='guest',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},账号状态正常') elif self.status == 0: print(f'用户名:{self.name},密码:{self.password},账号处于封禁状态') def modify_password(self): User.count=0 while User.count<3: x=eval(input('请输入原密码:')) if x == self.password: y=eval(input('请输入新密码:')) print('密码修改成功') self.password=y break else: User.count+=1 else: print('账户已锁,请稍后再试') class Admin(User): def __init__(self,name='admin',password=999999,status=1): super().__init__(name,password,status) def info(self): print("管理者账户") super().info() def reset_password(self,a): a.modify_password() def ban_user(self,a): a.status=0 def unblock_user(self,a): a.status=1 if __name__ == "__main__": u1 = User() u1.info() admin1 = Admin() admin1.info() admin1.ban_user(u1) u1.info() admin1.unblock_user(u1) u1.info() admin1.reset_password(u1)
from user import User as User1, Admin as Admin1 u1=User1() u1.info() u1.modify_password() u1.info() a1=Admin1() a1.reset_password(u1) u1.info() a1.ban_user(u1) u1.info() a1.unblock_user(u1) u1.info()
标签:info,status,name,self,u1,实验,模块,password 来源: https://www.cnblogs.com/123gan/p/16349579.html