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

The distributive property can be applied to Whitehall expression to factor 12x^3-9x^2+4x-3
In general, why does a tall person have a higher basal metabolic rate than a shorter person of the same weight? a. Shorter people have more skin surface area an
strategies that encourage to buy products include ___.
Ok this is the one I need help on!
Solve the exponential equation. (½)x = 32
Which of the following would be considered a limited resource in the lower depths of the ocean? a. water b. sunlight c. prey d. predators
What is the chemical name of the compound K2SO4?
Twenty switches in an office computer network are to be connected so that each switch has a direct connection to exactly three other switches. How many connecti
Simplify square root 18
ANSWER QUICKLY PLEASE!!!! 30 POINTS!!!!