实验7 类和模块

2022/6/6 23:23:10

本文主要是介绍实验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()

 



这篇关于实验7 类和模块的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程