实验7

1,实验任务5

 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 modify_password(self):
 7         n=0
 8         d=input('请输入旧密码:')
 9         while n!=2:
10             if d==self.password:
11                 b=input('输入新密码:')
12                 self.password=b
13                 print('密码修改成功')
14                 break
15             else:
16                 d=input('输入错误,重新输入密码')
17                 n+=1
18         if n==2:
19             self.status='封禁状态'
20             print('账户已锁,请稍后再试')
21     def info(self):
22         if self.status==1:
23             print(f'用户名:{self.name},密码:{self.password},账号状态:账号正常')
24         else:
25             print(f'用户名:{self.name},密码:{self.password},账号状态:账号封禁')
26 class Admin(User):
27     def __init__(self,name='admin',password='999999',status=1):
28         self.name=name
29         self.password=password
30         self.status=status 
31     def info(self):
32         def info(self):
33             if self.status==1:
34                 self.status='账户正常'
35             else:
36                 self.status='账户被封禁'
37                 print('管理员账户:')
38                 print(self.name,self.password,self.status)
39     def reset_password(self,user):
40         a=input('请输入你要修改的密码')
41         user.password=a
42     def ban_user(self,user):
43         user.status=0
44     def unblock_user(self,user):
45         user.status=1
46 
47 u1=User()
48 u1.info()
49 u1.modify_password()
50 u1.info()
51 a1=Admin()
52 a1.reset_password(u1)
53 a1.ban_user(u1)
54 u1.info()
55 a1.unblock_user(u1)
56 u1.info()

实验结果:

 1 from user import User,Admin
 2 u1=User()
 3 u1.info()
 4 u1.modify_password()
 5 u1.info()
 6 a1=Admin()
 7 a1.reset_password(u1)
 8 a1.ban_user(u1)
 9 u1.info()
10 a1.unblock_user(u1)
11 u1.info()

实验结果:

 

posted @ 2022-06-07 11:37  炸呼  阅读(8)  评论(1编辑  收藏  举报