Question

In: Computer Science

Using Python Define a Student class. A Student class needs to have two attributes, the student_name...

Using Python

Define a Student class. A Student class needs to have two attributes, the student_name and strudent_grade . It also has three methods as follows: set_grade(grade) that sets the grade of the student. get_grade returns the grade of the student. print_student_info that print the name and grade of student in a formatted string.

In the math_utils.py file define a function called average_grade(roster) . This method accepts as input a list of Student Objects and returns the average of the current roster.

In the app.py file, create a main function, to create a roster of 10 students, print the list of students, and print the average score of the current roster. You can either populate the student roster interactively (i.e. by using the input method to prompt the user from the console) or hard-code the student information in your code.

The app.py file must use the Student class, and the average_grade method you defined the mymodules module.

Solutions

Expert Solution

Here is the completed code for this problem. Ensure that filenames are correct and all files are in same folder. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#code

#student.py file

#Student class

class Student:
    #constructor taking name and grade
   
def __init__(self, name, grade):
        self.student_name=name
        self.student_grade=grade

    #sets the grade
   
def set_grade(self, grade):
        self.student_grade=grade

    #returns the grade
   
def get_grade(self):
        return self.student_grade

    #prints student info
   
def print_student_info (self):
        print('Name: {}, grade: {}'.format(self.student_name, self.student_grade))








#math_utils.py file

#returns the average grade of all students in roster

def average_grade(roster):
    #initializing total to 0
   
total=0
    #looping and summing grades of all students in roster
   
for student in roster:
        total+=student.get_grade()
    #finding average and returning it
   
avg=total/len(roster)
    return avg









#app.py file

#importing all classes/methods from student.py and math_utils.py modules
#ensure that you have saved the Student class and average_grade method in
#proper modules with correct name

from student import *
from math_utils import *

#main method
def main():
    #creating a list of 10 students
   
roster = [Student('Oliver', 90),
              Student('John', 92),
              Student('Nidhi', 94),
              Student('Ram', 88),
              Student('Kripke', 76),
              Student('Raj', 96),
              Student('Sheldon', 100),
              Student('Penny', 75),
              Student('Amy', 95),
              Student('Barry', 79)]
    #looping and printing all students
   
for i in roster:
        i.print_student_info()
    #finding and printing average_grade
  
print('\nAverage grade: {:.2f}'.format(average_grade(roster)))

main()

#output

Name: Oliver, grade: 90

Name: John, grade: 92

Name: Nidhi, grade: 94

Name: Ram, grade: 88

Name: Kripke, grade: 76

Name: Raj, grade: 96

Name: Sheldon, grade: 100

Name: Penny, grade: 75

Name: Amy, grade: 95

Name: Barry, grade: 79

Average grade: 88.50


Related Solutions

Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes...
Needs to be done in PYTHON A. Create a Dollar currency class with two integer attributes and one string attribute, all of which are non-public. The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part. The string attribute will represent the currency name. B. Create a CIS22C Dollar derived/inherited class with one additional non-public double attribute to represent the conversion factor from/to US...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length...
This is python #Create a class called Rectangle. Rectangle should #have two attributes (instance variables): length and #width. Make sure the variable names match those words. #Both will be floats. # #Rectangle should have a constructor with two required #parameters, one for each of those attributes (length and #width, in that order). # #Rectangle should also have a method called #find_perimeter. find_perimeter should calculate the #perimeter of the rectangle based on the current values for #length and width. # #perimeter...
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE-...
Using python class: Design a class called Account CLASS NAME:    Account ATTRIBUTES: -nextAcctID: int    #NOTE- class-level attribute initialized to 1000 -acctID: int -bank: String -acctType: String (ex: checking, savings) -balance: Float METHODS: <<Constructor>>Account(id:int, bank: String, type:String, bal:float) +getAcctID(void): int                        NOTE: retrieving a CLASS-LEVEL attribute! -setAcctID(newID: int): void           NOTE: PRIVATE method +getBank(void): String +setBank(newBank: String): void +getBalance(void): float +setBalance(newBal: float): void +str(void): String NOTE: Description: prints the information for the account one item per line. For example: Account #:        ...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
Define social class and explain its attributes.
Define social class and explain its attributes.
Using Eclipse, create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours...
Using Eclipse, create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type double. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type double. For each class, provide its getter and setter functions, a default constructor, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for the Services class...
This needs to be in Python and each code needs to be separated. Design a class...
This needs to be in Python and each code needs to be separated. Design a class for a fast food restaurant meals that should have 3 attributes; Meal Type (e.g., Burger, Salad, Taco, Pizza); Meal size (e.g., small, medium, large); Meal Drink (e.g., Coke, Dr. Pepper, Fanta); and 2 methods to set and get the attributes. Write a program that ask the user to input the meal type, meal size, and meal drinks. This data should be stored as the...
In python- Create a class defined for Regression. Class attributes are data points for x, y,...
In python- Create a class defined for Regression. Class attributes are data points for x, y, the slope and the intercept for the regression line. Define an instance method to find the regression line parameters (slope and intercept). Plot all data points on the graph. Plot the regression line on the same plot.
I have defined the class. Rectangle in Python. How do I define a class Canvas with...
I have defined the class. Rectangle in Python. How do I define a class Canvas with the following description: Class Canvas represents a collection of Rectangles. It has 8 methods. In addition, to the constructor (i.e. __init__ method) and two methods that override python's object methods (and make your class user friendly as suggested by the test cases), your class should contain 5 more methods: add_one_rectangle, count_same_color, total_perimeter, min_enclosing_rectangle, and common_point.
I am a student taking python programming. Can this problem be modified using the define main...
I am a student taking python programming. Can this problem be modified using the define main method, def main()? #Define showExspenses function def showExpenses(loan,insure,gas,oil,tyres,maintenance): expense=loan+insure+gas+oil+tyres+maintenance #Print monthly and yearly automobile operating expenses print("\nTotal Monthly expenses for operating expenses you entered = ",expense) print(f"\nTotal Yearly expenses for operating expenses you entered = 12 *",expense,f"= {expense*12:,}") #yearly expenses loan=int(input("Enter Loan :")) insure=int(input("Enter Insurance :")) gas=int(input("Enter Gas :")) oil=int(input("Enter Oil :")) tyres=int(input("Enter Tyres :")) maintenance=int(input("Enter Maintenance:")) showExpenses(loan,insure,gas,oil,tyres,maintenance)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT