# Python: Check whether a given number is a narcissistic number or not

## Python Basic - 1: Exercise-96 with Solution

Write a Python program to check whether a given number is a narcissistic number or not.

If you are a reader of Greek mythology, then you are probably familiar with Narcissus. He was a hunter of exceptional beauty that he died because he was unable to leave a pool after falling in love with his own reflection. That's why I keep myself away from pools these days (kidding).

In mathematics, he has kins by the name of narcissistic numbers — numbers that can't get enough of themselves. In particular, they are numbers that are the sum of their digits when raised to the power of the number of digits.

For example, 371 is a narcissistic number; it has three digits, and if we cube each digits 3^{3} + 7^{3} + 1^{3} the sum is 371. Other 3-digit narcissistic numbers are

153 = 1^{3} + 5^{3} + 3^{3}

370 = 3^{3} + 7^{3} + 0^{3}

407 = 4^{3} + 0^{3} + 7^{3}.

There are also 4-digit narcissistic numbers, some of which are 1634, 8208, 9474 since

1634 = 1^{4}+6^{4}+3^{4}+4^{4}

8208 = 8^{4}+2^{4}+0^{4}+8^{4}

9474 = 9^{4}+4^{4}+7^{4}+4^{4}

It has been proven that there are only 88 narcissistic numbers (in the decimal system) and that the largest of which is

115,132,219,018,763,992,565,095,597,973,971,522,401

has 39 digits.

Ref:: //https://bit.ly/2qNYxo2

**Sample Solution**:

**Python Code:**

```
def is_narcissistic_num(num):
return num == sum([int(x) ** len(str(num)) for x in str(num)])
print(is_narcissistic_num(153))
print(is_narcissistic_num(370))
print(is_narcissistic_num(407))
print(is_narcissistic_num(409))
print(is_narcissistic_num(1634))
print(is_narcissistic_num(8208))
print(is_narcissistic_num(9474))
print(is_narcissistic_num(9475))
```

Sample Output:

True True True False True True True False

**Pictorial Presentation:**

**Flowchart:**

**Python Code Editor:**

**Have another way to solve this solution? Contribute your code (and comments) through Disqus.**

**Previous:** Write a Python program to check whether every even index contains an even number and every odd index contains odd number of a given list.

**Next:** Write a Python program to find the highest and lowest number from a given string of space separated integers.

**What is the difficulty level of this exercise?**

Test your Programming skills with w3resource's quiz.

**Weekly Trends**- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join