Python – Print a word in part of python

Print a word in part of python… here is a solution to the problem.

Print a word in part of python

Hello, I would like to create a function that will use enhance (it just changes the word that has already been created) and print a new word in the part of the given number n. For the example of S=test, I should get (‘##t’, ‘#te’, ‘tes’, ‘est’, ‘st%’, ‘t%%’).

def enhance(S,n):
    S = "#"*(n-1)+S+"%"*(n-1)
    return S

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

S="test"
n = 3
for n in range (0,n):
    print(exploder(S,n))
    n=n+1
print(exploder(S,n))

Solution

Fix it now. Instead of:

  for i in range (n <= len(S)):

I think you want:

  for i in range(n, len(S) + 1):

This will give you the value of i in the range n < = i < len(s).

Also, as Alex Hall suggested, change:

print(exploder(S,n))

Just:

exploder(S,n)

The exploder function returns None. So that print is the source of your fake None output.

Related Problems and Solutions