Graderpractice for programmers

273387 Kotlin - Functions (part 1)

Awaiting submission
You can calculate your Body Mass Index (BMI) by dividing your weight by the square of your height. Here is an implementation of this function in Kotlin:
fun bmi(weight: Double, height: Double): Double {
    val heightM = height / 100.0
    return weight / (heightM * heightM)
}

Write a program that asks for your weight and height, and outputs your BMI (using the above function).

Awaiting submission
Write a program that reads in a list of grades (integers, one per line) and then calculates the average of all the grades (double). The end of the list of grades will be the string "q". Start with the following template and write a function to calculate the average.
fun main(args: Array) {
    println("Enter your grades: (q to end)")
    var grades = mutableListOf()
    while (true) {
        val input = readLine()
        if (input == "q") {
            // TODO call a function to calculate the average
            println("Average is ?")
            return
        }
        val num = input?.toIntOrNull()
        if (num != null) {
            grades.add(num)
        }
    }
}
Awaiting submission
Write a program that reads in a list of words (one per line) and then prints them all in reverse order. The program should contain the function fun printReversed(list: List).