实验七

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

 

posted @ 2022-06-08 13:13  pray4hell  阅读(3)  评论(2编辑  收藏  举报