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

A direct variation function contains the points (–8, –6) and (12, 9). Which equation represents the function?
giving two or more patients the same appointment slot with the same provider is called
Use the graph below which shows the number of cans of juice three sixth grade classes drank in each class what fraction of the cans were orange juice
When were the bill of rights added to the constitution?
How can you use your answer to B to find the amount of distilled water to add to a given amount of ammonia?
If set D is not the empty set but is a subset of set E, then which of the following is true? D ∩ E = D D ∩ E = E D ∩ E = ∅
The color red has the longest wavelengths of any color. According to the _________, that which has longer wavelengths is ____________. This supports the big ban
what is 21over28 can someone help me
what expression is the same as 0.5÷0.10 and equals
If all of the logical conditions are true, the and function returns the logical value _____.