Question

In: Computer Science

[PYTHON] Modify the examaverages.py program included with this assignment so it will also compute the overall...

[PYTHON] Modify the examaverages.py program included with this assignment so it will also compute the overall average test grade. E.g if there are 3 test each student must take and the user enters the following set of test scores for the two students…:

30, 40, 50 for the first student

50, 60, 70 for the second student

…then program will print the average for each student (i.e. 40 for the first student and 60 for the second student – the existing program already does this) and additionally will also print the overall average (i.e. (40 + 60) /2 = 50).

------------

this is the provided code from 'examaverages.py' :

##
#  This program computes the average grade for multiple students.
#

# Obtain the number of test grades per student.
numExams = int(input("How many grades does each student have? "))

# Initialize moreGrades to a non-sentinel value.
moreGrades = "Y"

# Compute average grades until the user wants to stop.
while moreGrades == "Y" :
   
   # Compute the average grade for one student.
   print("Enter the grades out of 100.")
   total = 0
   for i in range(1, numExams + 1) :
      score = int(input("test %d: " % i))   # Prompt for each test grade.
      total = total + score
      
   average = total / numExams
   print("The average is %.2f" % average)
   
   # Prompt as to whether the user wants to enter grades for another student.
   moreGrades = input("Enter grades for another student (Y/N)? ")
   moreGrades = moreGrades.upper()

Solutions

Expert Solution

New Lines: 9,10,13,23,28,29

I have commented the description about the added lines for the modification in the given code.

I have started the comment for the new lines with # (line added).

If you have any queries, please ask in the comments, I regularly check them for 2-3 days.

Thank You.

Code:

#  This program computes the average grade for multiple students.

#

# Obtain the number of test grades per student.

numExams = int(input("How many grades does each student have? "))

# Initialize moreGrades to a non-sentinel value.

moreGrades = "Y"

studs = 0 #(line added)

avgTotal = 0 #(line added)

# Compute average grades until the user wants to stop.

while moreGrades == "Y" :

   studs = studs + 1 #(line added) counts the number of students

   # Compute the average grade for one student.

   print("Enter the grades out of 100.")

   total = 0

   for i in range(1, numExams + 1) :

      score = int(input("test %d: " % i))   # Prompt for each test grade.

      total = total + score

      

   average = total / numExams

   print("The average is %.2f" % average)

   avgTotal = avgTotal + average #(line added) Calculates the sum of the averages for all students

   # Prompt as to whether the user wants to enter grades for another student.

   moreGrades = input("Enter grades for another student (Y/N)? ")

   moreGrades = moreGrades.upper()

ovrAvg = avgTotal/studs #(line added) Calculates the overall average

print("The overall average for all students is: " + str(ovrAvg)) #(line added) Prints the overall average


Related Solutions

​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so...
​​​​​​This is an assignment that I'm having trouble figuring out in python: Modify Node class so it has a field called frequency and initialize it as one. Add a search function. If a number is in the list, return its frequency. Modify Insert function. Remove push, append, and insertAfter as one function called insert(self, data). If you insert a data that is already in the list, simply increase this node’s frequency. If the number is not in the list, add...
Modify the program 5-13 from page 279 such that will also compute the class average. This...
Modify the program 5-13 from page 279 such that will also compute the class average. This class average is in addition to each individual student score average. To accomplish this additional requirement, you should do the following: 1. Add two more variables of type double: one for accumulating student averages, and one to hold the class average. Don't forget, accumulator variable should be initialized to 0.0. 2. Immediately after computing individual student average, add a statement that will accumulate the...
In python....Modify the recursive Fibonacci program given in the textbook so that it prints tracing information....
In python....Modify the recursive Fibonacci program given in the textbook so that it prints tracing information. Specifically, have the function print a message when it is called and when it returns. For example, the output should contain lines like these: Computing fib(4) OR Leaving fib(4) returning 3
The second assignment involves writing a Python program to compute the price of a theater ticket....
The second assignment involves writing a Python program to compute the price of a theater ticket. Your program should prompt the user for the patron's age and whether the movie is 3D. Children and seniors should receive a discounted price. There should be a surcharge for movies that are 3D. You should decide on the age cutoffs for children and seniors and the prices for the three different age groups. You should also decide on the amount of the surcharge...
In Python Modify the program so it contains four columns: name, year, price and rating (G,PG,R…)...
In Python Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating def list(movie_list): if len(movie_list) == 0: print("There are no movies in the list.\n") return else: i = 1 for row in movie_list: print(str(i) + ". " + row[0] + " (" + str(row[1]) + ")") i += 1 print() def add(movie_list): name...
Modify the Movie List 2D program -Modify the program so it contains four columns: name, year,...
Modify the Movie List 2D program -Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) -Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating def list(movie_list): if len(movie_list) == 0: print("There are no movies in the list.\n") return else: i = 1 for row in movie_list: print(str(i) + ". " + row[0] + " (" + str(row[1]) + ")") i += 1...
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted...
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted and use your variable names and testArrays.  
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
PYTHON Modify the program in section Ask the user for a first name and a last...
PYTHON Modify the program in section Ask the user for a first name and a last name of several people.  Use a loop to ask for user input of each person’s first and last names  Each time through the loop, use a dictionary to store the first and last names of that person  Add that dictionary to a list to create a master list of the names  Example dictionary: aDict = { "fname":"Douglas", "name":"Lee" } ...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when the program runs. Have the program request the number of initial numbers to be entered." //C++ Program 7.14 as follows #include #include #include #include using namespace std; int main() { const int NUMELS = 4; int n[] = {136, 122, 109, 146}; int i; vector partnums(n, n + NUMELS); cout << "\nThe vector initially has the size of " << int(partnums.size()) << ",\n and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT