Suppose we have a number n; we have to check whether it is equal to the sum of the digits of n to the power of the number of digits.
So, if the input is like 9474, then the output will be True as 9^4 + 4^4 + 7^4 + 4^4 = 6561 + 256 + 2401 + 256 = 9474.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, n): s=str(n) return n==sum(int(x)**len(s) for x in s) ob = Solution() print(ob.solve(9474))