实验7

2022/6/1 23:22:06

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

 



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


扫一扫关注最新编程教程