Unit 13 OOP - Student & Library
Unit 13 OOP - Student & Library
Questions
Q1. Create a class named Student that represents a student with basic
attributes.
a. Attributes and Methods in Class:
Attributes:
name: Stores the student's name.
age: Stores the student's age.
grades: A list of grades.
Methods:
average_grade(): Calculates the average of all grades.
display_details(): Prints the student's name, age, and average grade.
(***) Define an __init__ method that initializes the student's name, age, and a list of grades.
Expected Output:
b. Add a method called add_book that takes a book_title as input and appends it to the books list. Print a message
confirming the book was added.
c. Add a method called remove_book that takes a book_title as input. If the book exists in the books list, remove it
and print a confirmation message. If the book does not exist, print a message saying the book was not found.
d. Add a method called display_books that prints all the books in the library. If the library is empty, print a message
saying "The library is empty."
Expected Output:
Go to Answer Page