I vote for both too.
Learning to code or a new tool or anything is a contact sport. You can read all the theory you want, but until you pick up an editor with, start using the commands, or sit down and put your fingers on the keys of a keyboard you haven’t really got anything down. Keeping a flow through the book of a examples that build on each other is great and having the occasional “You can also do this…” type thing to give people something to do is what I aim for.
You’ve given me an idea though for including “if you want to take it further” or “homework” sections at the end of each chapters which takes something that was learned and gives the reader an extra challenge if they want to tackle something else. Don’t know if it would work for the book I’m working on, but it might.