Decode Digital Clock - Wipro
Decode Digital Clock - Wipro
Problem:
The program must accept an integer X representing the encoded key of a digital lock. There are two ways to decode the key of the digital lock. - If X is an armstrong number, then the key is the sum of even digits in the encoded key. - If X is not an armstrong number, then the key is the sum of odd digits in the encoded key. An armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits in the number. The program must decode the key X and print it as the output.
Input:
1634
Output:
10
Program:
def is_armstrong(number):
power = len(str(number))
temp = number
total = 0
while number > 0:
total += (number%10)**power
number //= 10
return total != temp
number = int(input())
result = is_armstrong(number)
decode = 0
while(number > 0):
if (number%10)%2 == result:
decode += number%10
number //= 10
print(decode)
Comments
Post a Comment