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

Why did thoreau come to the conclusion that the state was half-witted when it imprisoned him?
3/4 x 3 2/3 in simplest form
An evangelical sunday school teacher and a rabbi who live in the same neighborhood might have different political opinions due to what major demographic factor?
The central dogma of molecular biology is an explanation of the flow of genetic information within a biological system. It is a framework for understanding the
How did british and native american alliances contribute to the move toward war?
Which figure of speech is the following line from the poem “A Red, Red Rose” by Robert Burns an example of? O My Luve’s like a red, red rose A.onomatopoeia
Pitch describes the loudness of a sound. True False?
Many of the new tax collectors were incompetent; some were actually ___. A. trustworthy B. honest C. dishonest D. hardworking E. kind
The european explorers who followed columbus to north america
How does Céleste explain the murder and what happened? a. He thinks it is just bad luck. b. He says that the Arab had it coming. c. He cannot believe his friend