質問編集履歴
2
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,7 +10,15 @@
|
|
10
10
|
othello.putcells()
|
11
11
|
```
|
12
12
|
一部抜き出しですが、上のコードに対して```NameError: name 'nums' is not defined```
|
13
|
-
というエラーが出ます。
|
13
|
+
というエラーが出ます。(正確には
|
14
|
+
```
|
15
|
+
Traceback (most recent call last):
|
16
|
+
File "Main.py", line 51, in <module>
|
17
|
+
othello.putcells()
|
18
|
+
File "Main.py", line 18, in putcells
|
19
|
+
for i in nums:
|
20
|
+
NameError: name 'nums' is not defined
|
21
|
+
```)
|
14
22
|
numsはclassの直下に置いたのでクラス内のすべての関数内で使えるクラス変数になっていると思ったのですが...
|
15
23
|
|
16
24
|
classを書いてみたのは初めてなので、非常に初歩的な問題ですが教えていただけると嬉しいです。
|
1
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
```
|
2
|
-
class Othello:
|
2
|
+
class Othello():
|
3
|
+
n = int(input())
|
4
|
+
nums = [input().split() for i in range(n)]
|
5
|
+
|
6
|
+
def putcells(self):
|
3
|
-
|
7
|
+
for i in nums:
|
4
8
|
|
9
|
+
othello = Othello()
|
5
|
-
|
10
|
+
othello.putcells()
|
6
|
-
for i in nums:
|
7
11
|
```
|
8
12
|
一部抜き出しですが、上のコードに対して```NameError: name 'nums' is not defined```
|
9
13
|
というエラーが出ます。
|