Computer Science, asked by nanaakwesi93, 10 months ago

Suppose you are given a list of words, wordlist. Write Python code that will print one line for each word, with prefix and suffix sign *. The number of * of either prefix or suffix should be exactly equal to the length of that word. For example if worldList is [‘Jose’, ‘Sue’, ‘William’], then your code would print (Note: wordList is the variable containing those words)

****Jose****
***Sue***
*******William*******

Answers

Answered by Anonymous
1

def func(string):

# Used to store the starting and

# ending index of the substrings

start, end = 0, 0

while start < len(string):

# If substring is also the prefix

if string[end] == string[end-start]:

# Print the substring

print(string[start:end + 1], end= " ")

end += 1

if end == len(string):

start += 1

end = start

# Increment the starting

# index of the substring

else:

start += 1

end = start

if __name__ == "__main__":

string = "ababc"

func(string)

Similar questions