I'm alive!

Report a typo

Ryan Gosling divided his films into three categories: those where he is alive, those where he is dead, and Drive (null). You need to write a program that receives a film name from standard input, checks the category of that film, assigns a value to the Boolean? variable amIAlive, and prints the result:

If amIAlive is true — print "I'm alive!"

If amIAlive is false — print "I'm dead man, guys"

If amIAlive is null — print "Unbelievable! I'm Shroedinger's Ryan!"

Please insert a suitable scope function instead of <scope function>.

Sample Input 1:

Drive

Sample Output 1:

Unbelievable! I'm Shroedinger's Ryan!
Write a program in Kotlin
fun main() {
val amIAlive: Boolean?
val aliveFilms = listOf("The Believer", "Half Nelson", "Fracture", "Lars and the Real Girl")
val deadFilms = listOf("Stay", "The Notebook", "The Place Beyond the Pines", "Blade Runner 2049")
val currentFilm = readln()

amIAlive = when (currentFilm) {
in aliveFilms -> true
in deadFilms -> false
else -> null
}

val conclude: String = amIAlive?.<scope function> {
if (amIAlive) "I'm alive!" else "I'm dead man, guys"
} ?: "Unbelievable! I'm Shroedinger's Ryan!"

println(conclude)
}
___

Create a free account to access the full topic