

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print Narcissistic(Armstrong) Numbers with Python?
To print Narcissistic Numbers, let's first look at the definition of it. It is a number that is the sum of its own digits each raised to the power of the number of digits. For example, 1, 153, 370 are all Narcissistic numbers. You can print these numbers by running the following code
def print_narcissistic_nums(start, end): for i in range(start, end + 1): # Get the digits from the number in a list: digits = list(map(int, str(i))) total = 0 length = len(digits) for d in digits: total += d ** length if total == i: print(i) print_narcissistic_nums(1, 380)
This will give the output
1 2 3 4 5 6 7 8 9 153 370 371
- Related Questions & Answers
- Java program to print the Armstrong numbers between two numbers
- How to generate armstrong numbers in Python?
- How to print all the Armstrong Numbers from 1 to 1000 using C#?
- Armstrong Numbers between two integers?
- C Program for Armstrong Numbers
- Armstrong numbers between a range - JavaScript
- JavaScript Narcissistic number
- Armstrong Number in Python
- Python Program to Check Armstrong Number
- Write a program in Python to filter armstrong numbers in a given series
- Java Program to Display Armstrong Numbers Between Intervals Using Function
- How to Humanize numbers with Python?
- Python Program to Print Numbers in an Interval
- Finding Armstrong numbers in a given range in JavaScript
- How to Print all Prime Numbers in an Interval using Python?
Advertisements