【发布时间】:2014-01-23 20:10:44
【问题描述】:
无论函数必须返回什么,我的代码似乎都没有正确调用第一个函数,因为当我尝试通过一些 doctest 时,它会引发错误:
File "preg3.py", line 27, in mesDivisions
if nombreDivisions(llista[0],m)>=nombreDivisions(llista[1],m):
NameError: global name 'nombreDivisions' is not defined
这是我的代码:
def nombreDivisons(n,m):
x=0
def aux(n,m):
if n<m:
return x
else:
if n%m==0:
x=x+1
return aux(n/m,m)
else:
return x
def mesDivisions(llista,m):
if len(llista)==1:
return llista[0],nombreDivisions(llista[0],m)
else:
if nombreDivisions(llista[0],m)>=nombreDivisions(llista[1],m):
del llista[1]
return mesDivisions(llista,m)
else:
del llista[0]
return mesDivisions(llista,m)
有什么想法吗?
【问题讨论】:
-
"nombreDivisons" != "nombreDivisions"