質問編集履歴
7
自分の結果を他の方に知らせて、他の方がどうすればいいのかがわかるようにしてみた。
title
CHANGED
File without changes
|
body
CHANGED
@@ -104,4 +104,24 @@
|
|
104
104
|
print(build_list)
|
105
105
|
^
|
106
106
|
SyntaxError: invalid character in identifier
|
107
|
+
```
|
108
|
+
|
109
|
+
すいません、皆さんの貴重なお時間を使わせていただいて、先程エラーが出たところを再度入力したらエラーが出てこなくなりました。しかしReturnを最後の文に入れたところOutputすら出なくなりました。何が原因なのでしょうか??
|
110
|
+
```
|
111
|
+
def build_list():
|
112
|
+
# create an empty list
|
113
|
+
build_list = []
|
114
|
+
# test all of the numbers through 500
|
115
|
+
# if they are a multiple of either 2 or 9, then add it onto the end of your list
|
116
|
+
for i in range(501):
|
117
|
+
if i % 2 == 0 or i % 9 == 0:
|
118
|
+
build_list.append(i)
|
119
|
+
print(build_list)
|
120
|
+
# compute the sum of all of the numbers in the list
|
121
|
+
print(sum(build_list))
|
122
|
+
# print the sum of all of the numbers in the list
|
123
|
+
|
124
|
+
# return the list (required to pass the tests)
|
125
|
+
print('The sum of the list should be 69806.')
|
126
|
+
return build_list()
|
107
127
|
```
|
6
自分の進捗を他の方に知らせた
title
CHANGED
File without changes
|
body
CHANGED
@@ -76,4 +76,32 @@
|
|
76
76
|
[0, 2, 4, 6, 8, 9]
|
77
77
|
[0, 2, 4, 6, 8, 9, 10]
|
78
78
|
[0, 2, 4, 6, 8, 9, 10, 12]
|
79
|
+
```
|
80
|
+
|
81
|
+
print(build_list)をfor文のあとに移動してみると
|
82
|
+
```
|
83
|
+
def build_list():
|
84
|
+
# create an empty list
|
85
|
+
build_list = []
|
86
|
+
# test all of the numbers through 500
|
87
|
+
# if they are a multiple of either 2 or 9, then add it onto the end of your list
|
88
|
+
for i in range(501):
|
89
|
+
if i % 2 == 0 or i % 9 == 0:
|
90
|
+
build_list.append(i)
|
91
|
+
print(build_list)
|
92
|
+
# compute the sum of all of the numbers in the list
|
93
|
+
print(sum(build_list))
|
94
|
+
# print the sum of all of the numbers in the list
|
95
|
+
|
96
|
+
# return the list (required to pass the tests)
|
97
|
+
print('The sum of the list should be 69806.')
|
98
|
+
build_list()
|
99
|
+
```
|
100
|
+
こうなりました。しかし同時にエラーコードも出てきました
|
101
|
+
```
|
102
|
+
Traceback (most recent call last):
|
103
|
+
File "python", line 9
|
104
|
+
print(build_list)
|
105
|
+
^
|
106
|
+
SyntaxError: invalid character in identifier
|
79
107
|
```
|
5
自分の進捗を他の方に知らせた
title
CHANGED
File without changes
|
body
CHANGED
@@ -45,4 +45,35 @@
|
|
45
45
|
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] 0
|
46
46
|
Outputはこんな形になりました。
|
47
47
|
|
48
|
-
Appendコードを使うことで数字が出てくるようになりましたが、答えがすごく長くなりました。これってくりかえしくり返しなっているということですよね?これを1回限りにするにはどうすればいいのでしょうか?
|
48
|
+
Appendコードを使うことで数字が出てくるようになりましたが、答えがすごく長くなりました。これってくりかえしくり返しなっているということですよね?これを1回限りにするにはどうすればいいのでしょうか?
|
49
|
+
|
50
|
+
コードをこのようにしてみました
|
51
|
+
```
|
52
|
+
def build_list():
|
53
|
+
# create an empty list
|
54
|
+
build_list = []
|
55
|
+
# test all of the numbers through 500
|
56
|
+
# if they are a multiple of either 2 or 9, then add it onto the end of your list
|
57
|
+
for i in range(501):
|
58
|
+
if i % 2 == 0 or i % 9 == 0:
|
59
|
+
build_list.append(i)
|
60
|
+
print(build_list)
|
61
|
+
# compute the sum of all of the numbers in the list
|
62
|
+
# print the sum of all of the numbers in the list
|
63
|
+
|
64
|
+
# return the list (required to pass the tests)
|
65
|
+
print('The sum of the list should be 69806.')
|
66
|
+
build_list()
|
67
|
+
```
|
68
|
+
|
69
|
+
Outputはこのように500まで数字が出てくるようになったのですが、それがいっぺんに出てこないです。
|
70
|
+
```
|
71
|
+
[0]
|
72
|
+
[0, 2]
|
73
|
+
[0, 2, 4]
|
74
|
+
[0, 2, 4, 6]
|
75
|
+
[0, 2, 4, 6, 8]
|
76
|
+
[0, 2, 4, 6, 8, 9]
|
77
|
+
[0, 2, 4, 6, 8, 9, 10]
|
78
|
+
[0, 2, 4, 6, 8, 9, 10, 12]
|
79
|
+
```
|
4
自分の進捗を他の方に知らせた
title
CHANGED
File without changes
|
body
CHANGED
@@ -43,4 +43,6 @@
|
|
43
43
|
|
44
44
|
The sum of the list should be 69806.
|
45
45
|
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] 0
|
46
|
-
Outputはこんな形になりました。
|
46
|
+
Outputはこんな形になりました。
|
47
|
+
|
48
|
+
Appendコードを使うことで数字が出てくるようになりましたが、答えがすごく長くなりました。これってくりかえしくり返しなっているということですよね?これを1回限りにするにはどうすればいいのでしょうか?
|
3
自分の結果を他の方に知らせて、他の方がどうすればいいのかがわかるようにしてみたお。
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,4 +39,8 @@
|
|
39
39
|
build_list()
|
40
40
|
```
|
41
41
|
|
42
|
-
このような形まで持っていけたのですが、どうすればよいのでしょうか?
|
42
|
+
このような形まで持っていけたのですが、どうすればよいのでしょうか?
|
43
|
+
|
44
|
+
The sum of the list should be 69806.
|
45
|
+
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] 0
|
46
|
+
Outputはこんな形になりました。
|
2
自分の進捗を他の方に知らせた
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,4 +17,26 @@
|
|
17
17
|
print('The sum of the list should be 69806.')
|
18
18
|
```
|
19
19
|
|
20
|
-
またこのコードではエラーも出ずどこを改善すればいいのかがわかりません。
|
20
|
+
またこのコードではエラーも出ずどこを改善すればいいのかがわかりません。
|
21
|
+
|
22
|
+
```
|
23
|
+
def build_list():
|
24
|
+
# create an empty list
|
25
|
+
build_list = []
|
26
|
+
# test all of the numbers through 500
|
27
|
+
# if they are a multiple of either 2 or 9, then add it onto the end of your list
|
28
|
+
for i in range(501):
|
29
|
+
if i % 2 == 0 or i % 9 == 0:
|
30
|
+
print(build_list, end = ' ')
|
31
|
+
# compute the sum of all of the numbers in the list
|
32
|
+
all = 0
|
33
|
+
for x in build_list:
|
34
|
+
all = all * x
|
35
|
+
# print the sum of all of the numbers in the list
|
36
|
+
print(all)
|
37
|
+
# return the list (required to pass the tests)
|
38
|
+
print('The sum of the list should be 69806.')
|
39
|
+
build_list()
|
40
|
+
```
|
41
|
+
|
42
|
+
このような形まで持っていけたのですが、どうすればよいのでしょうか?
|
1
Codeを使って見やすくしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
このコードは2と9の倍数を0〜500の数字から抜き取り、それをリスト化して抜き取った数字をすべて足すようにできています(自分の中では笑)。しかし全く動きません。何を試したらいいかもわからず色々調べてみたのですが、これにあったものがなかったため困っています。どこを改善すればよいのでしょうか?
|
2
|
+
```
|
2
3
|
def build_list():
|
3
4
|
build_list[s]
|
4
5
|
for s in range(0, 501):
|
@@ -14,5 +15,6 @@
|
|
14
15
|
return build_list
|
15
16
|
|
16
17
|
print('The sum of the list should be 69806.')
|
18
|
+
```
|
17
19
|
|
18
20
|
またこのコードではエラーも出ずどこを改善すればいいのかがわかりません。
|