Want to learn to code? Don't copy and paste, type out other people's code
When learning code out of a book for a new language, one trick I found that worked really well was to read the code, then close the book and try to type as much of it from memory as I could.  I would futz with it for several minutes exploring various ways of making it break, seeing if I could 1) predict how I was breaking it, and 2) use the error messages to fix my mistakes.Then I would open up the book again and compare it to what I had typed, examine the differences between them, and see if/how they explained the errors I was getting.