0

I have a problem with this piece of code. Somehow if we put in 'register' or 'Register' as input, it goes to the register function, but after it prints the else: Aswell ("Bad input"); I have made more of these but cant find the fault in this one.

Please help me. Thanks! Here's my code:

def Boot(): 
        print "Type 'Login' + accountname to login."

        x = raw_input("> ")
        Name = x.split()

        if x == "Register" or x == "register":
            print "Registerbla"

        if Name[0] == "Login" or Name[0] == "login":
            print "Loginblabla"
        else:
            print "Bad input"

So what I see after input is: Registerbla Bad input

2
  • 5
    I think you want "elif Name..." instead of "if Name..." Commented Feb 20, 2013 at 13:59
  • 1
    In editing your post, I notice that you have spaces and tabs in your source. I hope that's just from trying to get it to display properly in stack overflow's renderer -- However, if it isn't, that's a particularly bad thing in python code. You can always run python with python -t script.py to find out if you're mixing spaces and tabs in a bad way. Commented Feb 20, 2013 at 13:59

2 Answers 2

2

You're missing the else portion of your if statement. Without it, you actually check two separate if statements: the register section and the login/bad input section. Instead, you should use elif:

    if x == "Register" or x == "register":
        print "Registerbla"
    elif Name[0] == "Login" or Name[0] == "login":
        print "Loginblabla"
    else:
        print "Bad input"

Also, consider changing your statements to check against lowercase, like

if x.lower() == "register":
    # Now any capitalized variant of register will work!
Sign up to request clarification or add additional context in comments.

Comments

1

when you type in register or Register

if Name[0] == "Login" or Name[0] == "login":

evaluates to false, printing Bad input

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.