1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MatroZZZ [7]
3 years ago
15

Modify the program you wrote for Chapter 6 Exercise 6 so it handles the following

Computers and Technology
1 answer:
Basile [38]3 years ago
6 0

Answer:

#try except

try:

   #opening the file

   read_file = open('numbers.txt', 'r')

   #Store the numbers in the variable file_numbers.

   file_numbers = read_file.read()

   #close the file

   read_file.close()

   #Split the number of files in list_values.

   list_values = file_numbers.split()

   #how many numbers are there

   list_length = len(list_values)

   try:

       #loop it up

       for i in range(list_length):

           list_values[i] = float(list_values[i])

       #Add up all the numbers, put into list_sum

       List_sum = sum(list_values)

       #heres how we average it

       Average_value = (List_sum)/list_length

       #print

       print(Average_value)

   except ValueError:

       print( "File must have only numbers. Try again." )

   #handles IOError exceptions

except IOError:

   #Display statement

   print("Trouble opening file. Try again.")

Explanation:

The python program uses the try-except exception handling method to catch errors in the code. The IOError is used for catching input and output errors in the program like file handling while the ValueError keyword in the except statement is used to catch data type errors from a return statement, calculation or user input.

You might be interested in
C programming:
mixas84 [53]
IsTeenager = ( ( kidAge >= 13 ) && ( kidAge <= 19 ) ) ? true : false;

Another way:

if( ( kidAge >= 13 ) && ( kidAge <= 19 ) )
  isTeenager = true;
else
   isTeenager = false;
8 0
3 years ago
Anybody wants to join my pad let to talk about video games
Rus_ich [418]

Answer:

im in

Explanation:

8 0
3 years ago
Read 2 more answers
To drive defensively, you should _______________.
Keith_Richards [23]
The answer is B, look ahead and keep your eyes moving
7 0
3 years ago
Consider the steps for debugging. First, you should
SCORPION-xisa [38]

Answer:

run the code to see where the error is

Explanation:

4 0
3 years ago
If you were going to construct a table that only included shapes name with number prefixes, which shape would you inlcude?
Annette [7]

Answer: Triangle

Explanation: Triangle has Tri

8 0
3 years ago
Other questions:
  • The amount of interest you will earn in one year from a savings account is the _____. A) APY B) return C) IDA D) CD
    12·2 answers
  • The concept of ____ refers to the idea that the internet is designed for all content to be treated equally.
    12·1 answer
  • Selecting the option to control Widows and Orphans will prevent _________. A single line from appearing at the top or bottom of
    10·1 answer
  • What is the autocad term for standard section line symbols?
    13·1 answer
  • What kind of energy transformation occurs in a gasoline-powered car?
    14·1 answer
  • Write a CPP Program to read an integer number. Use a pointer to display this numbe
    5·1 answer
  • Benefits of computer in bank​
    5·1 answer
  • I'd: 9872093250, password: qqqqq, join the meeting​
    11·1 answer
  • Where ....................... the books that you borrowed? *
    5·1 answer
  • Tasks you can perform online include which of the following?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!