/**
 * Given a list [lst] and an integer [n], appends the numbers from 1 to n (inclusive) to the end of the list.
 * Then, loops through the list and prints the square of each number in the list.
 *
 * @param lst A list of integers.
 * @param n An integer.
 * @throws IllegalArgumentException If n is not a positive integer.
 * @throws IllegalArgumentException If lst is not a list.
 */
fun appendAndLoop(lst: MutableList<Int>, n: Int) {

    require(lst is MutableList<Int>) { "lst must be a list" }
    require(n > 0) { "n must be a positive integer" }

    // Append numbers from 1 to n to the end of the list
    lst.addAll((1..n))

    // Loop through the list and print the square of each number
    lst.forEach { num ->
        val squared = num * num
        println(squared)
    }
}
/**
 * Given a list [lst] and an integer [n], appends the numbers from 1 to n (inclusive) to the end of the list.
 * Then, loops through the list and prints the square of each number in the list.
 *
 * @param lst A list of integers.
 * @param n An integer.
 * @throws IllegalArgumentException If n is not a positive integer.
 * @throws IllegalArgumentException If lst is not a list.
 */
fun appendAndLoop(lst: MutableList<Int>, n: Int) {
/**
 * Given a list [lst] and an integer [n], appends the numbers from 1 to n (inclusive) to the end of the list.
 * Then, loops through the list and prints the square of each number in the list.
 *
 * @param lst A list of integers.
 * @param n An integer.
 * @throws IllegalArgumentException If n is not a positive integer.
 * @throws IllegalArgumentException If lst is not a list.
 */
fun appendAndLoop(lst: MutableList<Int>, n: Int) {

    require(lst is MutableList<Int>) { "lst must be a list" }
    require(n > 0) { "n must be a positive integer" }

    // Append numbers from 1 to n to the end of the list
    lst.addAll((1..n))

    // Loop through the list and print the square of each number
    lst.forEach { num ->
        val squared = num * num
        println(squared)
    }
}