lingcooo 2021-10-27 21:45 采纳率: 90.9%
浏览 17
已结题

实在找不出哪里缩进有问题


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

  • 写回答

1条回答 默认 最新

  • 辉煌仪奇 2021-10-27 21:56
    关注

    你好,你的程序的错误的地方有几处,我就不一一说了,直接将修改好的代码发给你,你对比一下就知道了,

    
    
    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 self.login_attempts != 0:
                self.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.title())
    
    
    liu = Admin('li', 'qiang', 'man')
    liu.show_privileges()
    

    运行结果

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月4日
  • 已采纳回答 10月27日
  • 创建了问题 10月27日

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用