"""File: read_int.py Purpose: Illustrate exception handling. Run: python read_int.py Input: A sequence of lines of characters. The last should consist of a single int. Output: Prompts and error messages, until an int is entered. Then the int is printed. """ def read_int(prompt): """Print prompt and read in an int. Print error message if input is incorrect and try again.""" done = False while not done: try: x = int(raw_input(prompt + "\n ")) done = True except: print "Sorry. Please try again" print return x if __name__ == "__main__": x = read_int("Enter an int") print "We read", x