Question: Please answer the following question in Python. Students can graduate with honors if their GPA is at or above 3.0. Complete the Course class by
Please answer the following question in Python.
Students can graduate with honors if their GPA is at or above 3.0. Complete the Course class by implementing the count_honors() instance method, which returns the number of students with a GPA at or above 3.0.
The file main.py contains:
The main function for testing the program.
Class Course represents a course, which contains a list of Student objects as a course roster. (Type your code in here.)
Class Student represents a classroom student, which has three attributes: first name, last name, and GPA.
Hint: Refer to the Student class to explore the available instance methods that can be used for implementing the count_honors() method.
Note: For testing purposes, different student values will be used.
Ex. For the following students:
Henry Cabot 3.2 Brenda Stern 2.9 Lynda Robison 3.6 Jane Flynn 1.8
the output is:
Honors count: 2
Starter Code:
class Student: def __init__(self, first, last, gpa): self.first = first # first name self.last = last # last name self.gpa = gpa # grade point average
def get_gpa(self): return self.gpa
def get_last(self): return self.last
class Course: def __init__(self): self.roster = [] # list of Student objects
def add_student(self, student): self.roster.append(student)
def course_size(self): return len(self.roster)
# Type your code here
if __name__ == "__main__": course = Course() course.add_student(Student('Henry', 'Cabot', 3.2)) course.add_student(Student('Brenda', 'Stern', 2.9)) course.add_student(Student('Lynda', 'Robison', 3.6)) course.add_student(Student('Jane', 'Flynn', 1.8))
honors_count = course.count_honors() print(f'Honors count: { honors_count }')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
