实验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('修改成功') 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): a=input('请输入你要修改的密码') user.password=a 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('账户a', '5555', '1') u1.info() u1.modify_password() u1.info() admin1 = Admin('管理员', '999999', '1') admin1.info() admin1.reset_password(u1) admin1.ban_user(u1) u1.info() admin1.unlock_user(u1) u1.info()
标签:status,info,self,u1,实验,user,password 来源: https://www.cnblogs.com/Dejayh/p/16335638.html