Search code examples
pythonfunctionpython-2.7raw-input

How to check raw_input answers inside if-statements


I'm sorry as this is probably a dumb question, but I'm just beginning to learn to code Python and I'm trying to make a game that checks certain inputs from the users. The script, however, is not accepting the correct answer and running the next function.

def left2():
    x = 5 + 5  


def left():
    x = raw_input("What is Dwyane's last name?")  
    x = x.lower # changes to the lowercase version of the name 

    if x == 'johnson':  # Code stopping here, It's not recognizing the input
        left2()
    elif x == "":
        left2()
    else:
        print "You're lost!" # This is displayed regardless of what I type

Solution

  • I think the issue is with the second line of left() which should read:

    x = x.lower() # changes to the lowercase version of the name 
    

    The parentheses call the lower method on x and reassign what that returns to x, rather than just setting x to the callable method itself.