Skip to main content
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 if marks is 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'), then setMarks(85), then getMarks() returns 85
  • Student('Asha'), then setMarks(120) returns -1