and list processing You will write a program to read grade data from a text file, displays the grades as a 5-column table, and then print the statistics (min, max, median, and median). You can assume that the input file only one number per line. You can assum
phyton
Topics: list and list processing
You will write a program to read grade data from a text file, displays the grades as a 5-column table, and then print the statistics (min, max, median, and median). You can assume that the input file only one number per line. You can assume the user always enter a file that exists.
The median is the value in the middle of a sorted list. To sort a list, use list.sort() function. It’s computed as below.
For a list of odd length, the middle number is just the length divide by 2. For the list, [1,2,3], the median is 2 since 2 is in the middle of the list. The middle index is 3//2, which is 1. Remember that // is the integer division operator.
When the length of the list is even, there are two middle numbers. The median is the average of the two middle numbers. For example, [1,2,3,4], the median is (2+3)/2 = 2.5. The two middle indexes for this example are (4//2)-1 = 1 and (4//2) = 2.
Functions you need to write:
read_grades() |
Prompts for a file, read grades from file into a list and return the list. |
compute_min(grades) |
Given a list of grades, return the smallest value. |
compute_max(grades) |
Given a list of grades, return the largest value. |
compute_sum(grades) |
Given a list of grades, return the sum. |
compute_mean(grades) |
Given a list of grades, return the mean or the average. |
compute_median(grades) |
Given a list of grades, return middle value. |
print_grades(grades, ncols) |
Given a list of grades, print it as a table of ncols. |
main() |
Get the grades, compute the min, max, mean, and max and print them. |
Sample run:
Enter file: grades1.txt 1 50 55 66 75 97 98 100 min = 1 max = 100 mean = 67.75 median= 70.5 |
Data used for sample run:
1 55 66 100 75 98 50 97 |
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
When I excute, it gives me this error. I could't figure out exactly
Enter file: grades1.txt
Traceback (most recent call last):
File "main.py", line 52, in <module>
main()
File "main.py", line 45, in main
grades = read_grades()
File "main.py", line 7, in read_grades
grades.append(int(line))
ValueError: invalid literal for int() with base 10: '\n'