Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用python打印一个单词_Python_Regex_Printing_Substitution - Fatal编程技术网

用python打印一个单词

用python打印一个单词,python,regex,printing,substitution,Python,Regex,Printing,Substitution,你好,我想做一个函数,将使用增强(这只是改变了单词已经做了),并打印在一个给定的数字n的部分新词。S=test的示例我应该得到(“#t”,“#te”,“tes”,“est”,“st%”和“t%”) def增强(S,n): S=“#”*(n-1)+S+“%”*(n-1) 返回S def爆炸器(S、n): S=增强(S,n) x=0 对于范围内的i(n1个立即修复,而不是: for i in range (n <= len(S)): 这将为您提供范围n内的i值 输出: ##t #te t

你好,我想做一个函数,将使用增强(这只是改变了单词已经做了),并打印在一个给定的数字n的部分新词。S=test的示例我应该得到(“#t”,“#te”,“tes”,“est”,“st%”和“t%”)

def增强(S,n):
S=“#”*(n-1)+S+“%”*(n-1)
返回S
def爆炸器(S、n):
S=增强(S,n)
x=0

对于范围内的i(n1个立即修复,而不是:

  for i in range (n <= len(S)):
这将为您提供范围
n内的i值
输出:

##t
#te
tes
est
st%
t%%

还有一个问题在哪里?看起来类似于:但这样我就不会打印最后一个。@Alex oops,没有注意到。你只需要像我一样在
I
的范围内添加一个。这很有效,但我再打印一个。对不起,我是新手python@Alex只需调用
exploder
,不要
打印它,因为您正在打印它的内容eturns which is nothing.
exploder
自行打印。@Alex正确识别了代码的第二个问题。
print(exploder(S,n))
None
输出的来源。
  for i in range(n, len(S) + 1):
print(exploder(S,n))
exploder(S,n)
def enhance(S, n):
    S = "#" * (n - 1) + S + "%" * (n - 1)
    return S

def exploder(S, n):
    S = enhance(S, n)
    for i in range(len(S)-n+1):
        print(S[i:i+n])

S = "test"
n = 3
exploder(S, n)
##t
#te
tes
est
st%
t%%