class User():
def __init__(self,first_name,last_name,other):
self.first_name = first_name
self.last_name = last_name
self.other = other
self.login_attempts = 0
def describe_user(self):
print(self.first_name,self.last_name,self.other)
def greet_user(self):
print('Hello,'+ self.first_name + ' ' + self.last_name)
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
class Admin(User):
def __init__(self,first_name,last_name,other):
super().__init__(first_name,last_name,other)
self.privileges = ['can add post','caon delete post','an ban user']
def show_privileges(self):
for show_privileges in self.privileges:
print(show_privileges)
user = User('cao','feng','yanan')
user.describe_user()
user.greet_user()
user.increment_login_attempts()
print(user.login_attempts)
user.increment_login_attempts()
user.increment_login_attempts()
print(user.login_attempts)
user.reset_login_attempts()
print(user.login_attempts)
admin = Admin('张','三','延安')
admin.describe_user()
admin.show_privileges()
9-7
最新推荐文章于 2021-10-16 18:02:35 发布