You’ll often hear me say in class… practice, practice, and more practice. The reason for this is that you cannot learn programming by just reading a book. Therefore, I would like to explicitly draw attention to the following points:
- You should work on the numbered exercises until you have solved them. Do not dabble a bit and then look up the answer. Such an approach is utterly useless. There is no way that you are going to learn programming if you do not think about algorithms, write code, and test code. If you cannot solve an exercise even after you have worked on it for quite some time, it is better to ask for assistance than to just look up the answer. Being unable to solve an exercise means that there is something in the material that you have not grasped yet, and it is important that you identify what that is, and get to grips with it.
- You should do all of the exercises. The only way to learn programming is by practicing. You will have to write lots and lots of code before you have internalized the practice of programming. The few exercises that I place at the end of the chapters are not enough to accomplish that, but at least they are a start. If you cannot even bother to do all of those, you should not bother to try to learn programming.
- You should try to do the exercises independently. Working in teams on the exercises will allow one member of the team to learn, while the rest sits by and learns nothing. Students often say that they have a method of learning from assignments that involves working on them in small groups and discussing. That may be fine for analyzing texts or setting up an experiment, but in general does not work for coding. Watching someone write code teaches you very little about writing code. You have to write code by yourself.
- For none of the exercises you need information that was not discussed in the book up to that point. While there definitely may be easier ways to do some of the exercises if you would use Python constructs that I did not discuss yet at the time you get to the exercises, you do not need them. The purpose of the exercises is to practice with the discussed material. They are not meant to let you investigate future material. Even if you are aware of different ways to solve an exercise, try to do it with only the material discussed. Once you have done that, if you want to return to an exercise later and solve it in a different way, that is, of course, fine.
- Once you have solved an exercise by yourself and have tested it extensively, then and only then you should compare it to the answer that I provided. You may find that it is different from yours. That does not mean that your answer is wrong! There are usually very many ways to solve a programming problem. Some might be “better” in some way than others. But there are many answers that are equally correct. Moreover, in this book it is important that you learn to solve a problem by coding, not that you learn to code the most efficient solution to a problem. Just being able to solve the problem suffices, making solutions more efficient is of much lesser importance. For instance, “being efficient” is less important than “being easy to understand” and “being easy to maintain.”