Exercise -- Open Lab 10 The Grading Problem Part 2 w/Lists Due: June 24, XXXXXXXXXX:59pm (midnight) Note: This is due by midnight (11:59pm). Submissions after the deadline CANNOT BE accepted! Learning...

1 answer below »
Not understanding how to do it


Exercise -- Open Lab 10 The Grading Problem Part 2 w/Lists Due: June 24, 2021 11:59pm (midnight) Note: This is due by midnight (11:59pm). Submissions after the deadline CANNOT BE accepted! Learning Objectives This assignment is meant to test your understanding of lists. If you have done your reading, you already know almost everything there is to know about lists. The following problem is like what you might be asked on the final exam. Working completely alone (although you can ask the instructor questions, as always), test your knowledge. Background Write a complete Python program that reads an unknown number of floating-point numbers from the file grades.dat. This does mean that you need to open the file. Do NOT ask the user to enter a filename. Open the file explicitly. First, read all the grades into a list structure. Then calculate 1. the number of total grades in the list, 2. the sum of the grades, 3. the average of the grades 4. the percentage for each letter grade of the whole. Next output, the total number of grades. The output the percentage of each letter grade followed by all grades that are within that letter grade. (See the sample output below for reference). All values aside from the total count should be formatted as floating-point values with one decimal place precision and the rightmost digit of all numeric values should line up in the output. IMPLEMENTATION NOTES 1. Use as your source file name “newgrader.py”. 2. This will be a short program. 3. You do not need to define any functions other than main(). 4. You may assume the input data will have no errors and will not need to be checked for them. 5. The input data file should be read only once into a LIST! 6. You are NOT allowed to open the input file a second time NOR rewind the file in some way. 7. Output is to standard output (stdout i.e. use print()). 8. The file you open must be called grades.dat (see the Submission information below for how to run/test your program) 9. Your output MUST match EXACTLY. Your program should not crash if the file is empty. SAMPLE INPUT Three sample input data files are provided for you to test your program: grades1.txt, grades2.txt, and grades3.txt. These can be copied from $PUB in the same manner you have been (use past assignments for reference). Note: grades3.txt is an empty file. The summary information should be printed with all 0’s as values and the average would be 0.0% The file grades2.txt looks like: 81 95 74 61 59 There are only 5 grades in the file with one grade per line. Before running your program, you should copy the sample datafile and rename it to grades.dat. For example: $cp $PUB/grades2.txt grades.dat EXAMPLE OUTPUT The sample output below is what your output should look like given the sample input file above (grades2.txt copied as grades.dat). Your output must be spaced, labeled, punctuated, and formatted EXACTLY as shown. Double check that your numeric values line up as shown in the sample output and everything is spelled correctly! Submission You are to electronically submit the source program, a source program listing, and the execution results obtained from running your program against provided percentage.dat file (see above). Once you have a working program, the following UNIX commands will do what is required: $ script ola10.log $ cat -n newgrader.py $ cp $PUB/grades1.txt grades.dat $ python3 newgrader.py $ cp $PUB/grades2.txt grades.dat $ python3 newgrader.py $ cp $PUB/grades3.txt grades.dat $ python3 newgrader.py $ exit $ handin ola10 newgrader.py ola10.log Reminder You should work alone on this assignment; neither offer nor accept any additional help, except on a one-to-one basis with the instructor or TA. Grading In addition to examining your source code and the execution results obtained by running your program against the test file(s) provided above, the grader may run your program against some additional (and unknown to you) data sets. Your program MUST work properly for ANY valid input to be considered correct.
Answered Same DayJun 23, 2021

Answer To: Exercise -- Open Lab 10 The Grading Problem Part 2 w/Lists Due: June 24, XXXXXXXXXX:59pm (midnight)...

Pratap answered on Jun 24 2021
144 Votes
"""
Grader Program
"""
def main():
"""
Main function
:return: None
"""
try:
file = open('grades.dat', 'r') # open the file
data = [] # create empty list
file_data = file.readlines() # store all lines as list
if len(file_data) == 0: # if file is empty
empty_flag = True # set empty flag as True
data = [0] * 5 # create list of zeroes
total_grades = 0 # set total number of grades to zero
else: # if file is not empty
empty_flag = False # set empty flag to False
for line in file_data: # iterate through each line
# convert the line content to floating number
data.append(float(line.strip()))
total_grades = len(data) # set total grades
data.sort(reverse=True) # sort the data in descending
file.close() # close the file
# get the sum of all grades
sum_grades = round(float(sum(data)), 2)
try:
# get the average of grades
avg_grades = sum_grades / total_grades
except ZeroDivisionError:
# set average to 0 while the grades are zero
avg_grades = 0.0
letter_count = [0] * 5 # initialize the letter count A,B,C,D,F
for i in data: # iterate through all grades
if i >= 90: # if grade > 90
letter_count[0] += 1 # increment count...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here