Armstrong Number - An Armstrong Number is a Number which is equal to it's sum of digit's cube. For example - 153 is an Armstrong number: here 153 = (1*1*1) + (5*5*5) + (3*3*3).
This program will take a number and check whether it is Armstrong Number or Not.
Steps for checking Armstrong number:
- Calculate sum of each digit's cube of a number.
- Compare that number with the resultant sum.
- If Number and Sum of digit's cube is equal then it is an Armstrong Number otherwise not.
We are implementing this program using the concept of classes and objects.
Firstly we create the Class with "Check" name with 1 attributes (number) and 2 methods, the methods are:
- Constructor Method: This is created using __init__ inbuilt keyword. The constructor method is used to initialize the attributes of the class at the time of object creation.
- Object Method: isArmstrong() is the object method, for creating object method we have to pass at least one parameter i.e. self keyword at the time of function creation. This Object method has no use in this program.
Secondly, we have to create an object of this class using a class name with parenthesis then we have to call its method for our output.
Python code to count number of objects created
Output
need an explanation for this answer? contact us directly to get an explanation for this answer