In python write a program that computes and prints the average of the numbers in a text file. Because the numbers are read in from a text file, the number inputs are considered text. For example, there is the number 5 and there is a text 5. You can't do arithmetic operations on text. It must be converted to the number equivalent. You will make use of a few higher-order functions, map(), lambda and reduce(), to simplify the design. The basic outline of this program is as follows: Ask user for input file name and check to be sure it is valid Prepare input file for reading Get the numbers from the input file in to a list variable Convert the list variable string items to float numbers using the map and list functions Compute the sum of the numbers using the reduce and lambda functions Print the average of the numbers in the list. If the length of the list is zero then the average is zero
In python write a program that computes and prints the average of the numbers in a text file. Because the numbers are read in from a text file, the number inputs are considered text. For example, there is the number 5 and there is a text 5. You can't do arithmetic operations on text. It must be converted to the number equivalent. You will make use of a few higher-order functions, map(), lambda and reduce(), to simplify the design. The basic outline of this program is as follows: Ask user for input file name and check to be sure it is valid Prepare input file for reading Get the numbers from the input file in to a list variable Convert the list variable string items to float numbers using the map and list functions Compute the sum of the numbers using the reduce and lambda functions Print the average of the numbers in the list. If the length of the list is zero then the average is zero.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images