Answer to Question #174259 in Python for Paul Carpenter

Question #174259

Describe how catching exceptions can help with file errors. Write three Python examples that actually generate file errors on your computer and catch the errors with try: except: blocks. Include the code and output for each example in your post. 

Describe how you might deal with each error if you were writing a large production program. These descriptions should be general ideas in English, not actual Python code. 


1
Expert's answer
2021-03-22T08:22:07-0400
#1
#Code:
try:
    a = 1/0
    print(a)
except ZeroDivisionError:
    print("Zero!")

#2
#Code:
try:
    a = []
    print(a[1])
except IndexError:
    print("Index error")

#3
#Code:
try:
    A = 42
    A = A + ' 4 '
except TypeError:
    print('Wrong type')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS