Skip to content

An introduction to computer programming using Python

This collection of Jupyter notebooks and accompanying material form the basis of an interactive introduction to computer programming taught to chemistry undergraduate students at Imperial College London. It benefits from an earlier course focussed on data analysis, but does not build upon and does not depend on it.

As the name of the course suggests, the goal is not exactly to teach Python, but rather to use Python to teach features and constructs that are common in many imperative programming languages. Object-oriented features in Python are not covered, and therefore object specific methods are not used (in workshop 4, the convenience of some methods when processing strings lead to deviations from this principle). These choices may seem odd to Python programmers who will find more elegant ways of solving problems, but they keep the course shorter and more consistent, and hopefully more approachable to beginner programmers. Still, it is expected that the students will develop a good basis to start reading and working with Python code.

The structure of the course is as follows:

Workshop 1

  • Basic data types ---numbers (integers, floating point, complex), strings, booleans--- and their operations.
  • Conditional statements
  • Variables
  • Lists
  • Other data structures

Workshop 2

  • For and While loops
  • Defining functions (and a how to invoke methods)

Workshop 3

  • Using loops to do work; nested loop structures.
  • Using external modules.
  • Standalone scripts and prompting for input.

Workshop 4

  • Dealing with files: writing, reading, parsing.

The notebooks and related materials are made available under the Creative Commons Attribution 4.0 (CC-by) license, and can be downloaded as a zip archive. In order to use the notebooks interactively in your computer you will need to have a python interpreter (version 3.x) and the Jupyter notebook installed, both can be obtained, for example, by installing the Anaconda distribution.

We are interested in your feedback and to hear about other ways this material is being used.