-1

I am having a problem with the following code. This is supposed to be the beginning of a small text based game. I want to take the users input and then output a message (such as a help menu, or the start of the game).

def start (): # This runs when the program starts 
    print("THE LAST RANGER")
    print ("Type Start to Begin")
    print ("Type About for Credits")
    print ("Type Help for Instructions")
    prompt_start()

def Waking_up(): # This should run when the user enters "Start"
    print ("SIR... Sir. We need to get you out of here, come on.")

def About(): #This should run when the user enters "About"
    print ("Welcome to THE LAST RANGER created by Michael Frazer.")
    #add more to this at some point

def Help(): #This should run when the user enters "Help"
    print ("This is the help menu")

def prompt_start(): #This function takes the users input
    global input_0
    input_0 = input()

start () #This runs the "start" function defined in the first lines       

if input_0 == "Start" or "start": #These should evaluate the users input
    Waking_up ()
elif input_0 == "About" or "about":
    About ()
elif input_0 == "Help" or "help":
    Help ()
else:
    print ("Enter Valid Command")

My problem is that the input variable is being evaluated as literally anything. For example the line

if input_0 == "Start" or "start": #These should evaluate the users input
    Waking_up () 

Runs the "Waking_up" function even when the input is not equal to "Start". If the user enters something like "Help", the program seems to think that "Help" is equal to "Start" and runs the waking up function. I've tried to debug this with 3 friends and we are all out of ideas. Thanks for any help.

  • 1
    Possible duplicate of [How do I test one variable against multiple values?](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values) – Morgan Thrapp Nov 25 '15 at 18:42

2 Answers2

1

"start" is evaluating to true because you don't have the full expression. Try:

if input_0 == "Start" or input_0 == "start": #These should evaluate the users input
    Waking_up ()
Ryan
  • 2,058
  • 1
  • 15
  • 29
0

Just change the following:

if input_0 == "Start" or input_0 == "start":
    Waking_up ()
elif input_0 == "About" or input_0 =="about":
    About ()
elif input_0 == "Help" or input_0 == "help":
    Help ()
else:
    print ("Enter Valid Command")

This will work as you want and will only evaluate the corresponding input(s) instead of "Start" all the time.

Depending on what you're doing with the program, consider filtering the user's input as well (such as converting the input string to .lower() and only have your if/elif/else commands accept lowercase input -- may save you some time. Just a suggestion from a fellow python newbie.

Sludge
  • 6,072
  • 5
  • 31
  • 43