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
why do networking components need more examination from an information security perspective than from a systems development pers
padilas [110]
Networking components will eventually interact with computers and devices outside of itself. Whereas during system development you are only interacting with your program internally.

For example, when you first work on a website you can begin working on it on your personal computer not connected to the outside world. When you are done working on your website you will now upload it to a webserver (or you will create your webserver) and now you are opening up the doors so to speak to the Internet. When you "open the door" you need to make sure the proper security is in place so that no one hacks your site. This is ussually done by making sure the webserver you are on does not have any known security vulnerbilities and has the proper firewall settings to prevent unauthorized access.
4 0
3 years ago
A public Wi-Fi risk that can be minimized by only visiting
lord [1]

Answer

it is B

Explanation:

because i had the test and i picked that

6 0
3 years ago
Consider the latency model for static congestion windows. If the server receives an acknowledgement for the first data segment i
Angelina_Jolie [31]

Answer:

Latency of an object O is shown below.

Explanation:

W segment and stalled state transmits nothing and waits for acknowledgement. The latency is 2 R TT + the time required for server that are using to transmit the object + the amount of time when server is in stalled state. Let K be the number of window that is K= O/WS .The serveries stalled state where K-1 is period of ime with period lasting RTT-(W-1)S/R

latency = 2RTT +O/R +(K-1)[S/R +RTT - WS/R]

After combining the two case

latency = 2 RTT + O/R + (K-1)[S/R +RTT - WS/R]

where [x] means maximum of (x.0). This is the complete ananlysis of the static windows.

server time for transmit the object is (K-1)[S/R +RTT - WS/R]

7 0
3 years ago
In 3–5 sentences, describe how technology helps business professionals to be more efficient.
Vsevolod [243]

Technology helps business professionals, keep more organized, communicate better, and effectively keeps businesses secure. Technology helps keep employee information and business paper work more organized using computers and software; while making it easier to communicate with employee's using e-mail and memo's.

if wrong sry :(

3 0
3 years ago
Read 2 more answers
HELP!!! What would var d=?
sergiy2304 [10]

Answer:

51015

Explanation:

Var b is a string, and it'll treat addition like <em>string concatenation </em>(aka just adding a message.) Since it's concatenation, it'll then turn the numbers/integers into strings.

This kind of behavior might be different depending on the language, though. Some languages might not allow this. (For example, C and C++)

7 0
3 years ago
Other questions:
  • Which of the following is an occupation management group? Select the choice that best answers the question.
    15·1 answer
  • A collection of coordinating colors that can be used in an Excel document is called a color
    8·1 answer
  • David owns a retail business that just implemented a web app to supplement sales. He needs to choose an attribution partner to i
    15·1 answer
  • Edhesive coding practice 3.4​
    13·2 answers
  • What can help an interface user understand or navigate an online interface?​
    15·1 answer
  • Describe the importance of human interaction in a computing system.
    14·2 answers
  • Python will ignore any line of code that begins with hashtag true or false​
    13·2 answers
  • Pie charts are best used for
    5·1 answer
  • If you want to share information with individuals who are internal to your organization, which type of network would you want to
    6·1 answer
  • What to do if you click on a phishing link on iphone
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!