-
- class User():
- """用户信息及描述"""
- def __init__(self, first_name, last_name, sex):
- self.first = first_name
- self.last = last_name
- self.sex = sex
- self.login_attempts = 0
-
- """打印用户信息"""
- def describe_user(self):
- print('\nName: ' + self.first.title() +
- self.last.title(), '\nSex: ' + self.sex)
-
- """打印问候语"""
- def greet_user(self):
- if self.sex == 'man':
- print('\nMr. ' + self.first.title() +
- ' Welcome to the python.')
- else:
- print('\nMis. ' + self.first.title() +
- ' Welcome to the python.')
-
- """尝试次数统计"""
- def increment_login_attempts(self):
- self.login_attempts += 1
-
- """重置尝试次数"""
- def reset_login_attempts(self):
- if login_attempts != 0
- login_attempts == 0
-
-
- class Admin(User):
- """管理员用户信息"""
- def __init__(self, first_name, last_name, sex):
- """初始化父类"""
- super().__init__(first_name, last_name, sex)
- self.privileges = ["can add post",
- "can delete post", "can ban user"]
-
- """显示管理员权限"""
- def show_privileges(self):
- for pri in self.privileges:
- print('\n - ' + pri.titler())
-
- liu = Admin('li', 'qiang', 'man')
- liu.show_privileges()
-
-
提示错误是:
-
- File "/private/var/mobile/Containers/Shared/AppGroup/106E91C2-1881-478A-9069-7F89CF8A559C/Pythonista3/Documents/练习用.py", line 4
- def __init__(self, first_name, last_name, sex):
- ^
- IndentationError: unindent does not match any outer indentation level
-