diff --git a/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2.ipynb b/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2.ipynb index 3ac01114db3211a511e4657f6e676bb7528affd8..cea5f1ed958d837342f67fa57c6282e3b49b3028 100644 --- a/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2.ipynb +++ b/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2.ipynb @@ -1,11 +1,17 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "id": "fcdba72c", "metadata": {}, "source": [ - "# Conditionals 2" + "# Conditionals 2\n", + "\n", + "## Readings\n", + "\n", + "- Parts of Chapter 5 of Think Python\n", + "- Chapter 4.6 to end (skip 4.7) of Python for Everybody" ] }, { @@ -148,8 +154,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "Enter your age: 2\n", - "You are a: toddler\n" + "Enter your age: 10\n", + "You are a: kid\n" ] } ], @@ -296,7 +302,7 @@ { "data": { "text/plain": [ - "\"Feb 14th of '22\"" + "\"Sep 26th of '22\"" ] }, "execution_count": 8, @@ -305,7 +311,7 @@ } ], "source": [ - "format_date(2, 14, 2022)" + "format_date(9, 26, 2022)" ] }, { @@ -572,6 +578,7 @@ "# Refactoring Practice 1: recognizing equivalent code\n", "# Exam 1 Fall 2020\n", "def g(x, y):\n", + " # the expression after an if must be a Boolean expression or have a Boolean value\n", " if x:\n", " if y:\n", " return True\n", @@ -613,6 +620,7 @@ "source": [ "# Refactoring Practice 2:\n", "def h(x, y):\n", + " # the expression after an if must be a Boolean expression or have a Boolean value\n", " if x:\n", " return False\n", " else:\n", @@ -655,7 +663,8 @@ "# Refactoring Practice 3:\n", "\n", "def some_bool_eval(x, y):\n", - " if x: # the expression after an if must be a Boolean expression or have a Boolean value\n", + " # the expression after an if must be a Boolean expression or have a Boolean value\n", + " if x: \n", " return True\n", " elif y:\n", " return True\n", @@ -692,7 +701,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.9.12" } }, "nbformat": 4, diff --git a/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2_template.ipynb b/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2_template.ipynb index 3561e41a40689eb9739a7a1c08c88e46d0dfe2e3..a1f7d72a8b73d9e4512949ab420ad7f43c616be3 100644 --- a/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2_template.ipynb +++ b/f22/meena_lec_notes/lec-09/lec_09_Conditionals_2_template.ipynb @@ -5,7 +5,12 @@ "id": "25751b55", "metadata": {}, "source": [ - "# Conditionals 2" + "# Conditionals 2\n", + "\n", + "## Readings\n", + "\n", + "- Parts of Chapter 5 of Think Python\n", + "- Chapter 4.6 to end (skip 4.7) of Python for Everybody" ] }, { @@ -58,7 +63,7 @@ "source": [ "**Find a partner to do these TODOs**\n", "\n", - "TODO: try to compute the boolean expression yourself, by inserting a new cell below. Change team variable's value to all three possible values.\n", + "TODO: try to compute the boolean expression yourself, by inserting a new cell below. Change team variable's value to all three possible values. Observe what is wrong with the current expression.\n", "\n", "TODO: fix the expression after your experiments" ] @@ -100,7 +105,18 @@ "age = int(input(\"Enter your age: \"))\n", "\n", "def categorize_age(age):\n", - " pass\n", + " if 0 <= age <= 1:\n", + " return \"infant\" # TODO: discuss why we have a return here instead of print\n", + " elif 2 <= age <= 3:\n", + " return \"toddler\"\n", + " elif 4 <= age <= 10:\n", + " return \"kid\"\n", + " elif 11 <= age <= 12:\n", + " return \"tween\"\n", + " elif 13 <= age <= 17:\n", + " return \"teen\"\n", + " else:\n", + " return \"adult\"\n", " \n", "print(\"You are a:\", categorize_age(age))" ] @@ -360,6 +376,7 @@ "# Refactoring Practice 1: recognizing equivalent code\n", "# Exam 1 Fall 2020\n", "def g(x, y):\n", + " # the expression after an if must be a Boolean expression or have a Boolean value\n", " if x:\n", " if y:\n", " return True\n", @@ -385,6 +402,7 @@ "source": [ "# Refactoring Practice 2:\n", "def h(x, y):\n", + " # the expression after an if must be a Boolean expression or have a Boolean value\n", " if x:\n", " return False\n", " else:\n", @@ -412,7 +430,8 @@ "# Refactoring Practice 3:\n", "\n", "def some_bool_eval(x, y):\n", - " if x: # the expression after an if must be a Boolean expression or have a Boolean value\n", + " # the expression after an if must be a Boolean expression or have a Boolean value\n", + " if x: \n", " return True\n", " elif y:\n", " return True\n", @@ -449,7 +468,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.9.12" } }, "nbformat": 4,