实验七

-----

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)}')

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 rest_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)}')
adult=User("baby",1234,1)
adult.modify_password()
x=Admin()
x.rest_password()
x.in_fo()
x.ban_user()
x.in_fo()
x.unblock_user()
x.info()

 

-------恢复内容开始------------

------------恢复内容结束------------

posted @ 2022-06-07 16:14  刘思彤、  阅读(9)  评论(2编辑  收藏  举报