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

Which radioactive isotope is used in treating cancer? A) Carbon-14 B) Cobalt-60 C) Lead-206 D) Uranium-238
What is the main source for the basic teachings of Judaism
Jan van Eyck contributed to Renaissance art by
what to the second exponent is 64
Which organ is NOT correctly paired with its function? A.) Ovary- produces the eggs. B.) Penis- serve as the site of somen formation. C.) Testes- produces sper
How long after martin luther king, jr.'s death did the federal government adopt a holiday in his honor?
HURRY PLEEASE HEELPPP I WILL GIVE YOU ANYTHING BRAINIEST POINTS I WILL HELP YOU What is the value of x? Enter your answer x =
Is question 4 correct?
Compare and contrast the approach of the Black Panthers and Martin Luther King. Do you think black militancy in the 1960s helped or hurt the cause of civil righ
What type of microsoft server serves as an email server?