# File: except1.py # Program to read in a positive number # and complain when the input isn't that # # Matt Bishop, MHI 289I, Fall 2022 # # loop to show exception handling # while True: # read in a positive integer # handle any exceptions (relatively) intelligently try: n = int(input("type a number: ")) # exception: end of file, so quit except EOFError: break # exception: anything else except: print("Ignoring exception") # ignore the problem continue # no exception -- print the number if n <= 0: print("You typed a non-positive number") else: print("Read", n) print("\n-----------------------\n")