简体   繁体   English

登录系统的 Python 中的预期缩进块错误

[英]Expected indented block Error in Python for a login system

Please, I need help with this login system that I am currently working on, but I keep on getting the indented block error at def password().拜托,我需要有关我目前正在使用的登录系统的帮助,但我不断收到 def password() 处的缩进块错误。 I'm new to python but have worked with Java for a few years.我是 python 的新手,但与 Java 合作了几年。 I have tried to indent the def password(), but it just keeps on popping up.我试图缩进def密码(),但它只是不断弹出。

def username():
    userinputname = input('Please enter the username')
    if userinputname == user:
        password()
    elif userinputname != user:
        print('Wrong username, please try again')
        username()
    else:
        # problems()3


def password():
    userinputpass = input('Please enter the password')
    if  userinputpass == passs:   
        main()
    elif userinputpass != passs
        for x <=5:  
            print('Wrong password, please try again')
            x++
        exit
    else:
        # problems()


def register():
    registeragain = False
    user = input('Please register your username')
    passs = input('Please register your password')
    register = input('Do you want to register another account? Y/N')
        if register == 'Y':
            registeragain = True
        elif register == 'N':
            username()
        else:
            print("Error")
            # problems()

register()

I ran the problem and the error showed expected an indented block (, line 12)我运行了这个问题,错误显示预期有一个缩进块(第 12 行)

   else:
        # problems()3


def password():

The expected indented block error happens because you're supposed to have an indented block of code following an else: .发生expected indented block错误是因为您应该在else:之后有一个缩进的代码块。 Instead, you go directly from there to an unindent (starting a new function definition).相反,您 go 直接从那里取消缩进(开始一个新的 function 定义)。

If you put a pass statement under your else that will satisfy the requirement for there to be a block under it.如果您在else下放置一个pass语句,它将满足在它下面有一个块的要求。 Alternatively you could just remove the else since it's not doing anything.或者,您可以删除else ,因为它没有做任何事情。

You've declared an else statement at the end of each function without including anything to execute within the statement.您已经在每个 function 的末尾声明了一个 else 语句,而没有在语句中包含任何要执行的内容。 Else statements expect an indented block of code, hence the problem. Else 语句需要缩进的代码块,因此会出现问题。

If your intention is to do nothing in an 'else' block, use a 'pass' statement.如果您的意图是在“else”块中什么都不做,请使用“pass”语句。

else:
    pass
    # problems()

Instead of below, which is causing problems.而不是下面,这会导致问题。

 else:
     # problems()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM