質問編集履歴

7

自分の結果を他の方に知らせて、他の方がどうすればいいのかがわかるようにしてみた。

2020/05/09 22:12

投稿

Spursfun2002
Spursfun2002

スコア15

test CHANGED
File without changes
test CHANGED
@@ -211,3 +211,43 @@
211
211
  SyntaxError: invalid character in identifier
212
212
 
213
213
  ```
214
+
215
+
216
+
217
+ すいません、皆さんの貴重なお時間を使わせていただいて、先程エラーが出たところを再度入力したらエラーが出てこなくなりました。しかしReturnを最後の文に入れたところOutputすら出なくなりました。何が原因なのでしょうか??
218
+
219
+ ```
220
+
221
+ def build_list():
222
+
223
+ # create an empty list
224
+
225
+ build_list = []
226
+
227
+ # test all of the numbers through 500
228
+
229
+ # if they are a multiple of either 2 or 9, then add it onto the end of your list
230
+
231
+ for i in range(501):
232
+
233
+ if i % 2 == 0 or i % 9 == 0:
234
+
235
+ build_list.append(i)
236
+
237
+ print(build_list)
238
+
239
+ # compute the sum of all of the numbers in the list
240
+
241
+ print(sum(build_list))
242
+
243
+ # print the sum of all of the numbers in the list
244
+
245
+
246
+
247
+ # return the list (required to pass the tests)
248
+
249
+ print('The sum of the list should be 69806.')
250
+
251
+ return build_list()
252
+
253
+ ```

6

自分の進捗を他の方に知らせた

2020/05/09 22:12

投稿

Spursfun2002
Spursfun2002

スコア15

test CHANGED
File without changes
test CHANGED
@@ -155,3 +155,59 @@
155
155
  [0, 2, 4, 6, 8, 9, 10, 12]
156
156
 
157
157
  ```
158
+
159
+
160
+
161
+ print(build_list)をfor文のあとに移動してみると
162
+
163
+ ```
164
+
165
+ def build_list():
166
+
167
+ # create an empty list
168
+
169
+ build_list = []
170
+
171
+ # test all of the numbers through 500
172
+
173
+ # if they are a multiple of either 2 or 9, then add it onto the end of your list
174
+
175
+ for i in range(501):
176
+
177
+ if i % 2 == 0 or i % 9 == 0:
178
+
179
+ build_list.append(i)
180
+
181
+  print(build_list)
182
+
183
+ # compute the sum of all of the numbers in the list
184
+
185
+ print(sum(build_list))
186
+
187
+ # print the sum of all of the numbers in the list
188
+
189
+
190
+
191
+ # return the list (required to pass the tests)
192
+
193
+ print('The sum of the list should be 69806.')
194
+
195
+ build_list()
196
+
197
+ ```
198
+
199
+ こうなりました。しかし同時にエラーコードも出てきました
200
+
201
+ ```
202
+
203
+ Traceback (most recent call last):
204
+
205
+ File "python", line 9
206
+
207
+ print(build_list)
208
+
209
+ ^
210
+
211
+ SyntaxError: invalid character in identifier
212
+
213
+ ```

5

自分の進捗を他の方に知らせた

2020/05/09 22:00

投稿

Spursfun2002
Spursfun2002

スコア15

test CHANGED
File without changes
test CHANGED
@@ -93,3 +93,65 @@
93
93
 
94
94
 
95
95
  Appendコードを使うことで数字が出てくるようになりましたが、答えがすごく長くなりました。これってくりかえしくり返しなっているということですよね?これを1回限りにするにはどうすればいいのでしょうか?
