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

At a restaurant after every 12th visit you receive a free drink. After every 15th visit you receive a free dessert. At which visit will you first receive a free
what is the factor expression for 3p+18 answer?
How do Americans exercise popular sovereignty? a) by serving on juries b) by voting for representatives c) through checks and balances d) by revising the Consti
what is 9/10 minus 1/3
What route did Ferdinand Magellan's ships take to circumnavigate the globe?
describe a model that represents 3/3 x 4/4?
how did trade with Arabs affect the development of African kingdoms
Support the idea that genetic testing and engineering could have dangerous consequences for society.
find three consecutive integers whose sum is 468
Which term is used to describe what causes organisms to react to their environment? A. Stimulus B. Camouflage C. Parasites D. homeostasis