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 is magma that contains little silica less likely to erupt explosively?
Can someone tell me the menstrual cycle :)
The Computer Store has reduced the price of a computer by 15%. What is the original price of the computer if the sale price is $1275?
Explain how you would find the base area of a rectangle prism if you know the volume and the height
What does it mean for a figure to be 3-D
Which of the following is NOT a part of the setting? A. TimeB. LocationC. MoodD. Sequence
Divide £300 in a ration of 3:7 help please !
The ratio of the side lengths of two regular hexagons is 3 to 7. If the area of the smaller hexagon is 18 square units, then the area of the larger hexagon is _
use long division to find the quotient, q(x), and remainder, r(x)(x2-2x-15) / (x-5)
DO you know a animal with the name that starts with the letter n?