模块不产生输出



下面是主要的驱动程序代码。

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..

这是你需要的吗?

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.nn" + 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 ju

最新更新