user.py
 1 class User():
 2     def __init__(self,name="guest",password='111111',status=1):
 3         self._name=name
 4         self._password=password
 5         self._status=status
 6     def define(self):
 7         if self._status==1:
 8             return '账户正常'
 9         elif self._status==0:
10             return '账户处于封禁状态'
11     def info(self):
12         print('-用户名,密码,账户状态:')
13         print(f'{self._name},{self._password},{User.define(self)}')
14     def modify_password(self):
15         x=eval(input('请输入旧密码:'))
16         if x==self._password:
17             y=input('请输入新密码:')
18             self._password=y
19             print('修改密码成功')
20             print(f'{self._name},{self._password},{User.define(self)}')
21         else:
22             n=0
23             while n<=1:
24                 z=input('输入错误,请重新输入:')
25                 n+=1
26             if n>1:
27                 print('账户已锁,请稍后再试')
28                 self._status=0
29                 print(f'{self._name},{self._password},{User.define(self)}')
30 
31 
32 a1=User('May',123456,1)
33 a1.info()
34 a1.modify_password()

 

 

task5.py

 1 from user import User
 2 class Admin(User):
 3     def __init__(admin,name='admin',password=9999,status=1):
 4         admin._name=name
 5         admin._password=password
 6         admin._status=status
 7     def def_ine(admin):
 8         if admin._status==1:
 9             return '账户正常'
10         elif admin._status==0:
11             return '账户处于封禁状态'
12     def reset_password(admin):
13         x0=eval(input('重置密码:'))
14         admin._password=x0
15     def ban_user(admin):
16         admin._status=0
17         print('已被封禁')
18     def unblock_user(self):
19         self._status=1
20         print('解封')
21     def in_fo(admin):
22         print('-用户名,密码,账户状态:')
23         print(f'{admin._name},{admin._password},{Admin.def_ine(admin)}')
24 
25 
26 a2=Admin()
27 a2.info()
28 a2.reset_password()
29 a2.in_fo()
30 a2.ban_user()
31 a2.in_fo()
32 a2.unblock_user()
33 a2.info()