1. Learn
  2. /
  3. Courses
  4. /
  5. Object-Oriented Programming in Python

Exercise

Using internal attributes

In this exercise, you'll return to the BetterDate class of Chapter 2. Your date class is better because it will use the sensible convention of having exactly 30 days in each month.

You decide to add a method that checks the validity of the date, but you don't want to make it a part of BetterDate's public interface.

The class BetterDate is available in the script pane.

Instructions

100 XP
  • Add a class attribute _MAX_DAYS storing the maximal number of days in a month - 30.
  • Add another class attribute storing the maximal number of months in a year - 12. Use the appropriate naming convention to indicate that this is an internal attribute.
  • Add an _is_valid() method that returns True if the day and month attributes are less than or equal to the corresponding maximum values, and False otherwise. Make sure to refer to the class attributes by their names!