..The thing is that even these programs (which are exactly copy-paste from the book) cannot be executed and I have many fault messages in my terminal..
If I may add to what has been said in line with the quote above from your question. I will suggest you type out the code yourself instead of copy AND paste.
In my experience, when you copy from say pdf file, your text editor might not recognize the quotes and a number of letters properly. Some text editor will even tell you that, your code cannot be saved because you have "unicode" string in your file.
So, type out the codes you want to try and run it.
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me