python basis ---- seeking the number of daffodils


Narcissistic number, i.e. a three-digit, each digit of the bit cubic sum equal to the number itself.
Such as: 1 = 153 ** 3 + 3 + 3 5 ** 3 **

. 1  DEF is_narc_num (n-):
 2      # IF n-<n-100 or> 999: 
. 3      #      return False 
. 4      # n-STR = (n-) 
. 5      # IF int (n-[0]). 3 ** + int (n-[. 1] ). 3 ** + int ([2]) == int **. 3 (n-) n-: 
. 6      #      return True 
. 7      # the else: 
. 8      #      return False 
. 9      "" " 
10          Analyzing any number, whether the number of daffodils (whether is the number of digits)
 . 11      : param n-:
 12 is      : return:
 13 is      "" " 
14      n-= STR (n-)
 15      length = len (n-)
 16     sum = 0
17     for i in range(length):
18         sum += int(n[i])**3
19     if sum == int(n):
20         return True
21     return False
22 
23 def list_narc_num(start,end):
24     list_narc = []
25     for i in range(start,end+1):
26         if is_narc_num(i):
27             list_narc.append(i)
28     return list_narc
29 
30 narc_num = list_narc_num(1,50000)
31 print(narc_num)

 

Guess you like

Origin www.cnblogs.com/jeffrey04118110/p/11828884.html