0

Ok here it is

  done = False
  while not done:
      quit = input ("Do you want to quit? ")
      if quit == "y" :
         done = True;

      if not done:
       attack = input ("Does your elf attack the dragon? ")
       if attack == "y":
          print ("Bad choice, you died.")
          done = True;

but when I get to

           Do you want to quit?

And I enter

       n

I get

       Traceback (most recent call last):
         File "C:\Users\your pc\Desktop\JQuery\dragon.py", line 4, in <module>
           quit = input ("Do you want to quit? ")
         File "<string>", line 1, in <module>
        NameError: name 'n' is not defined

according to this http://www.youtube.com/watch?feature=player_embedded&v=2Z2pH0Ls9Ew#! it should work

1
  • 1
    Try raw_input() instead. Commented May 2, 2013 at 16:27

1 Answer 1

2

input behaves differently in version 2 and 3 of Python. You're clearly on Python 2, because it tries to interpret the input in the Python environment.

You will want raw_input() instead, which simply reads in a string.

Edit: To make the difference clear, in Python 2:

>>> type(input())
0
<type 'int'>
>>> type(raw_input())
0
<type 'str'>

In Python 3:

>>> type(input())
0
<class 'str'>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.