We truly want to believe that you find the Armstrong Number in Python article as a main priority. We should continue on toward the articles.
A number is called an Armstrong number on the off chance that the amount of blocks of digits of a number is equivalent to the actual number. In the beneath C program, we are checking regardless of whether the info number is Armstrong.
Armstrong number is a number that is equivalent to the amount of 3D squares of its digits. For instance 0, 1, 153, 370, 371, and 407 are the Armstrong numbers.
We should attempt to comprehend the reason why 153 is an Armstrong number.
153 = (1*1*1)+(5*5*5)+(3*3*3)
where:
(1*1*1)=1
(5*5*5)=125
(3*3*3)=27
So:
1+125+27=153
What is Armstrong Number?
A three-digit number can be supposed to be an Armstrong number when the amount of all its singular digits blocks is equivalent to the actual number.
Armstrong Number in Python using 3 digits
At first, We can give the 3 digits of contribution to check regardless of whether the given info number is an Armstrong Number in the beneath program.
# Python program to check if the number is an Armstrong number or not
# take input from the user
num = int(input("Enter a number: "))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output
Two types of inputs are given below to clear your doubts.
Enter a number: 154 154 is not an Armstrong number
Enter a number: 153
153 is an Armstrong number
Armstrong Number in Python using n digits
num = 1634
# Changed num variable to string,
# and calculated the length (number of digits)
order = len(str(num))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
# display the result
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Conclusion
We really want to believe that you find the Armstrong Number in Python article extremely helpful. Assuming you have any questions you can ask your questions through the remark enclose this article