Answer:
See explaination
Step-by-step explanation:
def remove_italicized_text(x):
ans = ""
n = len(x) # length of string
i = 0
while i < n:
if x[i:(i+3)] == "<i>": # check for opening italic html tag
i += 3
cur = ""
while i < n:
if x[i:(i+4)] == "</i>": # check for closing italic html tag
break
cur += x[i]
i += 1
i += 4
ans += cur # add the text between two tags into output string
ans += " " # adding a space between two next
ans += cur # add the text again
else:
ans += x[i]
i += 1
return ans
sentence = "<i>Stony Brook</i>"
print("sentence = " + sentence)
print("Return value: " + remove_italicized_text(sentence))
print("\\")
sentence = "I <i>love</i> SBU, yes I do!"
print("sentence = " + sentence)
print("Return value: " + remove_italicized_text(sentence))
print("\\")
sentence = "Hey <i>Wolfie</i>, he's so fine, we hug him <i>all the time</i>!"
print("sentence = " + sentence)
print("Return value: " + remove_italicized_text(sentence))
print("\\")
sentence = "This text has no italics tags."
print("sentence = " + sentence)
print("Return value: " + remove_italicized_text(sentence))
print("\\")