Conceptual Programming with Python
Thorsten and Isaac have written this book based on a programming course we teach for Master’s Students at the School of Computer Science of the University of Nottingham. The book is intended for students with little or no background in programming coming from different backgrounds educationally as well as culturally. It is not mainly a Python course but we use Python as a vehicle to teach basic programming concepts. Hence, the words conceptual programming in the title.
We cover basic concepts about data structures, imperative programming, recursion and backtracking, object-oriented programming, functional programming, game development and some basics of data science.
Thorsten Altenkirch (also known as Der Chef) and Isaac Triguero (also known as El Jefe) are with the School of Computer Science of the University of Nottingham.
Overview of the bookWe start with an exploration of Python from the top-level (Chapter 2), which covers some basic concepts like data types, coercions, functions and so on. We also introduce a graphical view of data structures in Python. Next we look at imperative programming (Chapter 3) which is the traditional way of programming present in Fortran or C. We introduce basic control structures like if-then-else and loops. We also discuss Turing's famous Halting problem. After this, we introduce one of the most powerful spells the young software wizard should master: recursion (Chapter 4), that is a function that calls itself. We are also using this to implement a sudoku solver via backtracking. Obviously, we cover Object Oriented Programming (Chapter 5) which is now a standard approach to program development. We also explain the use of trees to represent expressions and knowledge bases. An alternative to Object Oriented Programming is Functional Programming (Chapter 6), which is close to a mathematical understanding of programming. We also cover infinite data structures and how to write a Python interpreter in a functional style. Now you need to develop a bigger program, ideally in a group, and we suggest to write a game because it is fun and it is easy to understand what the goal is, hence we introduce the pygame library (Chapter 7). Finally, we give an introduction to Data Science which underlies the modern approach to Machine Learning (Chapter 8).
We present some challenges during the text, which you should try to solve yourself, but our solution is provided at the end of the chapter. Each chapter finishes with a quiz and exercises. The quiz can be easily done by using the Python interpreter but the point is to see whether you understand the language well enough to execute programs in your head. Indeed, the ability to run programs in your head is essential if you want to be able to write programs. The exercises are of different degrees of difficulty.
1.1 Why Python?
1.2 How to use Python?
1.3 Where to find more information?
1.4 Overview over the book
1.5 About the authors
2 Python from the top-level
2.1 Basic types and operations
2.2 Data structures
2.3 Mysteries of Python
2.5 Solution to top-level challenge
3 Imperative Programming
3.1 Blocks of Code
3.3 Error handling
3.5 The Halting problem
3.6 Iterating through data structures
3.7 The guessing game
3.9 Solution to Challenges
4 Recursion and backtracking
4.1 Prelude: functions calling functions
4.2 The Towers of Hanoi
4.3 How is recursion executed?
4.4 Some combinatorics
4.5 Solving sudoku: Using backtracking
4.7 Solution to recursion challenge
5 Object Oriented Programming
5.1 First example: a class to handle accounts
5.2 OOP example 1: Implementing Expressions
5.3 OOP example 2: Creating a Knowledge Base
5.5 Solution to oop challenge
6 Functional Programming
6.1 Higher order functions and comprehension
6.3 The sieve of Erathostenes
6.4 Python in Python
6.6 Solution to challenge
7 Implementing games with pygame
7.1 What is Pygame?
7.2 The Pong Game
7.3 Software Engineering
8 Getting started with Data Science
8.1 Data analysis with the Pandas library
8.2 Visualising your data
8.3 Mining the data
8.5 Solutions to Challenges
VideosWe are making some videos associated to the different chapters of our book. These are available on the Computerphile channel.
Chapter 3: Imperative Programming
The Halting problem
Chapter 4: Recursion and backtracking
The Towers of Hanoi
Solving sudoku: Using backtracking
Chapter 5: Object Oriented Programming
Tree Processors: Partial derivatives
Chapter 7: Implementing games with Pygame
The Pong Game series (4 videos)
Chapter 8: Data Science
Data Science for the Pong Game
"Excellent book! Highly recommended. This is the main textbook of a module I'm currently teaching." By Ahmed Kheiri, Lecturer in Management Science at Lancaster University (United Kingdom), 14-Jan-2020
"I really enjoyed reading this book. With its colloquial style, it is easy to follow and a pleasure to read. I can imagine that it is well suited for early programmers and definitely has some insights even for seasoned coders. Examples and problems presented are interesting and refreshing - you want to try them out. After all, who does not want to impress their elders by having their Python code solve the most difficult Sudoku? At first, I was surprised not to find all code on Github. However, just as the authors say that reading code is important, I think writing code, even if it is copying out of this book, is a useful next step. Off to finish my Pygame Pong implementation!" By Yves 29-Dec-2019
This book is very informative and at a level of everybody. It is touched the most important concepts of programming. Moreover, it has challenging exercises to help you cemented a concept learnt on each chapter. It is easy to follow even for a person with no background in programming. It is well written and go to straight to the point. You don’t waste time with a lot of literature which don’t matter to the learning. I will highly recommend this book to anybody who wants to learn concepts of programming, not just programming syntax. By RAOUL NIYO 28-Dec-2019
InstructorsCourse instructors can request an inspection copy of the book, together with a large collection of introductory and advanced exams and answers based on the content.
ErrataAll known issues are reported on our bitbucket issue tracking system. Please use this system if you spot any further issues.
Thorsten is from Berlin, Germany and has grown up on the western side of the wall. Indeed it is a little known fact that the wall was only built for him and it was taken down 6 weeks after he left to start his PhD in Edinburgh, Scotland. Having worked as a programmer in Berlin for various companies, Thorsten got sucked into more theoretical realms doing a PhD on Type Theory which is a synthesis of logical reasoning and functional programming. Following this ambition he has been working in Gothenburg, Sweden and even in (for a Prussian from Berlin) more exotic places like Munich in catholic Bavaria. Eventually at the turn of the Millenium, Thorsten joined the School for Computer Science at the University of Nottingham where he founded the Functional Programming Laboratory together with his colleague Graham Hutton (check out Graham's Haskell book!). He ended up teaching Python after a sabbatical at the Institute for Advanced Study in Princeton which left him no other choice after his return. However, he has been enjoying teaching this course, especially since he was joined by his colleague Isaac.
Thorsten and Isaac have mostly written this book together, but they led different chapters; you are challenged to guess who wrote what...
Contact us: Isaac, Thorsten