This program will read integers from a file and find results from these integers. Open the file, test to make sure the file opened. Use a loop to read the integers and process each integer as it is read. When End Of File is reached, close the file. After all of the integers have been read and processed, print the results for the following output: The integer count: The sum of the integers: The smallest integer: The largest integer: The average of the integers: Use notepad, vim, or other simple text editor to create a file named file1.txt containing the following, with one integer per line. Test the program two times. Use the following data in the first test: 11 9 18 22 27 33 21 For the second test add an additional line containing the number 40.
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
with open('file') as file:
numbers = []
for line in file:
numbers.append([int(x) for i in line.split()])
print('integer count:', len(numbers))
print('sum of the numbers:', sum(numbers))
print('smallest integer:', min(numbers))
print('largest integer:', max(numbers))
print('avarage value:', sum(numbers) / len(numbers))