MPhys Physics

Year of entry: 2024

Course unit details:
Introduction to Programming for Physicists

Course unit fact file
Unit code PHYS20161
Credit rating 10
Unit level Level 2
Teaching period(s) Semester 1
Available as a free choice unit? No


Introduction to Programming for Physicists


Follow-up units:

PHYS20872: Theory Computing Project

PHYS20762: Computational Physics

PHYS30762: OOP in C++

Some experiments in Y3 lab (PHYS30280) require computing.

Many MPhys projects require at least some element of computing (PHYS40181/2)


The aim of the course is to give a practical introduction to computer programming for physicists assuming little or no previous programming experience.

Learning outcomes

On completion successful students will:

  1. Be able to write programs in Python to aid them in practical situations they will face in their degree course and future work in physics or in other fields.
  2. Implement basic programming theory to write efficient code.



Elements of Programming – (3 weeks)

  1. Introduction to Python
  2. Variable types and lists
  3. Operators
  4. Input / output
  5. Conditional expressions
  6. Loops
  7. Introduction to debugging, testing and errors
  8. Functions
  9. Style and PEP8

Basic Python libraries and validation – (2 weeks)

  1. Python Modules
  2. Introduction to numpy
  3. Numpy arrays, built-in functions and indexing

Introduction to algorithms and visualisation – (3 weeks)

  1. Algorithms and their uses
  2. Basic manipulation and visualisation of data
  3. Read and write files
  4. Data validation
  5. Root finding
  6. Basic optimization algorithms


Introduction to scientific programming libraries – (3 weeks)

  1. Advanced uses of numpy and matplotlib
  2. Introduction to scipy
  3. Using inbuilt functions


Assessment methods

5 BlackBoard quizzes worth 7% each due weeks 1-3,7 and 8. 

1st assignment worth 15% 

Final assignment worth 50% 

Standard late penalties apply of 10% deducted per day late for each assessment. 

Feedback methods

Feedback is offered orally by demonstrators in the lab, automated responses in the quizzes, and specific written comments for each assignment.

Recommended reading

Hill, C. Learning scientific programming with python (Cambridge Uni. press)

Study hours

Scheduled activity hours
Lectures 10
Practical classes & workshops 66
Independent study hours
Independent study 24

Teaching staff

Staff member Role
Clive Dickinson Unit coordinator
Lloyd Cawthorne Unit coordinator

Additional notes

Note: Laboratory facilities are not available for resits.  A student who has failed may be permitted to submit further assessments, based on laboratory work already carried out, in order to pass the course unit.

Return to course details