实验七

user.py

 1 class User:
 2     count=0
 3     def __init__(self,name='guest',password='111111',status='1'):
 4         User.count+=1
 5         self.name=name
 6         self.password=password
 7         self.status=status
 8     def info(self):
 9         print(f'用户名:{self.name}\n密码:{self.password}')
10         if self.status=='1':
11             print('帐号状态正常')
12         else:
13             print('账号处于封禁状态')
14     def modify_password(self):
15         n=0
16         for i in range(3):
17             a=input('输入旧密码:')
18             if a==self.password:
19                 b=input('输入新密码:')
20                 self.password=b
21                 print('密码修改成功')
22                 break
23             else:
24                 n+=1
25         if n==3:
26             self.status='0'
27             print('账户已锁,请稍后再试')
28     @classmethod
29     def show_count(cls):
30         print(f'用户总数:{User.count}')
31 class Admin(User):
32     def __init__(self,name='admin',password='999999',status='1'):
33         super(Admin,self).__init__(name,password,status)
34     def info(self):
35         print('管理员账户')
36         super().info()
37     def reset_password(self,user):
38         user.password=input('输入新的密码:')
39         print('密码修改成功')
40     def ban_user(self,user):
41         user.status='0'
42         print('账号已封禁')
43     def unblock_user(self,user):
44         user.status='1'
45         print('账号已解封')
46 def main():
47     a=User()
48     a.info()
49     a.modify_password()
50     b=User('joe','123456','0')
51     b.info()
52     User.show_count()
53     c=Admin()
54     c.info()
55     c.reset_password(a)
56     c.unblock_user(b)
57     a.info()
58     b.info()
59 if __name__=='__main__':
60     main()

 

 task5.py

 1 from user import User,Admin
 2 a=User('marry','121212','1')
 3 b=User('Taylor','123456','0')
 4 a.info();b.info()
 5 b.modify_password()
 6 b.info()
 7 User.show_count()
 8 c=Admin()
 9 c.info()
10 c.reset_password(a)
11 c.ban_user(a)
12 c.unblock_user(b)
13 a.info();b.info()

 

posted on 2022-06-07 11:41  VolcanX  阅读(6)  评论(1编辑  收藏  举报