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
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 studentid: 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:
iinitself name: str studentid: 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 enrollself coursename: 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. addgradeself coursename: 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 getgpaself: 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 strself: Returns a string representation of the Student object in the format: "Student Name: ID: Courses:
# Creating a new student
student Student Alice
# Enrolling the student in courses
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
