Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code this in python In this assignment we are going to practice reading from a file and writing the results of your program into a

Code this in python

In this assignment we are going to practice reading from a file and writing the results of your program into a file.

We are going to write a program to help Professor X automate the grade calculation for a course. Professor X has a data file that contains one line for each student in the course. The students name is the first thing on each line, followed by some tests scores. The number of scores might be different for each student. Here is an example of what a typical data file may look like:

Joe 10 15 20 30 40 Bill 23 16 19 22 Sue 8 22 17 14 32 17 24 21 2 9 11 17 Grace 12 28 21 45 26 10 John 14 32 25 16 89

Program details

Write a program that:

  • Ask the user to enter the name of the data file.

  • Read the data from the file and for each student calculate the total of the test scores, how many tests the student took, and the average of the test scores.

  • Save the results in an output file (e.g. stats.txt) in the following order:

    • studentName totalScore numberOfTests testAverage
    • Note that the average is saved with 2 decimal places after the decimal point.
  • Validation: Make sure your program does not crash if a file is not found or cannot be open.

Here is what a typical output file may look like (this one is based on the sample input file above):

Joe 115 5 23.00 Bill 80 4 20.00 Sue 194 12 16.17 Grace 142 6 23.67 John 176 5 35.20

Below are some sample runs:

Enter name of the data file: studentData.txt Stats have been save in the output file
Enter name of the data file: data.txt Error: that file does not exist. Try again. Enter name of the data file: students.txt Error: that file does not exist. Try again. Enter name of the data file: studentData.txt Stats have been save in the output file

Notes:

  • The purpose of this problem is to practice using file input/output.
  • Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.
  • This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.

Step by Step Solution

3.43 Rating (159 Votes )

There are 3 Steps involved in it

Step: 1

Python Program Python program that reads data from file process grades and store... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probability and Random Processes With Applications to Signal Processing and Communications

Authors: Scott Miller, Donald Childers

2nd edition

123869811, 978-0121726515, 121726517, 978-0130200716, 978-0123869814

More Books

Students also viewed these Operating System questions