Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Between Markers (simplified) by Khrystyna11
def between_markers(text: str, start: str, end: str) -> str:
word = ""
word_started = False
i = 0
while i < len(text):
current_char = text[i]
if current_char == start:
word_started = True
# Дійшовши до кінцевого символу, результат має бути готовий
elif current_char == end:
return word
elif word_started == True:
word += current_char
i += 1
return word
print("Example:")
print(between_markers("What is >apple<", ">", "<"))
# These "asserts" are used for self-checking
assert between_markers("What is >apple<", ">", "<") == "apple"
assert between_markers("What is [apple]", "[", "]") == "apple"
assert between_markers("What is ><", ">", "<") == ""
assert between_markers("[an apple]", "[", "]") == "an apple"
print("The mission is done! Click 'Check Solution' to earn rewards!")
May 24, 2024
Comments: