Congratulations! We’ve now covered enough fundamentals of Python (and programming in general) to start coding our first full program. In this chapter, we’re going to code a program that tests our understanding of the BODMAS rule of arithmetic calculation. If you are unsure what BODMAS is, you can check out this site http://www.mathsisfun.com/operation-order-bodmas.html.
Our program will randomly set an arithmetic question for us to answer. If we get the answer wrong, the program will display the correct answer and ask if we want to try a new question. If we get it correct, the program will compliment us and ask if we want a new question. In addition, the program will keep track of our scores and save the scores in an external text file. After each question, we can key “-1” to terminate the program. I’ve broken down the program into small exercises so that you can try coding the program yourself. Try the exercises before referring to the answers. Answers are provided in Appendix E or you can go to http://www.learncodingfast.com/python to download the Python files. I would strongly encourage you to download the source code as the formatting in Appendix E may result in the distortion of some indentation which makes the code difficult to read. Remember, learning the Python syntax is easy but boring. Problem solving is where the fun lies. If you encounter difficulties when doing these exercises, try harder. This is where the reward is the greatest. Ready? Let’s go for part 1!