Hello All,

Okay, I have created a small function that will check to see if a user
has answered with a Yes, No or other response.  If the user puts yes
or no the function ends, if they put anything but yes or no then the
function will ask them the same question and tell them they either
need to put yes or no for their response

This is what I have as of now:
### Start of Code ###
def question_y_n(question):
    answer = input(question)
    while(answer != "Yes"):
        if answer != "No":
            print("Please enter Yes or No for your response!")
            answer = input(question)
        else:
            answer = "No"
            break
    return answer

answer = question_y_n("You want a drink of water? :")
print("Your answer to the question was ", answer)
### End of Code ###

Is this the best way to handle this?  I would like to use this any
time I have a yes or no question. In the future I will add to this and
make it work with yes/no, true/false, 1/0 so that anytime there is
anything that only has two answer I could use this instead of writing
more code for each two answer type questions.

Thank you for your advice ahead of time!!!

PS: I hope don't mind me posting code that works to see if I can improve on it!

Sincerely in Christ,
Christopher
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to