索引错误:列表索引超出范围。第 7 行

m = [[1,2,3],

    [2,1,3],

    [5,4,3]]

for i in range(len(m)):

    for j in range(len(m)*len(m)):

        if i <= len(m) and j <= (len(m)*len(m)):

            m[i][j] <= m[i+1][j+1]

            is_sink = "True"

        if i <= (len(m)-1) and j <= (len(m)*len(m)):

            m[i][j] <= m[i+1][j]

            is_sink = "True"

        if i <= len(m) and j <= ((len(m)*len(m))-1):

            m[i][j] <= m[i][j+1]

            is_sink = "True"

        if i <= (len(m)-1) and j <= (len(m)*len(m)):

            m[i][j] <= m[i+1][j-1]

            is_sink = "True"

        if i <= len(m) and j <= (len(m)*len(m)):

            m[i][j] <= m[i-1][j+1]

            is_sink = "True"

        if i <= len(m) and j <= (len(m)*len(m)):

            m[i][j] <= m[i][j-1]

            is_sink = "True"

        if i <= len(m) and j <= (len(m)*len(m)):

            m[i][j] <= m[i-1][j]

            is_sink = "True"

        else:

            is_sink = "False"

我试图比较相邻的单元格以显示地图上的最低点。虽然它显示超出范围,但我不太确定如何正确表达范围。我确信这段代码可以减少,但这是我目前可以显示的最佳长度。


30秒到达战场
浏览 219回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python