是主要的驱动程序代码。
import Proj05Runner
str = 'The lazy brown fox jumped over the fence.'
subStr = 'fox'
result = Proj05Runner.run(str,subStr)
print(result)这里是我到目前为止需要使用驱动程序的模块的代码。
def run(str, subStr):
"""Returns a substring of any given string based upon a given range of characters before and after the substring"""
str_range = 3
if subStr in str:
str_modified = str[str.index(subStr) - str_range : str.index(subStr) + len(subStr) + str_range]
return ("I certify that this program is my own work " + "\n" + str + "\n" + subStr + "\n" + str_modified +
"and is not the work of others. I agree not " + "\n" + str + "\n" + subStr + "\n" + str_modified +
"to share my solution with others. " + "\n" + str + "\n" + subStr + "\n" + str_modified +
"Print your name here." + "\n" + str + "\n" + subStr + "\n" + str_modified)
else:
return "ERROR: subStr not found in str!"--例如,输出没有正确地产生
I certify that this program is my own work
The lazy brown fox jumped over the fence.
fox
wn fox juand is not the work of others. I agree not
The lazy brown fox jumped over the fence.
fox
wn fox juto share my solution with others.
The lazy brown fox jumped over the fence.
fox
wn fox juPrint your name here.
The lazy brown fox jumped over the fence.
fox
wn fox ju这里的输出我需要它来生产
I certify that this program is my own work
and is not the work of others. I agree not
to share my solution with others.
Print your name here.
The lazy brown fox jumped over the fence.
fox
wn fox ju
im sorry guys im new to this..发布于 2021-09-22 03:46:02
这就是你需要的吗:
def run(str, subStr):
"""Returns a substring of any given string based upon a given range of characters before and after the substring"""
str_range = 3
if subStr in str:
str_modified = str[str.index(subStr) - str_range : str.index(subStr) + len(subStr) + str_range]
return ("I certify that this program is my own work \nand is not the work of others. I agree not \nto share my solution with others.\nPrint your name here.\n\n" + str + "\n" + subStr + "\n" + str_modified)
else:
return "ERROR: subStr not found in str!"
str = 'The lazy brown fox jumped over the fence.'
subStr = 'fox'
out = run(str, subStr)
print (out)输出:
I certify that this program is my own work
and is not the work of others. I agree not
to share my solution with others.
Print your name here.
The lazy brown fox jumped over the fence.
fox
wn fox juhttps://stackoverflow.com/questions/69277250
复制相似问题