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
Assign a variable solveEquation with a function expression that has three parameters (x, y, and z) and returns the result of eva
larisa [96]

Answer:

<em>The programming language is not stated;</em>

<em>However, the program written in Python is as follows</em>

def solveEquation(x,y,z):

     result = z - y + 2 * x

     print(result)

x = float(input("x = "))

y = float(input("y = "))

z = float(input("z = "))

print(solveEquation(x,y,z))

Explanation:

This line defines the function solveEquation

def solveEquation(x,y,z):

This line calculates the expression in the question

     result = z - y + 2 * x

This line returns the result of the above expression

     print(result)

The next three lines prompts user for x, y and z

x = float(input("x = "))

y = float(input("y = "))

z = float(input("z = "))

This line prints the result of the expression

print(solveEquation(x,y,z))

3 0
2 years ago
How has the use of computers impacted business
Svetlanka [38]
It has allowed for better organization, faster communication, and more advanced actions that people can't complete
3 0
3 years ago
Read 2 more answers
Why can’t I see one individual’s questions in the app through their profile, but I can see their questions on the website?
Mumz [18]

Answer:

I think thats just a software issue. i have the same problem

Explanation:

7 0
3 years ago
Read 2 more answers
Jennifer has written a short story for children. What should be her last step before she submits the story for publication?
SSSSS [86.1K]

Answer:

What is the choice of being answer c?

6 0
3 years ago
Windows organises information on computer using a
zhuklara [117]
The correct answer is b folder
6 0
3 years ago
Read 2 more answers
Other questions:
  • What type of program would use to create a personal budget?
    14·1 answer
  • The overall purpose of a food guide is________.
    11·1 answer
  • Fill in the correct term to complete the statement. _____ refers to borrowing money from a bank.
    13·2 answers
  • A database interrogation is a major benefit of the database management approach, where end users can query (“ask”) the database
    6·1 answer
  • How do you convert a decimal to binary?
    9·2 answers
  • What is an example of how pseudo - randomness is used to creative variation​
    5·1 answer
  • What is the name for the type of flash memory that is used by mobile devices to store their apps and data?
    6·1 answer
  • The browser on which you are viewing web pages is called the
    13·1 answer
  • Websites can have good content for a particular set of search phrases, yet rank poorly. Issues that may cause this to occur incl
    9·1 answer
  • What kind of skill is persuasion?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!