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 is meant by the term drill down?
andrezito [222]

Answer:

 The drill down term is basically used in the information technology for the explore the multidimensional information or data by navigating the different layers of the data from the web page applications.  

Drill down basically involve in the database by accessing the specific information through the database queries. Each query basically increase the data granularity. This term is also involve with the link for represent the details more specifically.

The drill down is the simple approach or technique for dividing the complex problems into small parts so that it make the technique more efficient.

7 0
3 years ago
What is the purpose of a register in a CPU? Describe three types of registers.
Ganezh [65]

Answer:

I hope this answer is correct

Explanation:

Internal registers include the instruction register (IR), memory buffer register (MBR), memory data register (MDR), and memory address register (MAR). The instruction register fetches instructions from the program counter (PC) and holds each instruction as it is executed by the processor.

5 0
3 years ago
Which of the following statements is false? a. Racks and bins are examples of storage equipment. b. Automation refers to equipme
svp [43]

Answer:

b. Automation refers to equipment that complements, rather than replaces, human contact.

3 0
3 years ago
Please help it's my last question
Yuki888 [10]

Explanation:

here is your answer.. of. different between client / server architecture and peer to peer architecture of the network.

6 0
2 years ago
Read 2 more answers
A type of technology that can be attached to a tag and used to identify postal packages is a(n)
deff fn [24]

Answer: bar code

Explanation: that is what it is

5 0
3 years ago
Other questions:
  • A type of specialty processor devoted exclusively to protecting your privacy.
    9·2 answers
  • If a pilot is converting standard time to UTC time and is given the time 1730 UTC, what would EST be?
    8·2 answers
  • Brad Smith works for GHI Firm. GHI firm is a registered Broker-Dealer in State A, B and C and a registered IA in State A. Brad i
    10·1 answer
  • Many software makers provide free downloadable updates, sometimes called a(n) ______ to users who have registered and/or activat
    5·1 answer
  • The communication channel used in IMC must rev: 12_06_2018_QC_ CDR-223 Multiple Choice match the traditional channel used in tha
    14·1 answer
  • What is Quantum Cryptography? How is it different from Public and Private-key transactions?
    6·1 answer
  • Program 3.Study the code carefully and write out the line where there is error, debug it and write out the correct code
    13·1 answer
  • Which type of file can be opened directly into Excel?
    15·1 answer
  • Which type of evaluation requires that the program be fully implemented before the evaluation can begin
    9·1 answer
  • Use conversion tool to convert the binary numbers to decimal.
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!