From 949ad78b367305f4a2a190e866ea917ef0e94eb9 Mon Sep 17 00:00:00 2001 From: gsingh58 <gurmail.singh@wisc.edu> Date: Fri, 10 Feb 2023 03:07:46 -0500 Subject: [PATCH] Lec8 update --- .../lec_08_Conditionals1.ipynb | 20 ++++++++++++++++- ..._Conditionals1_template_Gurmail_lec1.ipynb | 20 ++++++++++++++++- ..._Conditionals1_template_Gurmail_lec2.ipynb | 22 +++++++++++++++++-- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb index 3e6428b..cc64714 100644 --- a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb +++ b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb @@ -11,6 +11,24 @@ "* Q2 due Today" ] }, + { + "cell_type": "markdown", + "id": "a9ecd185", + "metadata": {}, + "source": [ + "# Function Scope Rules\n", + "1. Functions must be called before they run\n", + "2. Local variables are recycled when functions end\n", + "3. Local variables are recreated every time a function is called\n", + "4. We can only see variables that are in the active frame or the global frame\n", + "5. We can in general \"use\" any global variable with no problems at all. \"Use\" means anything other than assignment. e.g. printing\n", + "6. Python makes variables that we assign something to as local\n", + "7. Must assign local variables before we can use them.\n", + "8. use the keyword global to use the global version of the variable instead of making a local variable.\n", + "9. When we pass data (arguments) to functions the data is copied into the parameter - we don't use the original variables.\n", + "10. Even if the variables have the same name we still copy the data from the argument to the parameter." + ] + }, { "cell_type": "markdown", "id": "309ae71d", @@ -617,7 +635,7 @@ "outputs": [], "source": [ "def format_date(month, day, year):\n", - " \"\"\"returns a string representing the date, such as Feb 11th of ‘22\"\"\"\n", + " \"\"\"returns a string representing the date, such as Feb 11th of ‘23\"\"\"\n", " result_str = \"\"\n", " result_str += format_month(month)\n", " result_str += \" \" + format_day(day)\n", diff --git a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb index 382a165..5dcbfc3 100644 --- a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb +++ b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb @@ -11,6 +11,24 @@ "* Q2 due Today" ] }, + { + "cell_type": "markdown", + "id": "4933dfcf", + "metadata": {}, + "source": [ + "# Function Scope Rules\n", + "1. Functions must be called before they run\n", + "2. Local variables are recycled when functions end\n", + "3. Local variables are recreated every time a function is called\n", + "4. We can only see variables that are in the active frame or the global frame\n", + "5. We can in general \"use\" any global variable with no problems at all. \"Use\" means anything other than assignment. e.g. printing\n", + "6. Python makes variables that we assign something to as local\n", + "7. Must assign local variables before we can use them.\n", + "8. use the keyword global to use the global version of the variable instead of making a local variable.\n", + "9. When we pass data (arguments) to functions the data is copied into the parameter - we don't use the original variables.\n", + "10. Even if the variables have the same name we still copy the data from the argument to the parameter." + ] + }, { "cell_type": "markdown", "id": "309ae71d", @@ -476,7 +494,7 @@ "outputs": [], "source": [ "def format_date(month, day, year):\n", - " \"\"\"returns a string representing the date, such as Feb 11th of ‘22\"\"\"\n", + " \"\"\"returns a string representing the date, such as Feb 11th of ‘23\"\"\"\n", " pass" ] }, diff --git a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb index 3066c0c..2ebb2c2 100644 --- a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb +++ b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb @@ -11,6 +11,24 @@ "* Q2 due Today" ] }, + { + "cell_type": "markdown", + "id": "c8695d05", + "metadata": {}, + "source": [ + "# Function Scope Rules\n", + "1. Functions must be called before they run\n", + "2. Local variables are recycled when functions end\n", + "3. Local variables are recreated every time a function is called\n", + "4. We can only see variables that are in the active frame or the global frame\n", + "5. We can in general \"use\" any global variable with no problems at all. \"Use\" means anything other than assignment. e.g. printing\n", + "6. Python makes variables that we assign something to as local\n", + "7. Must assign local variables before we can use them.\n", + "8. use the keyword global to use the global version of the variable instead of making a local variable.\n", + "9. When we pass data (arguments) to functions the data is copied into the parameter - we don't use the original variables.\n", + "10. Even if the variables have the same name we still copy the data from the argument to the parameter." + ] + }, { "cell_type": "markdown", "id": "309ae71d", @@ -476,7 +494,7 @@ "outputs": [], "source": [ "def format_date(month, day, year):\n", - " \"\"\"returns a string representing the date, such as Feb 11th of ‘22\"\"\"\n", + " \"\"\"returns a string representing the date, such as Feb 11th of ‘23\"\"\"\n", " pass" ] }, @@ -487,7 +505,7 @@ "metadata": {}, "outputs": [], "source": [ - "format_date(9, 23, 2022)" + "format_date(2, 11, 2023)" ] }, { -- GitLab