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
Which of these files, when included in a program, will provide user assistance?
34kurt

Answer:

Answer for this question is D

Explanation:

Help flies

4 0
3 years ago
Read 2 more answers
❤️❤️❤️❤️❤️❤️❤️❤️IS THERE ANYONE'S STILL AWAKE?? HMM HEHE I'M HERE AGAIN~~~ FOLLOW ME FOR MOR3~~​
insens350 [35]

Answer:

hello?

Explanation:

3 0
2 years ago
Read 2 more answers
Why are there so many problems with drivers?
podryga [215]

D. hope this helped!!!!!

5 0
3 years ago
Which software is used to play, create, and modify audio and video files?
Alenkasestr [34]
Windows Movie Maker, iMovie, Final Cut Pro (x), QuickTime?
8 0
3 years ago
Read 2 more answers
From the set ( 5 , 7 , 9 , 11 , 13 make the inequality w - 4 < 8 true
Ksenya-84 [330]

Answer:

Explanation:

One group of students did an experiment to study the movement of ocean water. The steps of the experiment are listed below.

Fill a rectangular baking glass dish with water.

Place a plastic bag with ice in the water near the left edge of the dish.

Place a lighted lamp near the left edge of the dish so that its light falls directly on the plastic bag.

Put a few drops of ink in the water.

The student did not observe any circulation of ink in the water as expected because the experiment had a flaw. Which of these statements best describes the flaw in the experiment? (2 points)

Not enough ink was added.

Not enough water was taken.

The dish was too small for the experiment.

The lamp and the ice bag were at the same place.

7 0
3 years ago
Other questions:
  • Match terms in the first column with the order descriptions in column two.
    11·1 answer
  • Can someone please give me a good definition to audience expectations!<br> (in film)
    8·1 answer
  • What is the output of the following program? #include using namespace std; class TestClass { private: int val; void showVal() {
    5·1 answer
  • To switch from one open document to another, press _____.
    6·1 answer
  • Why is it difficult to convince top management to commit funds to develop and implement SIS
    5·2 answers
  • Which of the following statements best compares and contrasts hot and cold type?
    12·1 answer
  • How would you delete a slide from your presentation after selecting it?
    14·1 answer
  • Write a function called changeCharacter that takes three parameters – a character array, its size, and the replacement character
    15·1 answer
  • imagine that you wanted to write a program that asks the user to enter in 5 grade values. the user may or may not enter valid gr
    12·1 answer
  • Define foreign employment​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!