Search⌘ K

Challenge: Write a Class that Maintains an Integer

Explore how to design a Python class named Number that maintains an integer. Learn to implement methods for setting and retrieving the integer, checking if it is negative, testing divisibility by another number, and obtaining its absolute value. This lesson helps solidify your understanding of class design and object-oriented programming concepts in Python through practical coding.

Problem statement

Write a class called Number that maintains an integer. It should have the following methods in it to perform various operations on the integer:

set_number(self, n)    # sets n into
...