import kotlin.random.Random fun main() { var guess:Int? var targetNum=Random.nextInt(1,100) var attempts=0 do{ guess=readLine()?.toIntOrNull(); attempts++ if(guess==null){ println("Enter valid number") } else{ when{ guess < targetNum -> println("Too low") guess > targetNum -> println("To high") else->println("Your have guess the nummber in $attempts attempts") } } } while(guess!=targetNum && guess != null) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter