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
To accomplish a certain task when you would rsther be doing something else is an example of
fenix001 [56]

Answer:

Self Discipline

Explanation:

his is because you train your brain to do the right thing.

I hope I helped. Thank you for your time.

6 0
3 years ago
Which group on the Note Master tab contains the command to add footers to the notes pages?
nasty-shy [4]

Answer:

Place Holders

Explanation:

5 0
3 years ago
How does a hard drive work
hammer [34]
Hi There!

<span>How does a hard drive work?

Hard Drive is for saving information </span>
7 0
3 years ago
What should a pwc operator do to minimize the risk of accident or injury?
Natasha_Volkova [10]
PWC stands fro personal water craft (aquascooter, jet bike, jet ski, wave runner, ski free, motorised surfboard etc.). The operator of PWC must be at least 16 years old.
In order to minimize the risk of accident or injury the PWC operator must follow several rules:
- the pwc operator should know the boating rules
- to monitor the speed of the vessel to ensure that a safe speed is being maintained.
- to adhere to the 5 knot rule (approximately 10kph) when close to shore, other boats (including boats at anchor) around dive flags and swimmers, fixed structures (ramps and jetties)
3 0
3 years ago
Need answer ASAP
Alinara [238K]

both software coding and testing occurs during Engineering phase

6 0
2 years ago
Other questions:
  • Some files appear dimmed in one of the default folders on your computer. What would be the best course of action? A. Leave the f
    11·1 answer
  • How long did it take Linkedln to reach 1 million users?
    5·2 answers
  • a paragraph is a segment of text with the same format that begins when you press the enter key and ends when you press enter key
    6·2 answers
  • How to get out of compatibility mode in word?
    15·1 answer
  • Which CSS attribute would change an element's font color to blue? font-color: blue; background: blue; color: blue; background-co
    10·2 answers
  • What operating system is an open source program
    15·1 answer
  • Radar devices are used by law enforcement to be sure that individuals are driving safely. They tell the officer how fast the veh
    12·1 answer
  • Which similar computer network components connect multiple devices?
    7·1 answer
  • How did Bill Gates benefit from free enterprise? Need a paragraph please. Will give the branliest!!
    9·1 answer
  • Why is it essential for every person living in the 21st century to have a computer​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!