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
Can anybody answer this
Mumz [18]

Answer:

The answer should be C. I, II, IV

3 0
3 years ago
What are examples of some Exotic currencies?
Grace [21]

Answer:

D.

Explanation:

An exotic currency pair is the pair of currencies of a major countries with those markets that are emerging or developing. Such currency pairs are seldomly used as it lacks market depth, added to it, it also contain the possibility of unfair treatment or partial treatment.

<u>Some example of exotic currency pair includes EUR/TRY (Euro and Turkish Lira), AUD/CAD (Australian Dollar and Canadian Dollar), etc.</u>

The example of Exotic currencies from the given options are MXN (Mexican Peso), ZAR (South African Rand), and HKD (Hong Kong Dollar).

Thus the correct option is D.

5 0
3 years ago
Connect research concepts to their definitions
stellarik [79]
Answer Research is defined as the creation of new knowledge and/or the use of existing knowledge in a new and creative way so as to generate new concepts, methodologies and understandings
8 0
2 years ago
True or false
wariber [46]

Answer:

It would definitely be true studied a lot of this stuff.

Explanation:

8 0
3 years ago
1. What does a network allow computers to share?
Veronika [31]

Answer:

1. B 2. D

Explanation:

If computers share processing power, it is just a larger computer.

8 0
3 years ago
Other questions:
  • For film editors, which task comes last in their workflow pattern?
    12·2 answers
  • True or false: although the first personal computers were available as early as the 1970's, the creation of the world wide web (
    11·1 answer
  • Holly Carpenter argues that technology may actually prevent some kinds of evolution that would benefit humans. Do you agree with
    8·2 answers
  • Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished
    14·2 answers
  • Three variables, x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts th
    7·1 answer
  • A collection of facts can be copyrighted, but only if the collection is ____ in a way that causes the resulting work to rise to
    14·1 answer
  • What is SoC? how is it different from CPU?
    14·1 answer
  • In PowerPoint online what can you add to your presentation from the insert tab
    8·2 answers
  • Samantha is part of a project management team working on the initiation phase of a project. What is her team expected to do in t
    5·2 answers
  • How are most databases organized?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!