--- id: 69cfca90e8a0a6d4d6871c52 title: "Challenge 268: Narcissistic Number" challengeType: 29 dashedName: challenge-268 --- # --description-- Given a positive integer, determine whether it is a narcissistic number. - A number is narcissistic if the sum of each of its digits raised to the power of the total number of digits equals the number itself. For example, 153 has 3 digits, and 13 + 53 + 33 = 153, so it is narcissistic. # --hints-- `is_narcissistic(153)` should return `True`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(153), True)`) }}) ``` `is_narcissistic(154)` should return `False`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(154), False)`) }}) ``` `is_narcissistic(371)` should return `True`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(371), True)`) }}) ``` `is_narcissistic(512)` should return `False`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(512), False)`) }}) ``` `is_narcissistic(9)` should return `True`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(9), True)`) }}) ``` `is_narcissistic(11)` should return `False`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(11), False)`) }}) ``` `is_narcissistic(9474)` should return `True`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(9474), True)`) }}) ``` `is_narcissistic(6549)` should return `False`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertIs(is_narcissistic(6549), False)`) }}) ``` # --seed-- ## --seed-contents-- ```py def is_narcissistic(n): return n ``` # --solutions-- ```py def is_narcissistic(n): digits = str(n) power = len(digits) return sum(int(d) ** power for d in digits) == n ```