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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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'

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
User Defined DataType
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education