This was insightful, thanks for sharing!
In the early 90’s I remember owning and borrowing some novels that had BASIC code printed in them. These were small programs of no more than a few pages, usually at the end of a chapter, that would do things like output a story-relevant image or allow you to play a very simple game.
I only remember a few examples: One was at the end of a chapter in the middle of a book I borrowed from the library. The code would output an image of a ruby-eyed statue the characters had just discovered while exploring a South American jungle temple. The others were from the early titles in the Interplanetary Spy series, which was like a sci-fi version of the Choose Your Own Adventure books. There were codes that would generate a blocky image of your spaceship and a few things related to the puzzles in the book, but nothing that was actually required to figure them out. I only had access to a C64 for one summer so I never got to use most of these and the one time I tried I decided it wasn’t worth the effort required.
Adding on to the BASIC text adventure game my older brothers started was more fun, anyway.