Challenge: Write a Class that Maintains an Integer
Write a code inside a class that maintains an integer.
We'll cover the following...
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.
Access this course and 1400+ top-rated courses and projects.