Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Middle Characters by Red_Ale
def middle(text):
if len(text) < 3: return text
a = len(text)//2
return text[a-1:a+1] if len(text)%2 == 0 else text[a]
if __name__ == '__main__':
print("Example:")
print(middle('example'))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert middle('example') == 'm'
assert middle('test') == 'es'
assert middle('very-very long sentence') == 'o'
assert middle('I') == 'I'
assert middle('no') == 'no'
print("Coding complete? Click 'Check' to earn cool rewards!")
July 14, 2022
Comments: