Question: Ch 6 - P 9 . Exception Handling Modify the script Ch 6 / P 6 . py so it handles the following exceptions: It

Ch6-P9. Exception Handling
Modify the script Ch6/P6.py so it handles the following exceptions:
It should handle any IOError exceptions that are raised when the file is opened and data read from it.
It should handle any ValueError exceptions that are raised when the items that are read from the file are converted to a number.
create Ch6/P9.py
Ch6-P9. Exception Handling
Modify the script Ch6/P6.py so it handles the following exceptions:
It should handle any IOError exceptions that are raised when the file is opened and
data read from it.
It should handle any ValueError exceptions that are raised when the items that are read
from the file are converted to a number.
create Ch6/P9.py
submit two screenshots
GNU nano 4.8
P9.Py
r/%%/0sr/btn/python3
%P9
count =0
total =0
try:
infile = open("numbers.txt",'r')
for line in infile:
#print (line)
num = int (line)
count +=1
total += num
infile.close()
print ("The Average is", total/count)
except IOError:
print ("An I0 Error Occured")
except ValueError:
print ("Value Error")
except:
print ("Another type of Error")
Ch 6 - P 9 . Exception Handling Modify the script

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!