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 the name of the programming language created by Spu7Nix?
VMariaS [17]
The name of the programming language is “Brainfugd”
3 0
3 years ago
Read 2 more answers
Data values in a program are held in _________. a data types b names c variables d lockers
Tpy6a [65]

Answer:

Answered below

Explanation:

Data values in a program are held in variables. Variables are like containers for holding different types of data. A variable can be identified depending on the kind of data it holds. Variables can hold data types of integers, strings, arrays, lists, sets, Boolean etc. They hold unique data types and a can not hold different data types. Different rules exist for naming variables in different programming languages. A variable name should start with lowercase letters and be descriptive of the data it holds.

7 0
3 years ago
The formatting option functions like space bar. However instead of moving one space at a time, it allows you to move your text i
Schach [20]
What are the options???
4 0
3 years ago
A is a way for students to keep track of information during research
Ilya [14]
The choices are a) credible website B)search log c) Boolean operator d) online database.

The answer is, d. Online database. There are already numerous online digital tools that can aid research. Examples are readcube, mendeley, google scholar. It helps you save and organize researches as well as automatically give bibliographies according to your need like APA and MLA. These tools can hold and save different information that researchers need.
6 0
3 years ago
Zbn-ivfh-ovm is the meet code enter there lol
RSB [31]

Answer:

bet

Explanation:

8 0
3 years ago
Other questions:
  • List three types of cardinalities for relationships within a relational database.
    9·1 answer
  • A ________ is a material deficiency, or combination of significant deficiencies, that results in more than a remote likelihood t
    6·1 answer
  • You load an image file into a numpy array and look at its shape, which is (433, 650). What does this indicate?
    13·1 answer
  • Difference between a software package and Integrated software and why users would choose one over the other
    8·1 answer
  • Which of the following are correct? I. Hold the middle mouse button to rotate the model on the screen. II. To pan the model, hol
    15·1 answer
  • 5. The command to add new layout to the slide is present in<br>tab.​
    15·1 answer
  • Creating a Venn diagram takes specialized computer software.
    15·2 answers
  • In your own words, explain the FNAF timeline
    15·1 answer
  • Why are computer simulations useful in studying phenomena in the universe?
    15·1 answer
  • Which type of attack can be addressed using a switched ethernet gateway and software on every host on your network that makes su
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!