[Tutor] Why isn't my simple if elif script not working?

Santosh Kumar sntshkmr60 at gmail.com
Sun Jul 22 07:58:11 CEST 2012


In first half of this script:

prompt = raw_input("Can you tell me your name? ")
if prompt in ("Yes", "yes", "y", "Y"):
    name = raw_input("What's your name? ")
elif prompt in ("No", "no", "n", "N"):
    exit("OK, have nice day..")
else:
    prompt = name

if name == "Santosh":
    print "Hey! I have the same name."
elif name in ("John Cleese", "Michael Palin"):
    print "I have no preference about your name. Really!!"
else:
    print "You have a nice name."

I want that if anyone enter their name at the first prompt the name
should be stored in "name" variable, or else if they enter anyone of
("Yes", "yes", "y", "Y") they should be given another prompt where
they can enter their name. But currently when I enter name other than
("Yes", "yes", "y", "Y") it says that name is not defined. How can I
fix this?


More information about the Tutor mailing list