96
+
97
+
98
+
99
+ コードをこのようにしてみました
100
+
101
+ ```
102
+
103
+ def build_list():
104
+
105
+ # create an empty list
106
+
107
+ build_list = []
108
+
109
+ # test all of the numbers through 500
110
+
111
+ # if they are a multiple of either 2 or 9, then add it onto the end of your list
112
+
113
+ for i in range(501):
114
+
115
+ if i % 2 == 0 or i % 9 == 0:
116
+
117
+ build_list.append(i)
118
+
119
+ print(build_list)
120
+
121
+ # compute the sum of all of the numbers in the list
122
+
123
+ # print the sum of all of the numbers in the list
124
+
125
+
126
+
127
+ # return the list (required to pass the tests)
128
+
129
+ print('The sum of the list should be 69806.')
130
+
131
+ build_list()
132
+
133
+ ```
134
+
135
+
136
+
137
+ Outputはこのように500まで数字が出てくるようになったのですが、それがいっぺんに出てこないです。
138
+
139
+ ```
140
+
141
+ [0]
142
+
143
+ [0, 2]
144
+
145
+ [0, 2, 4]
146
+
147
+ [0, 2, 4, 6]
148
+
149
+ [0, 2, 4, 6, 8]
150
+
151
+ [0, 2, 4, 6, 8, 9]
152
+
153
+ [0, 2, 4, 6, 8, 9, 10]
154
+
155
+ [0, 2, 4, 6, 8, 9, 10, 12]
156
+
157
+ ```

4

自分の進捗を他の方に知らせた

2020/05/09 21:40

投稿

Spursfun2002
Spursfun2002

スコア15

test CHANGED
File without changes
test CHANGED
@@ -89,3 +89,7 @@
89
89
  [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] 0
90
90
 
91
91
  Outputはこんな形になりました。
92
+
93
+
94
+
95
+ Appendコードを使うことで数字が出てくるようになりましたが、答えがすごく長くなりました。これってくりかえしくり返しなっているということですよね?これを1回限りにするにはどうすればいいのでしょうか?

3

自分の結果を他の方に知らせて、他の方がどうすればいいのかがわかるようにしてみたお。

2020/05/09 21:31

投稿

Spursfun2002
Spursfun2002

スコア15

test CHANGED
File without changes
test CHANGED
@@ -81,3 +81,11 @@
81
81
 
82
82
 
83
83
  このような形まで持っていけたのですが、どうすればよいのでしょうか?
84
+
85
+
86
+
87
+ The sum of the list should be 69806.
88
+
89
+ [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] 0
90
+
91
+ Outputはこんな形になりました。

2

自分の進捗を他の方に知らせた

2020/05/09 20:49

投稿

Spursfun2002
Spursfun2002

スコア15

test CHANGED
File without changes
test CHANGED
@@ -37,3 +37,47 @@
37
37
 
38
38
 
39
39
  またこのコードではエラーも出ずどこを改善すればいいのかがわかりません。
40
+
41
+
42
+
43
+ ```
44
+
45
+ def build_list():
46
+
47
+ # create an empty list
48
+
49
+ build_list = []
50
+
51
+ # test all of the numbers through 500
52
+
53
+ # if they are a multiple of either 2 or 9, then add it onto the end of your list
54
+
55
+ for i in range(501):
56
+
57
+ if i % 2 == 0 or i % 9 == 0:
58
+
59
+ print(build_list, end = ' ')
60
+
61
+ # compute the sum of all of the numbers in the list
62
+
63
+ all = 0
64
+
65
+ for x in build_list:
66
+
67
+ all = all * x
68
+
69
+ # print the sum of all of the numbers in the list
70
+
71
+ print(all)
72
+
73
+ # return the list (required to pass the tests)
74
+
75
+ print('The sum of the list should be 69806.')
76
+
77
+ build_list()
78
+
79
+ ```
80
+
81
+
82
+
83
+ このような形まで持っていけたのですが、どうすればよいのでしょうか?

1

Codeを使って見やすくしました。

2020/05/09 20:47

投稿

Spursfun2002
Spursfun2002

スコア15

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,6 @@
1
1
  このコードは2と9の倍数を0〜500の数字から抜き取り、それをリスト化して抜き取った数字をすべて足すようにできています(自分の中では笑)。しかし全く動きません。何を試したらいいかもわからず色々調べてみたのですが、これにあったものがなかったため困っています。どこを改善すればよいのでしょうか?
2
+
3
+ ```
2
4
 
3
5
  def build_list():
4
6
 
@@ -30,6 +32,8 @@
30
32
 
31
33
  print('The sum of the list should be 69806.')
32
34
 
35
+ ```
36
+
33
37
 
34
38
 
35
39
  またこのコードではエラーも出ずどこを改善すればいいのかがわかりません。