Question: QUESTION 1 . You are required to create a Python class named Student that models a student. The class should have the following attributes and

QUESTION
1. You are required to create a Python class named Student that models a student. The class should have the following attributes and methods:
a. Attributes:
i. name : A string representing the student's name.
ii. student_id: An integer representing the student's unique identification number.
iii. courses: A list of strings representing the courses the student is enrolled in.
iv. grades: A dictionary where the keys are course names and the values are the grades the student has received in those courses.
b. Methods:
i.__init_(self, name: str, student_id: int): Initializes a new Student object with the provided name and student ID. The courses list should be empty, and the grades dictionary should be empty when a student object is created.
ii. enroll(self, course_name: str): Enrolls the student in a new course by adding the course name to the courses list. If the student is already enrolled in the course, the method should do nothing.
iii. add_grade(self, course_name: str, grade: float): Adds a grade for a specific course to the grades dictionary. If the student is not enrolled in the course, the method should raise a ValueError with the message "Student is not enrolled in the course.".
iv. get_gpa(self): Calculates and returns the student's GPA as the average of all grades in the grades dictionary. If the student has no grades, the method should return None.
v. str(self): Returns a string representation of the Student object in the format: "Student Name: , ID: , Courses: ".
\# Creating a new student
student = Student ("Alice",1234)
\# Enrolling the student in courses
QUESTION 1 . You are required to create a Python

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!