0

I have been working on a project, and to test If/Elif/Else projects, I wrote a little bit of code to get an idea how it worked. I wrote:

opclo = input('>');
if(opclo == 'CLOSED'):
    print "Good night.";
elif(opclo == 'WACKED'):
    print "wacked";
else:
    print "Good morning.";

It gives me this error:

Traceback (most recent call last):
    File "python", line 2, in <module>
    File "<string>", line 1, in <module>
NameError: name 'CLOSED' is not defined

I am wondering why it does this. I have tried mutliple things, such as removing brackets, adding a opclo = opclo2 (making line 1's opclo into opclo2) and adding a array with "CLOSED" and "WACKED" in it. Any ideas?

Thanks.

tobias_k
  • 81,265
  • 12
  • 120
  • 179

2 Answers2

3

You are using Python2 so you need to use raw_input instead of input.

opclo = raw_input('>')
if opclo == 'CLOSED':
    print "Good night."
elif opclo == 'WACKED':
    print "wacked"
else:
    print "Good morning."
Daniel
  • 42,087
  • 4
  • 55
  • 81
0

tl;dr

input('>') - for python expressions

raw_input - for strings.

You should use raw_input

Igor Komar
  • 381
  • 1
  • 8
  • 16