defined – Python- raw_input not working

defined – Python- raw_input not working

If you are using the new versions of python — 3.x.x — then raw_input no longer exists. Use input(prompt) instead. It works pretty much the same. basic Syntax:

foo = input(some prompt). 

What input does is it reads a line from the standard input file, or <stdin>. It prints the prompt within the () and then waits for user input. Example: (>>> is the command line prompt, <<< is output

Command Line, interactive mode (or IDLE): 
>>> foo = input(GIMME SOME INPUT: )  #tell it to take some input
<<<GIMME SOME INPUT: foo          # it prints out, GIMME SOME INPUT: user types in foo
>>> print(foo)
<<< foo

Response to your edit:

Use this:

print (CHOICE)
print (A.Gimme the gun!)
print (B.Fine)
choice = input(What do you choose?)
if choice == A or choice == a:
    #Some Action 
if choice == B or choice == b: 
    #Some Other Action  

You appear to be using Python 3. In Python 3, raw_input() has been renamed to input().

defined – Python- raw_input not working

Re your new question:

But now I dont get a choice it forces me to choose a and then after that it forces me to choose b

Thats because youre calling input() twice, and each time you call it, youre prompted to type something. You want to call it once, store the value you get in a variable, and compare that variable to the possible choices.

Leave a Reply

Your email address will not be published. Required fields are marked *