Question

In: Computer Science

This is python: #Imagine you're writing a program to calculate the class #average from a gradebook....

This is python:

#Imagine you're writing a program to calculate the class
#average from a gradebook. The gradebook is a list of
#instances of the Student object.
#
#You don't know everything that's inside the Student object,
#but you know that it has a method called get_grade().
#get_grade() will return the average for the student
#represented by a given instance of Student.
#
#You don't know if get_grade() is stored in memory or if
#it's calculated when it's needed, but you don't need to.
#All you need to know is that the class Student has a method
#get_grade() that returns an integer representing the
#student's numeric grade.
#
#Write a function called class_average. class_average()
#should take as input a list of instances of Student, and it
#should return as output the average grade of those
#students, as calculated via their get_grade() method.
#Remember, average is the sum of all their individual
#grades, divided by the number of students.
#
#Hint: You do NOT need to write the Student class to
#complete this problem. You may if you want to in order to
#run and test your code, but when you submit your code for
#grading, we will test it with our Student class. Don't let
#this throw you off: throughout this course, you've been
#using lots of classes without knowing how they work: you
#don't know how the String class works, but you know what
#its upper() method does. You do not need to know how the
#Student class works to use its get_grade() method.


#Write your function here!

#If you want to write a Student class to test your code,
#you could below, and then add your own test cases below
#that. The only requirement you would need to meet is that
#your Student class would need to have a get_grade()
#method that returns an integer (in addition to any other
#usual requirements for classes).

Solutions

Expert Solution

Python Code for the provided problem statement

# Python program to calculate the Average grades of each student
# as well as the average of class grades

# student class
class Student:
   def __init__(self, roll, name, lst): # constructor
       self.name = name # name
       self.roll = roll # roll Number
       self.lst = lst # list of marks
  
   # this class method will calculate the average marks of current student object
   # and then return the calculated value
   def get_grade(self):
   total = 0
   list_size = len(self.lst)
  
   for x in self.lst:
   total += x
   avg = total/list_size
   return avg

# this method will display the each student data
# as well as calculate the Average grades of the class
# and then it will display the average_of_class_grades
def class_average(students_list):
sum_of_average_grades = 0
  
for obj in students_list:
print("\nStudent Name: ",obj.name)
print("Student Roll no: ",obj.roll)
  
# call method to get the average grades of the Student
temp = obj.get_grade()
print("Student Average Grades: ",temp)
sum_of_average_grades += temp
  
# average_of_class_grades
total_students = len(students_list)
average_of_class_grades = sum_of_average_grades/total_students
print("\nAverage of Class Grades: ",average_of_class_grades)

# driver function for initial inputs
def main():
# enter number of students
no_of_students = int(input("Number of students in the class: "))
  
# initialize list to store student object
students_list = []
  
# for each student, enter roll, name, and marks
for i in range(no_of_students):
print("\nStudent -> ",(i+1))
roll = int(input("Enter roll number: "))
name = input("Enter name: ")
  
# initialize list to store marks
marks_list = []
for j in range(3):
# add marks to the list
marks_list.append(int(input("Enter marks "+str(j+1)+": ")))
  
# add student object to the list
students_list.append(Student(roll, name, marks_list))
  
# call method to calculate the Average grades of the class
class_average(students_list)

# program start from here   
if __name__=="__main__":
main()

Python Code Screenshots

Output Screenshot

Note:- Please take care of indentation while writing the python code.


Related Solutions

C++ exercise ! Change the WEEK‐4 program to work through the GradeBook class. This program has...
C++ exercise ! Change the WEEK‐4 program to work through the GradeBook class. This program has some functionality that you can use with the Gradebook class. So, please revise Gradebook class so that the class can use sort() and display() functions of WEEK4 program . week-4 program : #include #include using namespace std; void sort(char nm[][10]); void display(char name[][10]); int main() { char names[10][10]; int i; for (i=0; i<10; i++) { cout << "Enter name of the student : ";...
Write a Python program that uses function(s) for writing to and reading from a file: a....
Write a Python program that uses function(s) for writing to and reading from a file: a. Random Number File Writer Function Write a function that writes a series of random numbers to a file called "random.txt". Each random number should be in the range of 1 through 500. The function should take an argument that tells it how many random numbers to write to the file. b. Random Number File Reader Function Write another function that reads the random numbers...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
Using steps.py in this repository for a starter file, write a Python program to calculate average...
Using steps.py in this repository for a starter file, write a Python program to calculate average number of steps per month for a year. The input file (which you will read from the command line, see the sample program on how to read command line arguments in this repository) contains the number of steps (integer) a person took each day for 1 year, starting January 1. Each line of input contains a single number. Assume this is NOT a leap...
in python You will be writing a program that can be used to sum up and...
in python You will be writing a program that can be used to sum up and report lab scores. Your program must allow a user to enter points values for the four parts of the problem solving process (0-5 points for each step), the code (0-20 points), and 3 partner ratings (0-10) points each. It should sum the points for each problem-solving step, the code, and the average of the three partner ratings and print out a string reporting the...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
In Python Write a Fibonacci class to calculate next number in the 'Fibonacci' class by the...
In Python Write a Fibonacci class to calculate next number in the 'Fibonacci' class by the 'nxt' method. In this class, the 'val' member is a Fibonacci number. The 'nxt' method will return a 'Fibonacci' object whose value is the next number in Fibonacci series. class Fibonacci (): """A Fibonacci number. >>>a = Fibonacci(): >>>a 0 >>>a.nxt() 1 >>>a.nxt().nxt() 1 >>>a.nxt().nxt().nxt() 2 >>>a.nxt().nxt().nxt().nxt() 3 >>>a.nxt().nxt().nxt().nxt().nxt() 5 >>>a.nxt.nxt().nxt().nxt().nxt().nxt() 8 """ def __init__(self): self.val = 0 def nxt(self): """YOUR SOURCE CODE HERE"""...
The sixth assignment involves writing a Python program to read in the temperatures for ten consecutive...
The sixth assignment involves writing a Python program to read in the temperatures for ten consecutive days in Celsius and store them into an array. The entire array should then be displayed. Next each temperature in the array should be converted to Fahrenheit and the entire array should be again be displayed. The formula for converting Celsius to Fahrenheit is °F = (°C × 1.8) + 32. Finally, the number of cool, warm and hot days should be counted and...
This involves writing a Python program to determine the body-mass index of a collection of six...
This involves writing a Python program to determine the body-mass index of a collection of six individuals. Your program should include a list of six names. Using a for loop, it should successively prompt the user for the height in inches and weight in pounds of each individual. Each prompt should include the name of the individual whose height and weight is to be input. It should call a function that accepts the height and weight as parameters and returns...
Explain this python program as if you were going to present it to a class in...
Explain this python program as if you were going to present it to a class in a power point presentation. How would you explain it? I am having a hard time with this. I have my outputs and code displayed throughout 9 slides. #Guess My Number Program # Python Code is modified to discard duplicate guesses by the computer import random #function for getting the user input on what they want to do. def menu(): #print the options print("\n\n1. You...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT