class User(): def __init__(self,name="guest",password='111111',status=1): self._name=name self._password=password self._status=status def define(self): if self._status==1: return '账户正常' elif self._status==0: return '账户处于封禁状态' def info(self): print('-用户名,密码,账户状态:') print(f'{self._name},{self._password},{User.define(self)}') def modify_password(self): x=eval(input('请输入旧密码:')) if x==self._password: y=input('请输入新密码:') self._password=y print('修改密码成功') print(f'{self._name},{self._password},{User.define(self)}') else: n=0 while n<=1: z=input('输入错误,请重新输入:') n+=1 if n>1: print('账户已锁,请稍后再试') self._status=0 print(f'{self._name},{self._password},{User.define(self)}') a1=User('May',123456,1) a1.info() a1.modify_password()
from user import User class Admin(User): def __init__(admin,name='admin',password=9999,status=1): admin._name=name admin._password=password admin._status=status def def_ine(admin): if admin._status==1: return '账户正常' elif admin._status==0: return '账户处于封禁状态' def reset_password(admin): x0=eval(input('重置密码:')) admin._password=x0 def ban_user(admin): admin._status=0 print('已被封禁') def unblock_user(self): self._status=1 print('解封') def in_fo(admin): print('-用户名,密码,账户状态:') print(f'{admin._name},{admin._password},{Admin.def_ine(admin)}') a2=Admin() a2.info() a2.reset_password() a2.in_fo() a2.ban_user() a2.in_fo() a2.unblock_user() a2.info()