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

3x-11x=3(12+12x)-10(3x-9)
Labor unions were first formed in the interest of protecting Child workers Auto Workers Weavers Only answer if you are 100% sure!!!!!!!!!!!!!!!!!!!!
The total cost for four people to bowl one game is $32.50. Each person paid $2.50 to rent their shoes, in addition to the cost of the game, c. Which of the foll
What is the third quar
what is the significance of the tropic of capricorn
what solutions did the new constitution include
How do people use bromine?
German philosopher and physicist Gustav Theodor Fechner founded psychophysics. True or False
Item 10 Find the median, first quartile, third quartile, and interquartile range of the data. 38,55,61,56,46,67,59,75,65,58 please !!!!!!!!!!!!!
When speakers use verbal cues what are they trying to achieve