该代码是搜索一个substring...the代码采取在2 inputs...the第二个字符串是用来搜索...即第二个字符串是较小的长度。
a=input("Enter the 1st string") //Giving error here
b=input("Enter the second string")
com=""
for x in range(0,len(a)):
com=""
for j in range(x,len(b)+x):
com=com+a[j]
if(com==b):
print "Match Found at" + str(x)
else:
continue
代码执行compile....pls帮助
发布于 2010-08-16 15:59:10
如果你使用的是Python2.x,你需要使用raw_input
,而不是input
。input
会尝试计算您输入的内容,就好像它是Python代码一样。在Python 3中就不再是这样了。
另一件显而易见的事情是:
if(com==b):
print "Match Found at" + str(x)
else:
continue
..。需要像这样缩进:
if(com==b):
print "Match Found at" + str(x)
else:
continue
发布于 2010-08-16 16:00:08
https://stackoverflow.com/questions/3494914
复制相似问题