how to check if a number is armstrong in python

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")

4
10
Polvoazul 255 points

                                    # 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")

4 (10 Votes)
0
4
2
Elenaher 90 points

                                    # Program to check Armstrong numbers in a certain interval

lower = 100
upper = 2000

for num in range(lower, upper + 1):

   # order of number
   order = len(str(num))
    
   # initialize sum
   sum = 0

   temp = num
   while temp > 0:
       digit = temp % 10
       sum += digit ** order
       temp //= 10

   if num == sum:
       print(num)

4 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
check the number is armstrong or not in python python armstrong number checker how to check whether a number is armstrong or not in python armstrong number check in python armstrong number in python easy program armstrong number code in python how to find the armstrong number in python armstrong number in python Given an integer N, check whether it's an Armstrong number or not. python armstrong number function in python armstrong number function python doselect armstrong number python doselect check number is armstrong or not in python check number is armstrong or not in python gfg armstrong of a number in python armstrong num code in python armstrong python program Write a python program to check whether the number is Armstrong number or not using function: python program to check given number is armstrong or not armstrong no in python how to find armstrong number in python armstrong number program in python using function generate armstrong number in python armstrong number series in python how to check if a number is armstrong in python 10. How would check a number is armstrong number using Python? armstrong number in python programiz armstrong program in python armstrong number in python youtuv program to check armstrong number in python armstrong in python python program to check armstrong number python code to find armstrong number armstrong numer code in python is armstrong is function available in python Write a Python Program to Check Armstrong Number? python armstrong program python program to find if a number is armstrong or not write python program to fined if given number is armstrong number write python program to fine armstrong number python armstrong number python code for armstrong number how to print armstrong no in python what is armstrong number logic python 4 digit armstrong number in python how to find given number is a armstrong number or not in python armstrong number or not in python python program to check armstrong number using functions python code to check armstrong number armstrong number program in python explanation armstrong number in python logic program for armstrong number in python python program to check for armstrong number python program for armstrong number using functions armstrong function in python given number is armstrong or not in python is armstrong number in python find armstrong number in python python what is armstrong numbers armstrong number in python using function armstrong python Implement Python Script to check given number is Armstrong or not. python function for armstrong number python program for armstrong number python code to show that number is Armstrong number or not (for n numbers). armstrong number python 2.Develop a python program to check the given number is Armstrong number or not using iteration control structures. program to find armstrong number in python check whether a number is armstrong or not in python Determine whether a number is a perfect number, an Armstrong number or a palindrome. armstrong number in python using while loop isarmstrong python python program armstrong number program to check whether number is armstrong or not in python To find whether a given number is Armstrong number or not in python Write a program in python to check whether the given number is Armstrong or not. armstrong number program in python armstrong number program python Check whether a given number is Armstrong number. in python armstrong without using loop python Write a python program to check whether a number is Armstrong number or not in python armstrong or not in python check armstrong number in python what is armstrong number in python armstrong number in python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source