{ "cells": [ { "cell_type": "markdown", "id": "62bbd210-72e0-440a-9090-a6630890e247", "metadata": {}, "source": [ "# Lesson 05 in-class demo\n", "\n", "## 1. Conditionals\n", "\n", "### 1.1. `if`, `else` and `elif`" ] }, { "cell_type": "code", "execution_count": 1, "id": "d0c4173f-aeb9-4fc6-89d8-1dce7d4c7791", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Equal to zero\n", "This runs every time\n" ] } ], "source": [ "num = 0\n", "\n", "if num > 0:\n", " print('Greater than zero')\n", "\n", "elif num == 0:\n", " print('Equal to zero') \n", "\n", "else:\n", " print('Not greater than zero')\n", "\n", " \n", "print('This runs every time')" ] }, { "cell_type": "code", "execution_count": 2, "id": "b5e4d023-1e08-48b7-9ddf-800f8c1083ed", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "num > 0" ] }, { "cell_type": "code", "execution_count": 6, "id": "f2f8e82f-a95c-4523-b4de-6f7136b6295e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "num == 0" ] }, { "cell_type": "markdown", "id": "5bfa17a6-9f53-4ae1-a142-a46bd7375367", "metadata": {}, "source": [ "## 2. Loops\n", "\n", "### 2.1. `for` loop" ] }, { "cell_type": "code", "execution_count": 3, "id": "c9b1f467-76f5-4812-95ce-7e3b36959ab7", "metadata": {}, "outputs": [], "source": [ "my_list = ['Python', 'is', 'fun']" ] }, { "cell_type": "code", "execution_count": 4, "id": "043f0be7-20b5-4261-9ed5-740e6ec4eaba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python\n", "is\n", "fun\n" ] } ], "source": [ "for word in my_list:\n", " print(word)" ] }, { "cell_type": "markdown", "id": "b628c341-bb62-48ee-ab53-1616350bf326", "metadata": {}, "source": [ "### 2.2. `while` loop" ] }, { "cell_type": "code", "execution_count": 5, "id": "e3dbb3a1-20ea-4d89-bcb1-19abc2497f32", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Count is 0\n", "Count is 1\n", "Count is 2\n", "Count is 3\n", "Count is 4\n", "Count is 5\n" ] } ], "source": [ "count = 0\n", "\n", "while count < 5:\n", " print(f'Count is {count}')\n", " count += 1\n", " \n", "print(f'Count is {count}')" ] }, { "cell_type": "markdown", "id": "d33f54fc-3023-45dc-b6fd-d531fa3cf68d", "metadata": {}, "source": [ "## 2.3. `range` and enumeration" ] }, { "cell_type": "code", "execution_count": null, "id": "06cfe8e2-321e-4e46-ae51-9d9a462c31df", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 [3.10]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.2" } }, "nbformat": 4, "nbformat_minor": 5 }