实验七

class User():
  count = 0
  def __init__(self, username='guest', password='111111', 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'
from user import User, Admin

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

admin1 = Admin('Admin1', '223322', '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-01 19:00  云处安  阅读(13)  评论(2编辑  收藏  举报