I am writing code using nesting lists as a grid system and am having trouble with something. Here is the code I'm using:
N = int(input(""))
Yard = \[\]
Yardhelper = \[\]
for n in range(0,N):
Yardhelper.append("")
for n in range(0,N):
Yard.append(Yardhelper)
for n in range(0,int(input(""))):
treepos = \[int(x) for x in input().split(" ")\]
Yard\[treepos\[0\]\] \[treepos\[1\]\] = 1
print(Yard)
the input format is
line 1: size of yard
line 2: number of trees
line 3+: coordinates for trees (input should be 'x y' (no quotes)
Try it yourself, I can't figure it out.
I poked around and found I can access the lists and read their values fine it's just writing in values. Let's say I give the input 3, then on the next line I want one tree so I put 1, then the next I put the coordinates: 0 1. It should give the result
[[0, 1, 0], [0, 0, 0], [0, 0, 0]]
but instead, it prints
[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
I don't know why this happens and neither do any of my friends, who are a bit better at coding than me. They all say my code looks good and are puzzled