Nicolegrove9449 Nicolegrove9449
  • 13-01-2021
  • Computers and Technology
contestada

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

Respuesta :

Buksmi
Buksmi Buksmi
  • 14-01-2021

Answer:import functools

# open your file

file = open("integers.txt", 'r')

file = file.read()

# put numbers into a list

file = file.split()

# convert list into integers

file = list(map(int, file))

# use lambda function to get average.

print(functools.reduce(lambda x, y: x+y / len(file), file, 0))

Explanation:

Answer Link

Otras preguntas

A square has a perimeter of 24cm. Work out its area.​
What is collaboration? (1 point)O working together with others on a shared ideaO a venue for asking questionsa process of working independentlyo communicating w
If the domino effect occurs as a result of changes in the money supply, what will most likely happen as an immediate result of interest rates being increased? B
15. For a random sample of n = 64, find the probability of a sample mean being less than 24.3 when p = 24 and o = 1.25.
Can somebody please tell me if it’s right? i’ll mark u the brainliest
What is the difference between sin^-1 and sin?
An array of solar panels produces 9.35 A of direct current at a potential difference of 195 V. The current flows into an inverter that produces a 60 Hz alternat
what would a an illegitimate government look like?
A commitment to the full development of one’s personality, talents, and potential is a. individualism. c. narcissism. b. self-fulfillment. d. internalization.
Find the quotient. (5x4 – 3x2 + 4) ÷ (x + 1)