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
Python 4.5 code practice
Arada [10]

Answer:

add the question

Explanation:

3 0
3 years ago
________ is a dedicated device designed to manage encrypted connections established over an untrusted network such as the Intern
pantera1 [17]

Answer:

The correct answer to the following question will be Option B (VPN concentrator).

Explanation:

  • Virtual Private Network (VPN) is a virtual, limited-use network generated using protocol encryption and tunneling over physical, public network connections.
  • A dedicated tool for managing VPN connections built over an untrusted network, such as the Internet, is called a VPN concentrator.
  • It's a type of networking system that ensures secure VPN connections are established and messages are transmitted between VPN nodes.

Therefore, Option B is the right answer.

7 0
3 years ago
Write a program that produces a bar chart showing the population growth of Prairieville, a small town in the Midwest, at 20-year
Sunny_sXe [5.5K]

Answer:

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

ifstream Inputfile;

Inputfile.open("People.txt"); // Open file

if (!Inputfile) // Test for open errors

{

cout << "Error opening file.\n";

return 0;

}

int Pop; // Population

// Display Population Bar Chart Header

cout << "PRAIRIEVILLE POPULATION GROWTH\n"

<< "(each * represents 1000 people)\n";

for (int Year = 1; Year <= 6; Year++)

{ // One iteration per year

switch (Year)

{

case 1 : cout << "1900 ";

break;

case 2 : cout << "1920 ";

break;

case 3 : cout << "1940 ";

break;

case 4 : cout << "1960 ";

break;

case 5 : cout << "1980 ";

break;

case 6 : cout << "2000 ";

break;

}

Inputfile >> Pop; // Read from file

// calculate one per 1000 people

//cout<<"**"<<Pop<<endl;

while(Pop > 0)

{ // Display one asterisk per iteration

// One iteration per 1000 people

cout << "*";

Pop -= 1000;

}

cout << endl;

}

Inputfile.close(); // To close file

return 0;

}

Explanation:

5 0
3 years ago
What are the core components of a computer system? CPU, RAM, ROM, I/O ports, keyboard CPU, RAM, ROM, I/O ports, system bus CPU,
zimovet [89]
CPU, RAM, ROM, system bus, I/O ports
8 0
4 years ago
Read 2 more answers
You will hear a series of activities typical of Candela's life. After listening to and repeating each one, rewrite the entire se
Anon25 [30]

These are the complete sentences using the correct forms of the verbs conjugated in the simple present tense:

  1. Nosotros escribimos correos electrónicos desde diferentes partes del mundo.
  2. Tus padres deben tener mucho dinero.
  3. Sus amigas asisten al gimnasio todos los días.
  4. Tú no comprendes a las otras abuelitas.
  5. Yo también vivo la vida loca.
<h3 /><h3>What is the simple present tense?</h3>

The Spanish simple present tense (''presente del indicativo'' in Spanish) is used to talk about habitual situations, routines, universal truths and facts.

All the verbs in the exercise are conjugated using this tense.

I was able to find the complete instructions for the exercise online. Here are the sentences that had to be changed:

  1. Candela escribe correos electrónicos desde diferentes partes del mundo. (Nosotros)
  2. Candela debe tener mucho dinero. (Tus padres)
  3. Candela asiste al gimnasio todos los días. (Sus amigas)
  4. Candela no comprende a las otras abuelitas. (Tú)
  5. Candela vive la vida loca. (Yo también)

Check more information about the simple present tense here brainly.com/question/26436711

6 0
3 years ago
Other questions:
  • Suppose that cells B1 through B100 of an Excel spreadsheet contain the quantity of units ordered on each of 100 different days.
    13·1 answer
  • "This command will give you a listing of your basic IP information for the computer you are using"
    6·1 answer
  • A(n) ____ is a predefined procedure that you can call (or invoke) when needed.
    9·1 answer
  • Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where
    11·1 answer
  • A pages visual organization is known as the
    14·2 answers
  • Truck drivers probably cannot see your vehicle if you cannot
    6·2 answers
  • Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in
    15·1 answer
  • True or False: <br> The object reference can be used to polymorphically store any class in Java.
    13·1 answer
  • If you delete a conversation many times with someone like this, will you stop receiving messages from them?
    13·1 answer
  • What do you understand by the term input, output, processing and storage.​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!