Bummer! This is just a preview. You need to be signed in with an account to view the entire instruction.

Well done!

You have completed (UPI) Chapter 16: Working with Files in Python!

Instruction

Try and except

Programs can be designed to handle exceptions, rather than terminate. A try statement runs code that might raise an exception. An except clause runs code in response to the exception. Example: Try to open a file The following program, named try_open.py, asks the user for a filename and counts the number of lines in the file. name = input("Enter a filename: ") try: file = open(name) l...