首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不产生输出的模块

不产生输出的模块
EN

Stack Overflow用户
提问于 2021-09-22 01:44:48
回答 1查看 25关注 0票数 1

是主要的驱动程序代码。

代码语言:javascript
复制
import Proj05Runner

str = 'The lazy brown fox jumped over the fence.'
subStr = 'fox'
result = Proj05Runner.run(str,subStr)
print(result)

这里是我到目前为止需要使用驱动程序的模块的代码。

代码语言:javascript
复制
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!"

--例如,输出没有正确地产生

代码语言:javascript
复制
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

这里的输出我需要它来生产

代码语言:javascript
复制
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..
EN

回答 1

Stack Overflow用户

发布于 2021-09-22 03:46:02

这就是你需要的吗:

代码语言:javascript
复制
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)

输出:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69277250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档