name = input(str('Please enter your name'))
names= ('name1','name2','nameetc')
if name in names:
print "hi",name
If I use this code and user inputs name1
, I get an error name1 is not defined
. If the user puts "name1"
in quotes then it works. I could ask the user to put the name in quotes, but then how do I check to ensure that it was before continuing. Preferably I would only have to ask for the name though. If I replace each str
in the list with an int the code works fine. How do I make it work with a str
in a list?