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 :: Random parola uretme 
Python :: jupyter notebook print formatted text 
Python :: pyqt5 different resolutions 
Python :: python round function 
Python :: images in pygame 
Python :: python developer 
Python :: python import only one function 
Python :: frontmost flag qt 
Python :: how to make a var in pycode 
Python :: internet spam 
Python :: filter titlecase django 
Python :: pandas df to R df 
Python :: pytesseract.image_to_data into pandas dataframe 
Python :: nltk document 
Python :: lines = paths.read().splitlines() 
Python :: Seaborn boxplots shifted incorrectly along x-axis 
Python :: numpy symmetrize array 
Python :: plt.savefig no frame 
Python :: etails of the Response object by using help() method 
Python :: python multiple imports 
Python :: Regular Expressions In Practical NLP example 
Python :: plotly two y axis bar chart grouped 
Python :: Top n rows of each group 
Python :: how to hide a specific file in python 
Python :: parsing date columns when reading csv 
Python :: Create an x amount of unique random fixed size strings 
Python :: python store salt in csv 
Python :: python tk highlightthicknes 
Python :: auto indent python code 
Python :: egt id of current object django 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =