1.管理员:管理员是一种特殊的用户。编写一个名为Admin的类,让它继承你为编写的User类。添加一个名为privileges的属性,用于存储一个由字符串(如"can add post"等)组成的列表。编写一个名为show_privileges()的方法,它显示管理员的权限。创建一个Admin实例,并调用这个方法。
class User():
def __init__(self,login_attempts):
self.login_attempts=login_attempts
def increment_login_attempts(self,login_attempts):
self.login_attempts+=1
if login_attempts>=self.login_attempts:
self.login_attempts=login_attempts
print(login_attempts)
else:
print("不能打印该值。")
def reset_login_attempts(self):
login_attempts=0
class Admin(User):
def __init__(self,login_attempts):
self.login_attempts=login_attempts
super().__init__(login_attempts)
privileges=[]
privileges.append(login_attempts)
def show_privileges(self):
print("管理员的权限为:"+str(self.login_attempts))
my_user=User(1)
my_user.increment_login_attempts(2)
my_user.increment_login_attempts(3)
my_user.reset_login_attempts()
Admin=Admin("can not post")
Admin.show_privileges()