1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olga55 [171]
3 years ago
10

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

g 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.
Computers and Technology
1 answer:
zhenek [66]3 years ago
6 0

Answer:

In Python:

import os.path

from os import path

fname = input("Filename: ")

if path.exists(fname):

with open(fname) as file_in:

 lines = []

 for line in file_in:

  lines.append(line.rstrip('\n'))

f = open("stat.txt","r+")

f.truncate(0)

f = open("stat.txt", "a")

f.write("Names\tTotal\tSubjects\tAverage\n")

for i in range(len(lines)):

 rowsum = 0; count = 0

 nm = lines[i].split()

 for j in nm:

  if (j.isdecimal()):

   count+=1

   rowsum+=int(j)

 average = rowsum/count

 f.write(nm[0]+"\t %3d\t %2d\t\t %.2f\n" % (rowsum, count, average))

f.close()

else:

print("File does not exist")

Explanation:

See attachment for explanation where comments were used to explain each line

Download txt
You might be interested in
What was the computer works in binary functions
Mariulka [41]
Computers use binary - the digits 0 and 1 - to store data. A binary digit, or bit , is the smallest unit of data in computing.
7 0
3 years ago
What are the core components of a computer system?
Fantom [35]
CPU GPU harddrive ram
6 0
3 years ago
Which of these is a cultural form? A. Art B. Food C. Clothes D. All of the above
wel
D. All of the above


Sorry If Wrong
4 0
4 years ago
Read 2 more answers
Make a ladtract class that has 2 fields, one for the tractor's length and one for the width. The class should have a method that
Virty [35]

Explanation:

Below is the java code for the ladtract class :-

public class ladtract

{

private double length;  //length of tractor

private double width;   //width of tractor

public double calculateArea(){  

    return length*width;    //calculate and return the area of the tractor

}

public boolean equals(Object o) {

    if (o == this) {    //check if it's the same object

        return true;

    }

       if(o.length==this.length && o.width==this.width){   //check if the length and width are same for both objects

           return true;

       }

       return false;  

}

public String toString(){

    return "Area="+calculateArea(); //return the area of the tractor as a string

}

}

7 0
3 years ago
____ map a set of alphanumeric characters and special symbols to a sequence of numeric values that a computer can process.
Neporo4naja [7]
The answer is : coding schemes
4 0
3 years ago
Other questions:
  • Write in general about ergonomic injuries and also mention the symptoms that computer users exhibit when they experience these s
    11·2 answers
  • Tristan has successfully deleted the blank row. The next thing he wants to do is to increase the length of the first column. A 2
    13·2 answers
  • How can you tell that a website is not objective?
    15·2 answers
  • Does an android tablet have a hard drive
    7·1 answer
  • How do you create a logo on Adobe illustrator
    8·1 answer
  • Gwen's company is planning to accept credit cards over the Internet. Which one of the following governs this type of activity an
    13·1 answer
  • ________ consists of detailed, preprogrammed instructions that control and coordinate the computer hardware components in an inf
    11·1 answer
  • Sam wants to use the rule of thirds to capture the essence of his image. How will he apply this rule in his image to get a pleas
    6·1 answer
  • Power point programm<br><br>​
    11·1 answer
  • What is the effective address generated by the following instructions? Every instruction is
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!