Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Source Code: 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")
Comment

Source Code: 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")
Comment

PREVIOUS NEXT
Code Example
Python :: Bilgisayardaki mp3 uzantili dosyalari bulma 
Python :: django orm filter equal insensitive 
Python :: how to downlaod file using python 
Python :: list of ones python 
Python :: how can i add a list in python 
Python :: selenium restart browser python 
Python :: django command to fetch all columns of a table 
Python :: python polyfit with errors 
Python :: how to change pi hostname in python file 
Python :: 56.5 to 57 in python 
Python :: isat in panadas datframe 
Python :: Python Textfeld lköschen 
Python :: matplotlib include first number in plotter 
Python :: gym for creating simple grid world 
Python :: numpy convolution stride tricks 
Python :: django.com 
Python :: python Write code that asks users to enter the year they were born. Print out how many years old they will turn in 2019. 
Python :: np.modf 
Python :: Catching Specific Exceptions in Python 
Python :: Python Reloading a module 
Python :: REST APIs with Flask and Python free download 
Python :: plotly two y axis bar chart 
Python :: create new column with first character of string pyspark 
Python :: django save object 
Python :: ploting to data on the same axis 
Python :: return a table of selected features pandas 
Python :: what is PaasLib 
Python :: dht22 micropython library 
Python :: python typing namedtuple 
Python :: a list of available font in figlet in python 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =