Challenge: Write a Class that Maintains an Integer

Write a code inside a class that maintains an integer.

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 int
get_number(self)       # return current value of int
isnegative(self)       # checks whether int is negative
isdivisibleby(self, n) # checks whether int is divisible by n
absolute_value(self)   # returns absolute value of int
  • Input: It is an integer.
  • Output: We get the stored integer, check whether the given number is negative, check whether the number is divisible by another given number and return its absolute value.

Get hands-on with 1400+ tech skills courses.