Create NarcissisticNum.py

Get the narcissistic number
pull/189/head
catmemo 2019-06-09 12:45:17 +08:00 committed by GitHub
parent c2895d7cc0
commit f772f71b59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
"""
水仙花数Narcissistic number也被称为超完全数字不变数pluperfect digital invariant, PPDI
自恋数自幂数阿姆斯壮数或阿姆斯特朗数Armstrong number水仙花数是指一个 3 位数
它的每个位上的数字的 3次幂之和等于它本身例如1^3 + 5^3+ 3^3 = 153
Version: 0.1
Author: Ifan
Date: 2019-06-09
"""
import math
for i in range(1000):
if len(str(i)) == 1:
if i**3 == i:
print(i)
elif len(str(i)) == 2:
if int(str(i)[0])**3 + int(str(i)[1])**3 == i:
print(i)
elif len(str(i)) == 3:
if int(str(i)[0])**3 + int(str(i)[1])**3 + int(str(i)[2])**3 == i:
print(i)
else:
print("There are not Narcissistic Number")