This is often done using the loop-and-half construction with breakin the middle:
while True:
title_selection = raw_input("Please type in the number of your title and press Enter.\n%s" % (raw_input_string))
if title_selection:
break
print "Sorry, you have to enter something."
This method gives you the option to print a message about what the program expects.
source
share