All questions
EasyOOP · Encapsulation
Student Marks Encapsulation
Written by a community member · · 1 attempt · 0% pass
0
Implement a Python class that demonstrates encapsulation for a student's marks.
Create a Student class with:
__init__(self, name): stores the student's name and initializes marks as unset.setMarks(self, marks): sets the student's marks only ifmarksis an integer between 0 and 100 inclusive.- If the value is invalid, raise an error (
ValueErrorin Python).
- If the value is invalid, raise an error (
getMarks(self): returns the currently stored marks.- If marks have not been set yet, return
-1.
- If marks have not been set yet, return
Notes:
- Use a private attribute for marks.
- Do not validate the student name.
Examples:
Student('Asha'), thensetMarks(85), thengetMarks()returns85Student('Asha'), thensetMarks(120)raisesValueError