I once created a function to do that:
def yorn(question = "[y/n]", strict = True):
"""yorn([question][, strict]) -> user input
Asks the question specified and if the user input is 'yes' or 'y',
returns 'yes'. If the user input is 'no' or 'n', it returns no. If
strict is False, many other answers will be acceptable."""
question = question.strip(" ")
x = raw_input("%s " % question)
x = x.lower()
if (x == "yes") or (x == "y") or ((not strict) and ((x == "yep") or (x == "yeah") or (x == "of course") or (x == "sure") or (x == "definitely") or (x == "certainly") or (x == "uh huh") or (x == "okay") or (x == "ok"))):
return True
elif (x == "no") or (x == "n") or (not strict and x in ["nope", "uh uh", "no way", "definitely not", "certainly not", "nah", "of course not"]):
return False
else:
return yorn(strict = strict)
To use it, make your program something like this:
again = True
while again:
name = raw_input("Whats your name?: ")
age = raw_input("How old are you?: ")
if age.isdigit() and int(age) > 15:
print "Congradulations you can drive!"
elif age.isdigit() and int(age) < 16:
print "Sorry you can not drive yet :("
else:
print "Enter a valid number"
print ("it's been very nice getting to know you " + name)
print ("")
again = yorn("Would you like to try again? ", strict=False)