File tree 1 file changed +9
-0
lines changed
1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,22 @@ def armstrong_number(n: int) -> bool:
41
41
temp //= 10
42
42
return n == sum
43
43
44
+ def narcissistic_number (n :int ) -> bool :
45
+ """Return True if n is a narcissistic number or False if it is not"""
46
+
47
+ expo = len (str (n )) #power, all number will be raised to
48
+ temp = [(int (i )** expo ) for i in str (n )] # each digit will be multiplied expo times
49
+
50
+ # check if sum of cube of each digit is equal to number
51
+ return n == sum (temp )
44
52
45
53
def main ():
46
54
"""
47
55
Request that user input an integer and tell them if it is Armstrong number.
48
56
"""
49
57
num = int (input ("Enter an integer to see if it is an Armstrong number: " ).strip ())
50
58
print (f"{ num } is { '' if armstrong_number (num ) else 'not ' } an Armstrong number." )
59
+ print (f"{ num } is { '' if narcissistic_number (num ) else 'not ' } an Armstrong number." )
51
60
52
61
53
62
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments