Loops
Welcome to the third week of the 2025 SCIF10002 Introduction to Coding and Data Analysis for Scientists course! This week we shall be looking at for and while loops!
- Welcome Page
- Beginner: For and While Loops
- Intermediate: Advanced Iteration
- Advanced: Comprehensions
- Slides (Powerpoint)
Today’s Material
In today’s class, we shall focus on loops. As in the previous two classes, 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 for and while loops notebook linked below:
This notebook will talk you through the basics of loops in Python. 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 more advanced loop syntax such as iteration over dictionaries and the zip function.
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 will introduce you to list, set, dict and generator comprehensions, and explain how they can be combined with conditional expressions. Please only attempt this notebook if you have a strong background in Python programming.
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.