-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_Number89.py
More file actions
67 lines (41 loc) · 1.7 KB
/
04_Number89.py
File metadata and controls
67 lines (41 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
# =============================================================================
# testing codes
# =============================================================================
#int(str(89)[0])**1 + int(str(89)[1])**2
def sum_dig_pow(a, b):
the_list = []
for i in range(a, b+1):
if len(str(i)) == 1:
if i**1 == i:
the_list.append(i)
elif len(str(i)) == 2:
if int(str(i)[0])**1 + int(str(i)[1])**2 == i:
the_list.append(i)
elif len(str(i)) == 3:
if int(str(i)[0])**1 + int(str(i)[1])**2 + int(str(i)[2])**3 == i:
the_list.append(i)
elif len(str(i)) == 4:
if int(str(i)[0])**1 + int(str(i)[1])**2 + int(str(i)[2])**3 + int(str(i)[3])**4 == i:
the_list.append(i)
return the_list
sum_dig_pow(89, 135)
# =============================================================================
# BELOW CODE IS THE ONES
# =============================================================================
def sum_num(i):
a_num = 0
for N in range( 1, len(str(i)) + 1 ):
a_num += int(str(i)[N-1]) ** N
if a_num == i:
return a_num
def sum_dig_pow(a, b):
the_list = []
for i in range(a, b+1):
the_list.append( sum_num(i) )
return [x for x in the_list if x is not None]
sum_dig_pow(1, 1000)