All questions
EasyOOP · Data Abstraction
Student Marks Data Abstraction
Written by a community member · · 2 attempts · 50% pass
0
Implement a Python class that demonstrates data abstraction 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 between 0 and 100 inclusive and returns them. If the value is invalid, return -1.getMarks(self): returns the currently stored marks. If marks have not been set yet, return -1.
Notes:
- Use a private attribute for marks.
- Do not validate the student name.
Examples:
Student('Asha'), thensetMarks(85), thengetMarks()returns85Student('Asha'), thensetMarks(120)returns-1