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

AREAS AND VOLUMES OF SIMILAR SOLIDS URGENT?
identify the unit rate in the graph im sorry I accidentally put history but its mathematics
what is 300+-50+-75+225
Two ways in which HIV/AIDS is spread through transactional sex and thus become socially unjust to the victim
Andrew's family is going on vacation across the United States. They traveled 515 miles every day for 17 days. How many miles did they travel in all?*Please Show
Frank and gina are looking at an abstract painting in a museum. gina describes objects and people she thinks she sees int he painting. frank says, "it's a bunch
Consider five independently assorting gene pairs, a/a, b/b, c/c, d/d and e/e, where each demonstrates complete dominance (a_, b_, c_, d_, and e_) and recessiven
How much would 7 oranges cost at $2.49 per dozen? (don’t include tax) A: $1.45 B: $0.21 C: $1.47 D: $4.27
GEOMETRIC PROBABILITY URGENT?
Which lslamic empire controlled territory in Europe during the early modern era?