[Tutor] Help

Steven D'Aprano steve at pearwood.info
Tue May 15 21:43:10 EDT 2018


On Tue, May 15, 2018 at 08:01:13PM -0500, boB Stepp wrote:
> On Tue, May 15, 2018 at 7:51 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> 
> > You also seem to be using Python 2. In Python 2, you should never use
> > the input() function. Instead, use raw_input() instead.
> 
> What are you seeing that suggests the OP is using Python 2?  I am
> missing what you are seeing/understanding.

Excellent question :-)

The traceback Sam posted says (in part):

  Move = input('What Will You Do? Fight or Run: ')
  File "<string>", line 1, in <module>
  NameError: name 'Run' is not defined

so the failed line was the call to input(). In Python 3, it would return 
a string. In Python 2, input() evaluates whatever the user types as 
code, hence I infer Sam typed:

    Run

and input() tries to evaluate it, which fails.

Also, the following line says:

        if Move == Fight:
            pass

If input() returned a string, as in Python 3, then the next line would 
run and Sam would have got a name error for Fight. This didn't happen.



-- 
Steve


More information about the Tutor mailing list