The below function is written to check whether a given three digit number is an Armstrong number. Hint: An “Armstrong number” is an n-digit number that is equal to the sum of the nth powers of its individual digits. Example: 371 is an Armstrong number as 371 = 3^3 +7^3+ 1^3

The below function is written to check whether a given three digit number is an Armstrong number.

Hint: An “Armstrong number” is an n-digit number that is equal to the sum of the nth powers of its individual digits.
Example: 371 is an Armstrong number as 371 = 3^3 +7^3+ 1^3



Source:
'''
Created on 24-Aug-2019
@author: Anonymous
'''
#PF-Tryout
def find_armstrong(number):
temp=0
x=number #
while(number!=0):
remainder=number%10
# This Statement changing the value of number variable so
number=number//10
# For keeping original Number we took it in a variable named a "x"
temp+=(remainder*remainder*remainder)
if(x==temp):
return True
return False
number=371
if(find_armstrong(number)):
print(number,"is an Armstrong number")
else:
print(number,"is not an Armstrong number")
view raw #PF-Assgn-45.py hosted with ❤ by GitHub

No comments:

Post a Comment

Write a python function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

Write a python function,  find_correct()  which accepts a dictionary and returns a list as per the rules mentioned below. The input diction...