It says Python indentation error, but I don't know what's wrong.

Asked 2 years ago, Updated 2 years ago, 20 views

col, row = map(int,input().split())
x = [-1, 0, 1, 1]
y = [0, 1, 0, 1]
cnt = 0
mat = []
for i in range(row):
    mat.append(list(input()))

for i in range(row):
    for j in range(col):
        if(mat[i][j] == '.'):
            for k in range(4):
                if(i+x[k]<0 or i+x[k] >= col or j+y[k]<0 or j+y[k] >= row):
                    continue
                if(mat[i+x[k]][j+y[k]]=='*'):
                    cnt+=1
            mat[i][j] = cnt
            cnt = 0

print(mat)

The original code is For kin range(4): This part and If(mat[i][j] == '.'): This is the changed code When I changed these two lines, there was an indentation error I don't know which part is wrong.;

python

2022-09-22 15:23

1 Answers

Python is an important language to indent, so it distinguishes between tab and space.

In other words, if you indent with a tab, you have to tap everything. If you put four spaces, it's a grammar error.

An easy way to solve this problem is to collectively change all spaces to spaces or tabs in an advanced editor (vim, UltraEdit, NotePad++, Eclipse, etc.).


2022-09-22 15:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.