Python 3 Program to Check Whether the Number is Armstrong Number or Not Tutorial For Beginners
1K views
Jun 1, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I'll show you a Python
0:04
program uh to check whether a number is
0:07
a Armstrong number or not armstrong is a
0:09
special kind of a number as you can see
0:12
it's a number which is equal to the sum
0:15
of its own digits each raised to the
0:17
power of a number of digits in the
0:19
number so what this means 153 is a
0:22
Armstrong number as you can see 1 to
0:25
the^ 3 + 5 ^ 3 + 3 ^ 3 so this comes out
0:30
to be 1 and 5 to the^ 3 comes out to be
0:36
125 and then it comes out to be
0:39
27 so
0:41
this sum as you can see
0:45
126 + 7 comes out to be
0:49
your
0:50
153 so this
0:52
is the actual formula here
0:56
each digit to the raised power three the
1:00
actual sum
1:02
is this sum
1:05
153 so we can do this programmatically
1:08
to check whether a number is Armstrong
1:10
or not so this is actually our Python
1:12
program here we simply ask the
1:15
user so if I run this Python script it
1:17
will ask to enter a number so let's
1:20
suppose I write a number 153 as soon as
1:23
I write this number you will see it's a
1:26
Armstrong number it calculates this
1:30
programmatically the
1:32
formula and uh now if I submit another
1:36
number let's suppose 154 it will say not
1:40
an Armstrong number so let me just show
1:43
you the actual program guys it's uh it's
1:46
very easy and for this I will use this
1:48
Python tutor software where I will
1:51
explain each
1:53
line so this is a very special software
1:56
where you can visualize the execution of
1:58
the program step by step so here it will
2:00
asking you to enter a number let's
2:03
suppose I write a
2:05
number 153 click on submit so as you can
2:10
see the number is registered as a global
2:12
variable it is stored inside this
2:14
variable
2:16
num now in the next step what we are
2:19
doing we are extracting we need to
2:21
extract each digit each digit from this
2:24
number so we need to extract this one
2:27
then we need to extract this five then
2:29
we have to extract three and then we
2:32
need to process them 1 to the^ 3
2:36
5 but before that we need to extract
2:39
each digit for extracting each
2:42
digit so what we can do right here we
2:46
can uh now to extract this
2:50
three we can divide this number by 100
2:54
so if I divide this by
2:56
100 as you can
3:02
see it comes out to be
3:06
53 so
3:09
the 100 divided by
3:15
153 I think yeah so basically it
3:18
extracts the digit of so it comes out to
3:22
be one so we are extracting this digit
3:24
one so that's why divide this by 100 now
3:28
in the next step we are
3:30
dividing the whole number by 10 and then
3:34
extracting the remainder when we divide
3:37
this by 10
3:38
again so now what happens we extract
3:41
this five from
3:43
here and now to extract the unit digit
3:47
we actually get the remainder when
3:49
whenever we divide this by 10 so that's
3:52
why we this is the remainder operator
3:54
this is not division this is used to
3:57
calculate the remainder this is the
4:00
division operator so this will extract
4:04
this three which is
4:05
there so multiple ways by which you can
4:08
do extract the digits this is the most
4:10
simplest way by which you calculate this
4:13
by using the division operator and
4:16
remainder operator now we get all these
4:19
three digits now we can successfully
4:22
calculate this by this if condition a
4:25
raised ^ 3 + b raised ^ 3 + c raised to
4:29
^ 3 if it is comes out to be the actual
4:32
number then it's a Armstrong
4:35
number so it calculates so now the sum
4:39
comes out to be Armstrong so you can see
4:41
that it prints out this number is a
4:44
Armstrong number so in this easy way
4:47
this is the way by which you can check
4:49
whether a number is Armstrong or not
4:52
uh also check out my website guys uh
4:56
freemediattools.com uh which contains uh
4:59
thousands of tools