- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to check whether given number is Narcissistic number or not in Python
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 −
- s := a list of digits in of n
- return true if n is same as sum of x*(size of s) for all x in s, otherwise false
Let us see the following implementation to get better understanding −
Example
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))
Input
9474
Output
True
- Related Articles
- How To Check Whether a Number is a Narcissistic Number or Not in Java?
- Check whether the given number is Euclid Number or not in Python
- Program to check whether the given number is Buzz Number or not in C++
- Write a Golang program to check whether a given number is prime number or not
- Check whether the given number is Wagstaff prime or not in Python
- Program to check whether a number is Proth number or not in C++
- 8085 program to check whether the given 16 bit number is palindrome or not
- Check if given number is Emirp Number or not in Python
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Number is Prime or Not
- Write a Golang program to check whether a given number is a palindrome or not
- Program to check a number is ugly number or not in Python
- Program to check whether given graph is bipartite or not in Python

Advertisements