Conditional statement syntax issues


#1

Hi, I also have an issue with the exercise.
The script shows:

response = 

answer = "Left"
if answer == "Left":
    print "This is the Verbal Abuse Room, you heap of parrot droppings!"
    
# Will the above print statement print to the console?
# Set response to 'Y' if you think so, and 'N' if you think not.

And the exercise is:
If you think the print statement will print to the console, set response equal to 'Y'; otherwise, set response equal to 'N'.

I have tried writting Y "response = Y", and N "response = N", but I always obtain this error:

Traceback (most recent call last):
File "python", line 1, in
NameError: name 'Y' is not defined


Conditional statement syntax
#2

It says, Set Response = "Y" or "N". Do what it tells you to.


#3

response = "Y"

There is no defined variable, Y, which is why the error. It needs to be a string primitive.


#4

I'm not sure why but worked when I written True...


#5

Um, what is a "string primitive"?


#6

Anything written literally and in quotes is a string primitive. There are three main primitives:

  1. a raw number
  2. a raw string
  3. a raw Boolean

I'm not sure how Python treats primitives, but JavaScript gives then wrapper objects of the class that best fits. "string primitive" gets a String class, 42 gets a Number class, true and false get a Boolean class. null is also a primitive.

Primitives themselves are not objects so to be usable in object based code, they need to be made into objects, hence the wrapper.


#8