实验七

2022/6/7 23:21:13

本文主要是介绍实验七,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

class User:
    def __init__(self, name='guest', password='111111', status='1'):
        self.name=name
        self.password=password
        self.status=status
    def modify_password(self):
        i=0
        while i<=3:
            x1=input('输入旧密码:')
            if x1!=self.password:
                i+=1
                if i==3:
                    print('账户已锁,请稍后再试。')
                    break
            else:
                x2=input('输入新密码:')
                print('密码修改成功!')
                break
    def info(self):
        print(f'用户名:{self.name} 密码:{self.password} 账号状态:{self.status}')


a1 = User('Joe', '5006692', 1)
a1.modify_password()

class Admin(User):
    def __init__(self, name='admin', password='999999', status='1'):
        User(). __init__(name, password, status)
    def info(self):
        User().info()
    def reset_password(self,user):
        user.password='999999'
    def ban_user(self,user):
        user.status='0'
    def unblock_user(self,user):
        user.status='1'
from user import User, Admin

u1 = User('Bob', '123456', '1')
u1.info()
u1.modify_password()
u1.info()

u2 = Admin('Joe', '654321', '1')
u2.info()
u2.reset_password(u1)
u2.ban_user(u1)
u1.info()
u2.unblock_user(u1)
u1.info()

 



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


扫一扫关注最新编程教程