answer.
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
sertanlavr [38]
1 year ago
9

Write a program that computes and prints the average of the numbers in a text file. You should make use of two higher-order func

tions to simplify the design.
An example of the program input and output is shown below:




Enter the input file name: numbers.txt




The average is 69.83333333333333



______________________________________




Filename: numbers.txt




45 66 88



100 22 98
Computers and Technology
1 answer:
KengaRu [80]1 year ago
6 0

Answer:

Following is the program code as required.

Comments are given inside the code.

Explanation:

(=> Defining the main function)

def main():

(=> Getting input from user)

file = input("What is name of file?")

(=>Storing text from file in variable data )

data = open(file, "r")

(=> read the file and then split it)

info = data.read().split()

(=> Generating array named numbers)

numbers = []

for line in info:

(=>numbers will be appended from in format to list format)

numbers.append(int(line))

data.close()

(=> Average will be found by dividing sum of numbers to length of array)

avg = float(sum(numbers))/len(numbers)

(=> Printing calculation of average)

print("Calculated average is",avg)

main()

<h2>i hope it will help you!</h2>
You might be interested in
Jenny needs to record the names of 30 students, write down the subjects they studied, and note their grades in each subject afte
Marina86 [1]
The correct answer for this question is this one: "She can rename the 2 worksheet by right clicking the sheet tab. After right clicking the mouse, select Rename Sheet and type the preferred name of the sheet."  Hope this helps answer your question and have a nice day ahead.
5 0
2 years ago
Read 2 more answers
Isabella's manager has asked her to write up a _____ that describes their company's interest in developing a custom software sol
kakasveta [241]

Answer:

Request for information (RFI)

Explanation:

Request for Information is a business process document that contains information about an organization's capability to deliver solutions to a potential client. The RFI document will contain information that will help for decision making by clients. Other similar business documents in this line are Request for tender (RFT), request for quotation (RFQ).

6 0
1 year ago
Maurice has just purchased his first computer, which contains a preinstalled suite of basic software applications. He receives a
Oksanka [162]
This file will most likely _____.

A. convert itself into a different file type that his computer will recognize with one of its preinstalled software applications
5 0
2 years ago
Read 2 more answers
One factor affecting digital camera quality is the number of pixels, measured in ____, used to store the data for each image.
Vlada [557]
One factor affecting digital camera quality is the number of pixels, measured in megapixels, use to store the data for each image.
5 0
2 years ago
Read 2 more answers
Assume that a function named swapdoubles has been defined and is available for use in this exercise: that function receives two
Nata [24]

Answer:

C++ Code:

void sort3(double &a, double &b, double &c)

{

   if(a > b)

       swapdoubles(a,b);

   if (b > c)

       swapdoubles(b,c);

   if (a > b)

       swapdoubles(a,b);

}

Explanation:

To change the values of a,b,c within the function, we pass the values by reference. Let us assume that number a = 3.14, b = 2.71, c = 3.04. Since a > b, values of a and b will be swapped.Now a = 2.71 and b = 3.14. Similariy, since b > c, they will be swapped. This way, we move the largest number to its correct position in the first two steps. If there are only three numbers, and the largest number is in its correct position, then for the two remaining numbers, we will only need atmost one swap to exchange their positions. hence, we perform a comparison of a > b once again to see if the b is smaller than a. if its not, then all a,b,c are in sorted order.

6 0
2 years ago
Other questions:
  • What is one effective way for employees to keep their skillsets current?
    8·2 answers
  • Greg is writing a report on becoming an advertising and promotions manager. Complete the report by correctly filling in the miss
    12·1 answer
  • Suppose your company has decided that it needs to make certain busy servers faster. Processes in the workload spend 60% of their
    5·1 answer
  • Given an integer variable strawsOnCamel, write a statement that uses the auto-increment operator to increase the value of that v
    12·1 answer
  • Describe different types of intrusions such as SQL PL/SQL, XML, and other injections.
    5·1 answer
  • A queueing system has four crews with three members each. The number of "servers" is:
    5·2 answers
  • At one college, the tuition for a full-time student is $8,000 per semester. It has been announced that the tuition will increase
    13·1 answer
  • Write the definition of a class Telephone. The class has no constructors, one instance variable of type String called number, an
    9·1 answer
  • Clara writes online articles based on world religions. Her articles have references to dates. Which HTML element will help her d
    12·1 answer
  • The height of a small rocket y can be calculated as a function of time after blastoff with the following piecewise function: y 5
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!