Python-100-Days/Day01-15/code/Day05/NarcissisticNum.py

24 lines
779 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
水仙花数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")