Booleans and Conditionals

Welcome to the second week of the 2025 SCIF10002 Introduction to Coding and Data Analysis for Scientists course! This week we shall be looking at Booleans and conditional statements.

Today’s Material

In today’s class, we shall focus on the if statement. As in week 1, this week you have a choice of working through one of three notebooks.

Important: For today, please choose just one of the options below. You’ll have many opportunities to revisit the other concepts later in the course, so focus on building confidence with the Beginner material before tackling more advanced work.

Option 1: Beginner

If you have not spent much time coding in Python prior to taking this course, today you should work through the If Statements notebook linked below:

This notebook will talk you through the basics of the if statement. Please read through the text carefully and attempt all exercises!

Option 2: Intermediate

This weeks intermediate notebook should only be taken by those who are very comfortable with the material in the beginner notebook. Please ensure that you are able to complete the exercises in the beginner notebook before attempting this option. The intermediate material for this week is given below:

This notebook will guide you through the recently introduced Match statement, which can serve as a convenient alternative to an if-elif statement in many settings. Ensure you read through the text and attempt all exercises.

Option 3: Advanced

If you are an experienced programmer with a strong grasp of Python, begin by reviewing the exercises in the notebooks below to ensure you are fully comfortable with the material:

Once you are confident in your understanding, move on to the following notebook:

This notebook will talk you through some of the more complex nuances to boolean logic in Python, including lazy evaluation and in-line conditional evaluation. Please attempt this only if you have spent a lot of time developing code in Python already.

Getting Help

There is a lot to remember when first learning Python. To get more help see the Python API. Another useful link is the W3 schools series on Python which is very good, especially for new users. Another way to get help if you are ever unsure what a function is doing is to use thehelp function in the Python terminal like so:

In class, you can ask for help from the lecturer, demonstrators and your peers around you. We advise you do not ask AI for help unless you are really stuck.