Java教程

实验7

本文主要是介绍实验7,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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)}')


a1=User('May',123456,1)
a1.info()
a1.modify_password()

from user import User
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 reset_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)}')


a2=Admin()
a2.info()
a2.reset_password()
a2.in_fo()
a2.ban_user()
a2.in_fo()
a2.unblock_user()
a2.info()

 

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