Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Intro to python Chapter 6 Solution read_file = open('numbers.txt', 'r') file_numbers = read_file.read() read_file.close() list_values = file_numbers.split() list_length = len(list_values) for i in range(list_length): list_values[i]

Intro to python

Chapter 6 Solution

read_file = open('numbers.txt', 'r') file_numbers = read_file.read() read_file.close() list_values = file_numbers.split() list_length = len(list_values)

for i in range(list_length): list_values[i] = float(list_values[i])

List_sum = sum(list_values)

Average_value = (List_sum)/list_length

print(Average_value)

Problem:

Modify the program you wrote for Chapter 6 Exercise 6 so it handles the following exceptions: It should handle IOError exceptions that are raised when the file is opened and data is read from it by printing "Trouble opening file. Try again." and not executing any more of the code. It should handle any ValueError exceptions that are raised when the items that are read from the file are converted to a number by printing "File must have only numbers. Try again." and not executing any more of the code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

evaluate the quality of your data;

Answered: 1 week ago

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago

Question

7. Determine what feedback is provided to employees.

Answered: 1 week ago