回答編集履歴
1
追記
test
CHANGED
@@ -63,3 +63,87 @@
|
|
63
63
|
print(combination_sum(candidates, target))
|
64
64
|
|
65
65
|
```
|
66
|
+
|
67
|
+
**追記**
|
68
|
+
|
69
|
+
forループを再帰にする方法
|
70
|
+
|
71
|
+
```python
|
72
|
+
|
73
|
+
a = [11, 22, 33, 44]
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
for e in a:
|
78
|
+
|
79
|
+
print(e)
|
80
|
+
|
81
|
+
print('---')
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
for i in range(len(a)):
|
86
|
+
|
87
|
+
e = a[i]
|
88
|
+
|
89
|
+
print(e)
|
90
|
+
|
91
|
+
print('---')
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
def f(i):
|
96
|
+
|
97
|
+
if i < len(a):
|
98
|
+
|
99
|
+
e = a[i]
|
100
|
+
|
101
|
+
print(e)
|
102
|
+
|
103
|
+
f(i+1)
|
104
|
+
|
105
|
+
f(0)
|
106
|
+
|
107
|
+
print('---')
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
whileループを再帰にする方法
|
112
|
+
|
113
|
+
```python
|
114
|
+
|
115
|
+
a = []
|
116
|
+
|
117
|
+
i = 1
|
118
|
+
|
119
|
+
while sum(a) < 10:
|
120
|
+
|
121
|
+
print(i, a)
|
122
|
+
|
123
|
+
a.append(i)
|
124
|
+
|
125
|
+
i += 1
|
126
|
+
|
127
|
+
print('---')
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
a = []
|
132
|
+
|
133
|
+
def f(i):
|
134
|
+
|
135
|
+
if sum(a) < 10:
|
136
|
+
|
137
|
+
print(i, a)
|
138
|
+
|
139
|
+
a.append(i)
|
140
|
+
|
141
|
+
i += 1
|
142
|
+
|
143
|
+
f(i)
|
144
|
+
|
145
|
+
f(1)
|
146
|
+
|
147
|
+
print('---')
|
148
|
+
|
149
|
+
```
|