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
Savatey [412]
4 years ago
15

Define a function below called average_num_in_file. The function takes one argument: the name of a file full of numbers. Complet

e the function so that it opens the file and returns the average of the numbers in the file. Here is an example input file from the static test case if you want to test from the interpreter: canned_file.txt
Computers and Technology
1 answer:
Nookie1986 [14]4 years ago
7 0

Answer:

  1. def average_num_in_file(fileName):
  2.    with open(fileName) as file:
  3.        rows = file.readlines()
  4.        sum = 0
  5.        count = 0
  6.        for x in rows:
  7.            sum += float(x)  
  8.            count += 1
  9.        average = sum / count  
  10.    return average  
  11. print(average_num_in_file("cans.txt"))

Explanation:

The solution code is written in Python 3.

Firstly create a function that take one parameter, fileName (Line 1).

Open the file stream and use readlines method to read the data from the file (Line 2-3). Create variable sum and count to tract the total of the number from text files and number of data from the file (Line 5-6). Use a for loop to loop over each row of the read data and add the current value of each row to sum and increment the count by one (Line 7-9).

After the loop, calculate the average (Line 11) and return the result (Line 12).

At last, we can test the function by passing the cans.txt as argument (Line 14).

You might be interested in
Which of these statements best compares P waves and S waves of an earthquake?
vlabodo [156]
Fam Try C.<span>S waves do not travel through molten rocks but P waves travel through molten rocks.</span>
3 0
3 years ago
Cloud-based services can open doors to leveraging Artificial Intelligence (AI) without dramatically increasing risk. Which clien
vladimir1956 [14]

Answer:

Explanation:

The clients that would be best suited for this opportunity would be small business or business' that do not have the hardware/space resources necessary to create the computing power that they need. Instead, they can simply pay for these cloud-based services which provide all of the necessary computing/hardware power and resources necessary so that the company can easily fulfill all of their tasks without any problems. Bigger companies can easily pay for and implement their own hardware to solve their problems which may benefit them even more in the long-term.

7 0
3 years ago
What factor determines a boat's required equipment??
Eddi Din [679]

Length of the boat is the factor that determines a boat's required equipment.

<span>Safety required equipment are the most important on the boat or vessel, and an operator of the boat must make sure that a boat has safety equipment. According to the length of the boat equipment are required, if the boat is large in length, it contains more equipment than the boat which is small in length.</span>

6 0
3 years ago
By default, what appears on your screen whenever a new email arrives?.
Troyanec [42]

By default, the appears on your screen whenever a new email arrives is a  Desktop Alert.

<h3>What is a Desktop Alert?</h3>

This is known to be a kind of  a notification that often shows on your desktop when a person is said to receive a new email message, a meeting request, or others.

Note that the Desktop Alerts need to be turned on by default and as such, By default, the appears on your screen whenever a new email arrives is a  Desktop Alert.

Learn more about Desktop from

brainly.com/question/7221406

#SPJ1

7 0
2 years ago
Any please answer this How much resistance is required to gen-erate 50 mA of current from a 5 volt bat-tery?
nasty-shy [4]

Answer:

Calculating Currents: Current in a Truck Battery and a Handheld Calculator ... (b) How long does it take 1.00 C of charge to flow through a handheld calculator if a 0.300-mA current is ...

7 0
3 years ago
Other questions:
  • Write a Bash script that searches all .c files in the current directory (and its subdirectories, recursively) for occurrences of
    14·1 answer
  • Excel allows you to rotate text in a cell counterclockwise by entering a number between -1 degrees and -90 degrees. True or fals
    14·1 answer
  • Counting calculus students. About A university offers 3 calculus classes: Math 2A, 2B and 2C. In both parts, you are given data
    6·1 answer
  • Find the names of these cities with temperature and condition whose condition is neither sunny nor cloudy.
    15·1 answer
  • How do u reverse image search on Android? ​
    9·1 answer
  • PLEASE HELP! Please dont answer if your going to guess
    14·2 answers
  • What are the ten application areas of computer?​
    10·1 answer
  • 1) The critical path of a network is the A) shortest time path through the network. B) path with the fewest activities. C) path
    14·1 answer
  • A _ is the acknowledgment of a potential noncomformity, or an opinion regarding an issue that is not covered by a standard
    6·1 answer
  • Television, the internet, and smartphones are different communication _______blank hsn uses in its imc.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!