【发布时间】:2016-04-01 08:35:45
【问题描述】:
问题本身在这里解释:s 是要搜索的字符串,目标是要查找的子字符串。打印目标开始的每个索引。
'''Exercise to complete printLocations as described below.
Create File locations.py.'''
def printLocations(s, target):
'''
s is a string to search through, and target is the substring to look for.
Print each index where the target starts.
For example:
>>> printLocations('Here, there, everywherel', 'ere')
1
8
20
'''
repetitions = s.count(target)
# ?? add initialization
for i in range(repetitions):
# ?? add loop body lines
def main():
phrase = 'Here, there, everywhere!'
print('Phrasez', phrase)
for target in ['ere', 'er', 'e', 'eh', 'zx']:
print('finding:', target)
printLocations(phrase, target)
print('All done!')
main()
【问题讨论】:
-
能否请您在此处粘贴您的代码而不是图片?
-
所以我已经编辑过了。怎么了?你到底想做什么?
-
@PashNeopane 您能否编辑您的问题以包含您作为 cmets 添加的其他信息? SO 希望问题能够独立存在,无需任何人阅读 cmets。
-
你可以就家庭作业寻求帮助,但你应该一些尝试自己编写一些相关的代码。不要只是在这里转储任务描述并期望我们完成所有工作。
-
@kevinguan 请不要进行掩饰问题是作业转储这一事实的编辑。
标签: python