实验七

class User:
    def __init__(self,name='guest',password=111111,status=1):
        self.name=name
        self.password=password
        self.status=status
    def info(self):
        print('账户信息:用户名,密码,账号状态')
        if self.status==1:
            print(f'{self.name},{self.password},账号状态正常')
        elif self.status==0:
            print(f'{self.name},{self.password},账号状态封禁')
    def modify_password(self,count=1):
        while count<=3:
            old_password=eval(input('请先输入旧密码:'))
            if old_password==self.password:
                new_password=eval(input('请输入新密码:'))
                self.password=new_password
                print('密码修改成功')
                break
            else:
                count+=1
                if count==4:
                    print('账户已锁,请稍后再试')
                continue
class Admin(User):
    def __init__(self,name='admin',password=999999,stasus=1):
        super().__init__(name,password,stasus)
    def info(self):
        if self.status == 1:
            print(f'{self.name},{self.password},正常账号')
        elif self.status == 0:
            print(f'{self.name},{self.password},封禁账号')
    def reset_password(self,User):
        self.password=111111
    def ban_user(self,User):
        self.status=0
    def unblock_user(self,User):
        self.status=1
#测试
def main():
    a1=User('John',123456)
    a1.info()
    a1.modify_password()
    a1.info()
    a2=Admin('Bob',123456)
    a2.info()
    a2.reset_password(a1)
    a2.ban_user(a1)
    a2.unblock_user(a1)
    a2.info()
if __name__=='__main__':
    main()

class User():
    count = 0
    def __init__(self, username='username', password='111', status='1'):
        self.username = username
        self.password = password
        self.status = status
        User.count += 1

    def __del__(self):
        User.count -= 1

    def info(self):
        if self.status == '1':
            print(f"{self.username}, {self.password}, 账户正常")
        else:
            print(f"{self.username}, {self.password}, 账户被封禁")
    def modify_password(self):
        for i in range(3):
            old_password = input("旧密码: ")
            if old_password == self.password:
                self.password = input("新密码: ")
                print("密码修改成功!")
                break
            elif i == 2:
                print("账户已锁, 请稍后再试...")
                self.status = '0'
            elif old_password != self.password:
                continue

    def show_count():
        print(f"用户总数: {User.count}")


class Admin(User):
    def __init__(self, username='Admin', password='999999', status='1'):
        super().__init__(username, password, status)

    def info(self):
        print("管理员账户: ")
        super().info()
    def reset_password(self, user):
        user.password = input("请输入你要修改的密码: ")

    def ban_user(self, user):
        user.status = '0'

    def unlock_user(self, user_name):
        user_name.status = '1'


u1=User('账户1','0000','1')
u1.info()
u1.modify_password()
u1.info()

admin1=Admin('管理员1','9999','1')
admin1.info()
User.show_count()

admin1.reset_password(u1)
admin1.ban_user(u1)
u1.info()
admin1.unlock_user(u1)
u1.info()
User.show_count()

 

posted @ 2022-06-08 09:46  杪秋有四0904  阅读(5)  评论(0编辑  收藏  举报