# File: badger3.py # # Keep asking the user to type in a number # until the user types in a valid number. # # This version handles unknown exceptions, # including when the user types ctrl-C. # done = False while not done: try: # get input string and convert to integer # userInput = input("Enter a number: ") n = int(userInput) except ValueError: # exception triggered for input not a valid # integer # print("That's not an integer! Try again.") except EOFError: # exception triggered if user types ctrl-D # print("Please type something! Try again.") except BaseException: # unknown error... just quit. # try typing in ctrl-C print("Unknown error encountered!") exit() else: # no exceptions found. Can quit now. # print("Thank you!") done = True print("n is ", n)