|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>>> def Findstr(father,son):
s = 0
i = 0
while i < len(father):
print (father[i]+father[i+1])
if (father[i]+father[i+1]) == son:
s += 1
i += 1
print ("son appear ",s,'times')
请问各位大神这里的循环出啥问题了,为什么结果是这样(如下)
>>> Findstr('you can not improve your past , but you can improve your future . once time is wasted ,life is wasted ','im')
yo
yo
yo
yo
。。。。。。(无数个yo)
还有
>>> def Findstr(father,son):
s = 0
i = 0
for each in father:
if (father[i]+father[i+1]) == son:
s += 1
i += 1
print ("son appear ",s,'times')
为啥两个都循环不起来
#你的if 条件都满足不了,i怎么增加的?正确代码已经附上 - def Findstr(father,son):
- s = 0
- i = 0
- while i < len(father)-1:
- if (father[i]+father[i+1]) == son:
- s += 1
- i += 1
- print ("son appear ",s,'times')
-
- print( Findstr('you can not improve your past , but you can improve your future . once time is wasted ,life is wasted ','im'))
复制代码
|
|