09: Selection in Python

There are three main building blocks that all computer programs consist of: sequence, selection and iteration. This activity is designed to help you understand and use selection in python programs.

Tell your code how to make decisions
Selection: Tell your code how to make decisions

Selection means making a choice. You will select different choices hundreds of times every day:

What shall I select to eat for breakfast?

Which selection of clothes shall I wear?

Which people with I select to speak to today (and who will I try to ignore!)

examples of selection in everyday life.

Most programs need to be able to make choices too. You can write code that makes choices by using selection.

Contents:

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.

08: Sequence in Python

There are three main building blocks that all computer programs consist of: sequence, selection and iteration. This activity is designed to help you design and code your own sequences with python.

Plan the order of instructions carefully
Sequence in Python: Plan the order of instructions carefully

The colour of traffic lights follow a sequence that’s carefully planned. If the wrong lights show at the wrong time then you’ll probably agree that bad things will happen.

It’s just the same with lines of code: sometimes the order in which your lines of code run is really important. Sequence means running instructions in a set order to do what the program needs to do.

This activity gets you thinking about the order your instructions so that you can avoid common mistakes when writing python programs.

Contents:

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.

07: Python: Runtime errors

This activity is designed to help you learn how to recognise and fix errors that cause your program to crash when you’re writing python code.

Find and fix common errors in your code
Python runtime errors: Find and fix common errors in your code

The last few activities looked at how we can use variables and constants to store data and how to convert data between different data types.

There’s a good chance that you’ve come across some error messages whilst trying, debugging and extending your python code.

As mentioned before, there are three types of errors you’ll need to be able to find and fix: syntax errors, logical errors and runtime errors.

This activity focuses on runtime errors: what they are, how you can avoid them and how you can fix them.

Contents:

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.