/**
 * Given a string and an index, return the word present at that index in the string.
 * If the index is invalid, return 'Invalid index!'.
 *
 * Example:
 * wordAtIndex("I am a photographer", 2) -> "a"
 * wordAtIndex("I am a photographer", 6) -> "Invalid index!"
 */
fun wordAtIndex(string: String, index: Int): String {

    // Obtain a list of words from the string, using space as a delimiter
    val words = string.split(" ")

    // Check if the index is within the valid range of word indices
    return if (index >= 0 && index < words.size) {
        words[index]
    } else {
        "Invalid index!"
    }
}
/**
 * Given a string and an index, return the word present at that index in the string.
 * If the index is invalid, return 'Invalid index!'.
 *
 * Example:
 * wordAtIndex("I am a photographer", 2) -> "a"
 * wordAtIndex("I am a photographer", 6) -> "Invalid index!"
 */
fun wordAtIndex(string: String, index: Int): String {
/**
 * Given a string and an index, return the word present at that index in the string.
 * If the index is invalid, return 'Invalid index!'.
 *
 * Example:
 * wordAtIndex("I am a photographer", 2) -> "a"
 * wordAtIndex("I am a photographer", 6) -> "Invalid index!"
 */
fun wordAtIndex(string: String, index: Int): String {

    // Obtain a list of words from the string, using space as a delimiter
    val words = string.split(" ")

    // Check if the index is within the valid range of word indices
    return if (index >= 0 && index < words.size) {
        words[index]
    } else {
        "Invalid index!"
    }
}