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]
3 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]3 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
Question 5 of 10
Ostrovityanka [42]
Hello!

Answer:
B. Analyze data from the car’s external cameras.

I hope that this helps you!
3 0
2 years ago
Which option will Joan use to get a glimpse of how her presentation will look when she presents it to her audience? Joan will us
Murrr4er [49]

Since Joan wants to see what her presentation would look like in the eyes of her audience, it might be best for her to use the Slideshow view that is available at the bottom right side of her desktop view.

This option is a full-screen form of her Normal view in Microsoft PowerPoint. The Slideshow view is represented by the projector screen symbol next to the zoom in and out bar.

7 0
2 years ago
Read 2 more answers
The open items on your computer are displayed here.
koban [17]
The GUI or Graphical <u /><u></u><em />User Interface.
7 0
2 years ago
The process of using the new
IRINA_888 [86]

Answer:

The process of using the new

information system and doing away

with the old system is known as

system <u>development</u>

7 0
2 years ago
Need help coding this it uses input and I need to use the words good and morning
Masja [62]

Answer:

x = input ("Enter a word: ")

y = input ("Enter a word: ")

print ( x, " ", y)

Explanation:

This is the simplest way to write it using Python.

6 0
2 years ago
Other questions:
  • True or false: a cover letter accompanies a resume to showcase a job-seeker’s personal life
    6·2 answers
  • Which steps would you take to determine how much an employee should be paid? Select all that apply.
    9·1 answer
  • Which printer are used to print text and graphics with high speed ​
    15·1 answer
  • Discuss briefly four types of websites and the criteria you will use to evaluate the content of a website
    8·1 answer
  • An ALGORITHM IS?<br> PLEASE HELP
    14·1 answer
  • HW2.24. Statement: Area of a Triangle The area of a triangle can be computed by knowing the base and height of the triangle usin
    11·1 answer
  • Write a loop that continually asks the user what pets the user has until the user enters rock in which case the loop ends. It sh
    6·1 answer
  • Aii so is anyone pushing P?<br> if u are u a g
    8·2 answers
  • Compare the freedom available to the American media with the freedom available to media in other parts of the world. How does a
    8·1 answer
  • If I want to make it look like slide number one is turning a page to slide number two, what
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!