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

Alan Gauld alan.gauld at btinternet.com
Sun Jul 22 10:35:26 CEST 2012


On 22/07/12 06:58, Santosh Kumar wrote:

> 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

Don't you want

        name = prompt?


> 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?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list