An enormously complex tangle of piping and valves with numerous loops and on/off spigots that control the flow. MidJourney 5
Overview
In this session, we will be exploring Control Flows - if-elif
, for
, while
and other ways of altering the flow of code execution. Live coding is a great way to learn programming as it allows you to see the process of writing code in real-time, including how to deal with unexpected issues and debug errors.
Objectives
- Understand the fundamentals of flow control in Python.
- Apply
if-elif-else
constructions in practical examples. - Use
for
andwhile
loops to iterate through collections. - Develop the ability to troubleshoot and debug in a live setting.
Getting Started
Before we begin our interactive session, please follow these steps to set up your Jupyter Notebook:
- Open JupyterLab and create a new notebook:
- Click on the
+
button in the top left corner - Select
Python 3.10.0
from the Notebook options
- Click on the
- Rename your notebook:
- Right-click on the
Untitled.ipynb
tab - Select βRenameβ
- Name your notebook with the format:
Session_XY_Topic.ipynb
(Replace X with the day number and Y with the session number)
- Right-click on the
- Add a title cell:
- In the first cell of your notebook, change the cell type to βMarkdownβ
- Add the following content (replace the placeholders with the actual information):
# Day X: Session Y - [Session Topic]
[Link to session webpage]
[Current Date] Date:
Set up your notebook:
Please set up your Jupyter Notebook with the following structure. Weβll fill in the content together during our session.
### Introduction to Control Flows
<insert code cell below>
### Conditionals
#### Basic If Statement
<insert code cell below>
#### Adding Else
<insert code cell below>
#### Using Elif
<insert code cell below>
### Loops
#### For Loops
<insert code cell below>
#### While Loops
<insert code cell below>
### Applying Control Flows in Data Science
<insert code cell below>
### Conclusion
<insert code cell below>
Donβt forget to save your work frequently by clicking the save icon or using the keyboard shortcut (Ctrl+S or Cmd+S).
Remember, weβll be coding together, so donβt worry about filling in the content now. Just set up the structure, and weβll dive into the details during our session!
- Participation:
- Try to code along with me during the session.
- Feel free to ask questions at any time. Remember, if you have a question, others probably do too!
- Resources:
- I will be sharing snippets of code and notes. Make sure to take your own notes and save snippets in your notebook for future reference.
- Check out our class control flows cheatsheet.
Session Format
Introduction
- A brief discussion about the topic in Python programming and its importance in data science.
Demonstration
- I will demonstrate code examples live. Follow along and write the code into your own Jupyter notebook.
Practice
- You will have the opportunity to try exercises on your own to apply what youβve learned.
Q&A
- We will have a Q&A session at the end where you can ask specific questions about the code, concepts, or issues encountered during the session.
After the Session
Review your notes and try to replicate the exercises on your own.
Experiment with the code by modifying parameters or adding new features to deepen your understanding.
Check out our class flow control cheatsheet.