当我在我的程序中使用操作符in
来比较字符串时,它工作得很好,但是如果在我创建的模块中调用它,它似乎就不工作了。我知道我犯了一些错误,但不确定是什么,有人能帮我吗?你知道吗
这是我的密码:
模块:
def checkRoots(wordChecked, rootList):
numRoots = len(rootList);
numTypeRoots = createList(numRoots);
for z in range(0, numRoots):
root = rootList[z];
rootThere = root in word;
if rootThere == True:
numTypeRoots[z] = numTypeRoots[z] + 1;
return numTypeRoots;
但代码在不在模块中时仍然有效,如下所示:
for y in range (0, numRoots):
root = roots[y];
rootThere = root in word;
if rootThere == True:
numTypeRoots[y] = numTypeRoots[y] + 1;
Basic程序从文件中获取单词列表,然后查看单词中是否有特定的根。你知道吗
谢谢
函数正在执行
root in word
,但我认为您实际想要做的是root in wordChecked
全局变量是魔鬼。如果你能帮忙的话,最好避开它们。你知道吗
建议-如果编写其他人可能会看到的Python代码(提示:可能是任何/所有代码),最好通读并遵循PEP-8
相关问题 更多 >
编程相关推荐