Lecture 2: Functions, Logic and Conditionals
Contents
Lecture 2: Functions, Logic and Conditionals#
In Lecture 2 we’ll continue our introduction to python. In particular we will teach you
How to write functions to perform particular tasks.
NOTE All the coursework questions will require you to use functions. Please ask us and/or use the drop-in sessions to get help if you are confused about functions after going through today’s material
How to write conditional statements (“if” and “while” blocks) using python.
How to use logical operators (and, not, or) in python.
The weekly tasks are split up into a series of sequential notebooks. Any of these can be opened below by clicking on them. Some of these are interactive notebooks, where you will run and/or write code in the cells. To open any of the notebooks interactively, first click on the section, then click on the rocket and select “Colab”.
Weekly tasks#
- Functions - An overview
- Using (or “calling”) a function - Interactive
- Using (or “calling”) a function - Interactive - SOLVED
- How to write your own function
- Writing Functions - Exercises
- Writing Functions - Exercises - SOLVED
- Writing functions with multiple inputs and outputs
- Writing functions with multiple inputs and outputs - SOLVED
- Importing a function
- The most common reasons people use functions wrong and don’t pass coursework questions
- Logical operators
- Logical Operators - Exercises
- Logical Operators - Exercises - SOLVED
- Conditional statements
- Conditionals - Exercises
- Conditionals - Exercises - SOLVED
- Summary
- End of class exercises
- End of class exercises - SOLVED