Question
You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The
You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following:
The name of the file.
The sum of the numbers.
The count of how many numbers are in the file.
The average of the numbers. The average is the sum of the numbers divided by how many there are.
The maximum value.
The minimum value.
The range of the values. The range is the maximum value minus the minimum value.
the median of the numbers
The mode of the numbers.
The output from the program is to display the information described above using the following strings preceding the values. There is to be a space between the colon and the value.
File name: Sum: Count: Average: Maximum: Minimum: Range: Median: Mode:
At the end of one attempt at reading, or a successful read, of a file the user it to be asked if they would like to evaluate another file of numbers. Use the prompt: Would you like to evaluate another file? (y/n) If the user answers y, then the program is to accept input for another file name. If the user answers with anything other than y, the program is to exit.
The program you write must be able to handle four different circumstances for the file that contains the number data:
The count of the numbers in the file being even.
The count of the numbers in the file being odd.
The file containing only one number.
The file containing no numbers. (An empty file.) The user is to be told that no numbers could be found in the file.
The file containing an even or odd count of numbers is an issue when calculating the median which is discussed below in the Useful Information section.
Testing
Once you have written your program you need to test it. Four test files containing data are supplied in a file attached to the assignment called numbers.zip. You must unzip the file to get the files numbers.txt, numbers2.txt, numbers3.txt and numbers4.txt.
numbers.txt-
728 44 591 586 660 852 554 419 451 698 947 660 170 396 627 975 748 13 373 881 112 266 500 476 951 433 409 786 592 251 324 930 148 785 101 929 583 505 487 175 995 875 913 620 444 806 259 8 893 637 635 238 140 989 476 438 835 641 650 904 268 798 464 716 918 377 332 691 981 370 747 217 668 777 475 322 362 540 209 300 884 245 375 400 915 331 765 522 222 849 907 461 507 976 575 671 755 901 263 542
numbers2.txt
728 44 591 586 660 852 554 419 451 698 947 660 170 396 627 975 748 13 373 881 112 266 500 476 951 433 409 786 592 251 324 930 148 785 101 929 583 505 487 175 995 875 913 620 444 806 259 8 893 637 635 238 140 989 476 438 835 641 650 904 268 798 464 716 918 377 332 691 981 370 747 217 668 777 475 322 362 540 209 300 884 245 375 400 915 331 765 522 222 849 907 461 507 976 575 671 755 901 263
numbers3.txt
210
numbers4.txt
blank
Output
For the provided numbers.txt file the following are the values your program should generate:
Sum: 56110 Count: 100 Average: 561.1 Maximum: 995 Minimum: 8 Range: 987 Median: 564.5 Mode: [660, 476]
For the provided numbers2.txt file the following are the values your program should generate:
Sum: 55568 Count: 99 Average: 561.2929292929293 Maximum: 995 Minimum: 8 Range: 987 Median: 575 Mode: [660, 476]
For the provided numbers3.txt file the following are the values your program should generate:
Sum: 728 Count: 1 Average: 728.0 Maximum: 728 Minimum: 728 Range: 0 Median: 728 Mode: [728]
For the provided numbers4.txt file the program should generate:
There are no numbers in numbers4.txt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started