以下代码给出了名称错误

时间:2014-10-15 04:07:07

标签: python-3.x

def cc(s1, s2):
    """
    >>> cc(ravioli, ratoli)
    raoli
    """
    str(s1)
    str(s2)
    pos = 0
    s = str()
    while pos <= len(s1):
        if s1[pos] == s2[:] and s1[pos] != s[:]:
            s = s + s1[pos]
            pos = pos + 1
        else:
            s = s
            pos = pos + 1

    return s

引发异常:

Traceback (most recent call last):
  File "/usr/lib/python3.4/doctest.py", line 1324, in __run
    compileflags, 1), test.globs)
  File "<doctest L1G10tardor12.cc[0]>", line 1, in <module>
    cc(ravioli, ratoli)
NameError: name 'ravioli' is not defined

1 个答案:

答案 0 :(得分:1)

是的,因为馄饨实际上是在该代码中无处定义的。发布的代码显然是错误的。也许它应该是这样的:

cc('ravioli', 'ratoli')