It was not my fault no matter how much I thought about the Python the Python error that I couldn't understand

Asked 2 years ago, Updated 2 years ago, 23 views

a=int(input())
d=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

e=[c,c,c,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d,d]

for i in range(a):
    b , c=input().split(' ')
    b=int(b)
    print(b)
    c=int(c)
    print(c)
    e[b-1][c-1]=1
print(e)

This is the code, so if you enter the position where you put the white stone on the checkerboard 19*19, ex.

2   
4 6  
5 9

It's a code that says you'll put two white go eggs and put them at (4,6) (5,9) when you go and hit it's a code
The problem is that e[b-1][c-1]=1 is acting strangely.
e[b-1][c-1] If it's just one location, the entire line changes.
What did you do wrong?

python

2022-09-21 11:34

1 Answers

import print
a=int(input()) 
e = [[0 for col in range(10)] for row in range(10)]
for i in range(a):
    b , c=input().split(' ')
    b=int(b)
    c=int(c)
        print(b, c)
    e[b-1][c-1]=1

pprint.pprint(e)

1
4 6
4 6
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

I don't know the exact reason, but when it comes to initializing the arrangement, In the same or similar case as below, if you modify the specific value afterwards, it all changes collectively.

e = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]* 10


2022-09-21 11:34

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.