One of the primary reasons I started programming was a textbook: When I was 12, back in 1988, we had a mathematics textbook that included short but self-contained programs. I and a few friends came together and tried out those programs. It made sense and was a lot of fun. We got into programming.
I don’t see such textbooks anymore. But I’m just one person with limited reach to many countries, their schools and books.
Why don’t you help us find out if there are such books, in any subject matter, that include short program source code samples at the end of their chapters?