Task

Write a game (computer program) that follows the following rules:

 The computer chooses a number between given set limits.
 The player is asked for repeated guesses until the the target number is guessed correctly
 At each guess, the computer responds with whether the guess is:
 higher than the target,
 equal to the target, 
 less than the target,   or
 the input was inappropriate. 


Related task

   Guess the number/With Feedback (Player)


import kotlin.random.Random
 
fun main() {
    val n = 1 + rand.nextInt(20)
    println("Guess which number I've chosen in the range 1 to 20\n")
    while (true) {
        print(" Your guess : ")
        val guess = readLine()?.toInt()
        when (guess) {
            n              ->  { println("Correct, well guessed!") ; return }
            in n + 1 .. 20 ->    println("Your guess is higher than the chosen number, try again")
            in 1 .. n - 1  ->    println("Your guess is lower than the chosen number, try again")
            else           ->    println("Your guess is inappropriate, try again")
        }
    }
}