实验7

 1 class User:
 2     count=0
 3     def __init__(self,name='爷傲奈我何',password=5201314,state=1):
 4         self.name = name
 5         self.password = password
 6         self.state= state
 7         User.count+=1
 8     def info(self):
 9         if self.state==1:
10             print(self.name,self.password,'正常')
11         else:
12             print(self.name, self.password,'异常')
13     def modify_password(self):
14         x = 1
15         while True:
16             a=eval(input('输入密码:'))
17             if a!=self.password and x<=2:
18                 print("密码错误")
19                 x+=1
20                 continue
21             elif x>2:
22                 print('账号给你锁了')
23                 self.state =0
24                 break
25             elif a==self.password:
26                 e=eval(input("修改新密码:"))
27                 self.password=e
28                 print('修改成功')
29                 break
30 x1=User()
31 x1.info()
32 x1.modify_password()
33 x1.info()
34 print('用户数:',User.count)

 

 1 class Admin(User):
 2     count = 0
 3 
 4     def __init__(self, name='小帅哥', password=13333, state=1):
 5         User.__init__(self, name='admin', password=13333, state=1)
 6 
 7     def info(self):
 8         User.info(self)
 9 
10     def modify_password(self):
11         User.modify_password(self)
12 
13     def reset_password(self):
14         q = eval(input('重置:'))
15         self.password = q
16         print('成功')
17 
18     def ban_user(self):
19         self.state = 0
20         print('封禁')
21 
22     def unblock_user(self):
23         self.state = 1
24         print('解开封印')
25 
26 
27 x = Admin()
28 x.info()
29 x.modify_password()
30 x.info()
31 print('用户数:', User.count)
32 x.reset_password()
33 x.ban_user()
34 x.unblock_user()

难哦,好多东西要记哦。

posted @ 2022-06-02 10:43  气工吴旭  阅读(8)  评论(2编辑  收藏  举报