/**
 * This exercise requires appending elements to a list and accessing values in a dictionary.
 * Given an animal name and type, the goal is to append the animal name to the 'animalList'
 * and retrieve the corresponding type from the 'animalDict' using the animal name as the key.
 *
 * @param animalList A list containing animal names.
 * @param animalDict A dictionary containing animal names as keys and their corresponding types as values.
 * @param animalName The name of the animal to append to the list.
 * @param animalType The type of the animal to retrieve from the dictionary.
 * @return The message indicating success or failure. The message should contain the type of the animal retrieved.
 */
fun appendAnimalToList(animalList: MutableList<String>, animalDict: Map<String, String>, animalName: String, animalType: String): String {

    // Append the animalName to the animalList
    animalList.add(animalName)

    return try {
        // Retrieve the animalType from the animalDict using animalName as the key
        val retrievedType = animalDict[animalName]

        // Check if the retrieved type matches the specified animal type
        if (retrievedType == animalType) {
            "Successfully appended"
        } else {
            "Failed to append"
        }
    } catch (e: Exception) {
        "Failed to append"
    }
}
/**
 * This exercise requires appending elements to a list and accessing values in a dictionary.
 * Given an animal name and type, the goal is to append the animal name to the 'animalList'
 * and retrieve the corresponding type from the 'animalDict' using the animal name as the key.
 *
 * @param animalList A list containing animal names.
 * @param animalDict A dictionary containing animal names as keys and their corresponding types as values.
 * @param animalName The name of the animal to append to the list.
 * @param animalType The type of the animal to retrieve from the dictionary.
 * @return The message indicating success or failure. The message should contain the type of the animal retrieved.
 */
fun appendAnimalToList(animalList: MutableList<String>, animalDict: Map<String, String>, animalName: String, animalType: String): String {
/**
 * This exercise requires appending elements to a list and accessing values in a dictionary.
 * Given an animal name and type, the goal is to append the animal name to the 'animalList'
 * and retrieve the corresponding type from the 'animalDict' using the animal name as the key.
 *
 * @param animalList A list containing animal names.
 * @param animalDict A dictionary containing animal names as keys and their corresponding types as values.
 * @param animalName The name of the animal to append to the list.
 * @param animalType The type of the animal to retrieve from the dictionary.
 * @return The message indicating success or failure. The message should contain the type of the animal retrieved.
 */
fun appendAnimalToList(animalList: MutableList<String>, animalDict: Map<String, String>, animalName: String, animalType: String): String {

    // Append the animalName to the animalList
    animalList.add(animalName)

    return try {
        // Retrieve the animalType from the animalDict using animalName as the key
        val retrievedType = animalDict[animalName]

        // Check if the retrieved type matches the specified animal type
        if (retrievedType == animalType) {
            "Successfully appended"
        } else {
            "Failed to append"
        }
    } catch (e: Exception) {
        "Failed to append"
    }
}