JetBrains offers a great online environment, Kotlin playground, where you can play around and share Kotlin code fragments. This environment offers an option to embed code fragments from the Kotlin Playground into your website using an iframe. This does not always play nicely with WordPress. Luckily there is a WordPress plugin available that allows for including runnable Kotlin code into your WordPress posts.
Tip from our side, try to edit in text mode only, we noticed that indentation is being stripped from the code snippets when using this plugin in the visual editor, which is rather annoying. You could also revert back to the classic editor in WordPress. See this github ticket for more details: https://github.com/Kotlin/kotlin-playground-wp-plugin/issues/9
Try the example below yourself:
The plugin can be downloaded from the Kotlin github page: https://github.com/Kotlin/kotlin-playground-wp-plugin