Returns the middle character of a given string.
The mid() function returns the middle character of a given string.If the string has an even number of characters, it returns an empty string.
If the string has an odd number of characters, it returns the single character that sits exactly in the middle.
- A variable found is initialized as an empty string.
- The function checks if the length of the word is even (len(word) % 2 == 0):
- If even, it immediately returns an empty string ("").
- If odd, it calculates the middle character’s position with:
- index = len(word)/2 + 0.5 - 1
- This formula ensures the result is centered for odd-length strings.
- The function converts the result to an integer and returns the character at that position.