du_chuan 2019-10-29 21:33
浏览 613

为啥会显示name error错误啊?

[Clang 6.0 (clang-600.0.57)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate elevation.py]
update_elevation(THREE_BY_THREE_COPY, [1, 0], [1, 1], -2)
Traceback (most recent call last):
Python Shell, prompt 2, line 1
builtins.NameError: name 'THREE_BY_THREE_COPY' is not defined

def update_elevation(elevation_map: List[List[int]], start: List[int],
stop: List[int], delta: int) -> None:
"""Modify elevation map elevation_map so that the elevation of each
cell between cells start and stop, inclusive, changes by amount
delta.

Precondition: elevation_map is a valid elevation map.
              start and stop are valid cells in elevation_map.
              start and stop are in the same row or column or both.
              If start and stop are in the same row,
                  start's column <=  stop's column.
              If start and stop are in the same column,
                  start's row <=  stop's row.
              elevation_map[i, j] + delta >= 1
                  for each cell [i, j] that will change.

>>> THREE_BY_THREE_COPY = [[1, 2, 1],
...                        [4, 6, 5],
...                        [7, 8, 9]]
>>> update_elevation(THREE_BY_THREE_COPY, [1, 0], [1, 1], -2)
>>> THREE_BY_THREE_COPY
[[1, 2, 1], [2, 4, 5], [7, 8, 9]]
>>> FOUR_BY_FOUR_COPY = [[1, 2, 6, 5],
...                      [4, 5, 3, 2],
...                      [7, 9, 8, 1],
...                      [1, 2, 1, 4]]
>>> update_elevation(FOUR_BY_FOUR_COPY, [1, 2], [3, 2], 1)
>>> FOUR_BY_FOUR_COPY
[[1, 2, 6, 5], [4, 5, 4, 2], [7, 9, 9, 1], [1, 2, 2, 4]]

"""
THREE_BY_THREE_COPY = [[1, 2, 1],
...                    [4, 6, 5],
...                    [7, 8, 9]]
FOUR_BY_FOUR_COPY =  [[1, 2, 6, 5],
...                   [4, 5, 3, 2],
...                   [7, 9, 8, 1],
...                   [1, 2, 1, 4]]
if start[0]==stop[0]:
    for num in range(stop[1]-start[1]):
        elevation_map[start[0]][start[1+i]]=elevation_map[start[0]][start[1+i]]+delta
else:
    for num in range(stop[0]-start[0]):
        elevation_map[start[0]][start[1+i]]=elevation_map[start[0+i]][start[1]]+delta
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在若依框架下实现人脸识别
    • ¥15 网络科学导论,网络控制
    • ¥100 安卓tv程序连接SQLSERVER2008问题
    • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
    • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
    • ¥15 关于arduino编程toCharArray()函数的使用
    • ¥100 vc++混合CEF采用CLR方式编译报错
    • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
    • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
    • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同