0

I had to code this for my midterm in my programming class, this is just a small part of the code. keep in mind I'm really new to programming and this is an intro class to it.

we are learning 3.5 in class, and the code I wrote works fine in 3.5. however, I am starting to try and learn 2.7 and this code does not work on it:

print ("is student 1 here?")
attendence1 = input()
if attendence1 == "yes":
     student1 = "Y"
if attendence1 != (str("yes")):
student1 = ("N")

I'm just curious as to what the problem is between versions, and how 3.5 reads it vs how 2.7 does. I noticed that if I entered in my answer in 2.7 as a string, it would work, i.e: Q:is student 2 here? A: "yes" does not cause an error, how ever Q:is student 2 here? A Yes causes it to give me

attendence1 = input()
File "<string>", line 1, in <module>
NameError: name 'yes' is not defined

How would I make this code work on 2.7?

vaultah
  • 44,105
  • 12
  • 114
  • 143
  • use `raw_input` instead of `input` for `2.7` – inspectorG4dget Mar 09 '16 at 21:20
  • 1
    See http://stackoverflow.com/questions/4915361/whats-the-difference-between-raw-input-and-input-in-python3-x – Ben Mar 09 '16 at 21:20
  • Possible duplicate of [Python input() error - NameError: name '...' is not defined](http://stackoverflow.com/questions/21122540/python-input-error-nameerror-name-is-not-defined) – vaultah Sep 01 '16 at 05:28

1 Answers1

0
attendence1 = raw_input("is student 1 here?\n")
if attendence1 == "yes":
    student1 = "Y"
else:
    student1 = "N"

Need to use raw_input() instead of input. Also I think you wanted "N" not ("N")

quikst3r
  • 1,783
  • 1
  • 10
  • 15