您好,我正在通过MIT 6.00 Intro to Computer Science练习Open course的练习题来学习python。
我试图做练习题1第2部分创建一个递归函数来计算目标中的键的实例。我的代码到目前为止...
from string import *
def countSubStringMatchRecursive (target, key,x,s):
if (find(target,key)==find(target,key,s)) and (find(target,key)==find(target,key,(find(target,key)))):#if first and last
return (1)
elif (find(target,key)==find(target,key,s))and (find(target,key)!=find(target,key,(find(target,key)))):#if first but not last
x=1
s= find(target,key)
return (countSubStringMatchRecursive(target,key,s,x)
elif (find(target,key,s))==-1 and (find(target,key)!=find(target,key,s)):#if last but not first
return (x+1)
elif:(find(target,key,s))!=-1 and (find(target,key)!=find(target,key,s)):#if not last and not first
x=x+1
s= find(target,key,s)
return (countSubStringMatchRecursive(target,key,s,x)我在第8行收到语法错误。我只想知道我在那里做了什么错误。不要担心我应该能够理清其他错误。我只是坚持这一点。谢谢。