Back to Course
Python Programming Exercise
0% Complete
0/0 Steps
-
Python Program to Print Hello world!
-
Python Program to Add Two Numbers
-
Python Program to Find the Square Root
-
Python Program to Calculate the Area of a Triangle
-
Python Program to Solve Quadratic Equation
-
Python Program to Swap Two Variables
-
Python Program to Generate a Random Number
-
Python Program to Convert Kilometers to Miles
-
Python Program to Convert Celsius To Fahrenheit
-
Python Program to Check if a Number is Positive, Negative or 0
-
Python Program to Check if a Number is Odd or Even
-
Python Program to Check Leap Year
-
Python Program to Find the Largest Among Three Numbers
-
Python Program to Check Prime Number
-
Python Program to Print all Prime Numbers in an Interval
-
Python Program to Find the Factorial of a Number
-
Python Program to Display the multiplication Table
-
Python Program to Print the Fibonacci sequence
-
Python Program to Check Armstrong Number
-
Python Program to Find Armstrong Number in an Interval
-
Python Program to Shuffle Deck of Cards
-
Python Program to Find the Sum of Natural Numbers
-
Python Program To Display Powers of 2 Using Anonymous Function
-
Python Program to Find Numbers Divisible by Another Number
-
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
-
Python Program to Find ASCII Value of Character
-
Python Program to Find HCF or GCD
-
Python Program to Find LCM
-
Python Program to Find the Factors of a Number
-
Python Program to Make a Simple Calculator
-
Python Program to Display Calendar
-
Python Program to Display Fibonacci Sequence Using Recursion
-
Python Program to Find Sum of Natural Numbers Using Recursion
-
Python Program to Find Factorial of Number Using Recursion
-
Python Program to Convert Decimal to Binary Using Recursion
-
Python Program to Add Two Matrices
-
Python Program to Transpose a Matrix
-
Python Program to Multiply Two Matrices
-
Python Program to Check Whether a String is Palindrome or Not
-
Python Program to Remove Punctuations From a String
-
Python Program to Sort Words in Alphabetic Order
-
Python Program to Illustrate Different Set Operations
-
Python Program to Count the Number of Each Vowel
-
Python Program to Merge Mails
-
Python Program to Find the Size (Resolution) of a Image
-
Python Program to Find Hash of File
Lesson 19 of 46
In Progress
Python Program to Check Armstrong Number
In this example, you will learn to check whether an n-digit integer is an Armstrong number or not.
Check Armstrong number (for 3 digits)
# 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 1
Enter a number: 663 663 is not an Armstrong number
Output 2
Enter a number: 407 407 is an Armstrong number
Check Armstrong number of 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")