From 904a17aec77cf60a4f27dd76fbbf0a0c470bb14c Mon Sep 17 00:00:00 2001 From: gsingh58 <gurmail-singh@cs.wisc.edu> Date: Fri, 24 Feb 2023 12:32:28 -0600 Subject: [PATCH] Lec13 update --- .../13_Strings/lec_13_Strings.ipynb | 95 ++++++++----------- ...lec_13_Strings_template_Gurmail_lec1.ipynb | 26 ++--- ...lec_13_Strings_template_Gurmail_lec2.ipynb | 26 ++--- 3 files changed, 68 insertions(+), 79 deletions(-) diff --git a/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings.ipynb b/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings.ipynb index 45463be..81f3a3e 100644 --- a/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings.ipynb +++ b/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings.ipynb @@ -559,10 +559,10 @@ "evalue": "Replacement index 1 out of range for positional args tuple", "output_type": "error", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "Input \u001b[0;32mIn [19]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# TODO: what will happen when you pass only one argument to format method using email string?\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43memail\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mformat\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mRogers\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n", - "\u001b[0;31mIndexError\u001b[0m: Replacement index 1 out of range for positional args tuple" + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_5224\\3770012135.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# TODO: what will happen when you pass only one argument to format method using email string?\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0memail\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Rogers\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m: Replacement index 1 out of range for positional args tuple" ] } ], @@ -646,10 +646,10 @@ "evalue": "string index out of range", "output_type": "error", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", - "Input \u001b[0;32mIn [21]\u001b[0m, in \u001b[0;36m<cell line: 8>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(day[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]) \u001b[38;5;66;03m# last\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(day[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m2\u001b[39m]) \u001b[38;5;66;03m# 2nd last\u001b[39;00m\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mday\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m50\u001b[39;49m\u001b[43m]\u001b[49m)\n", - "\u001b[0;31mIndexError\u001b[0m: string index out of range" + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_5224\\1223714302.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mday\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# last\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mday\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# 2nd last\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mday\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m50\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# this won't work\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m: string index out of range" ] } ], @@ -760,11 +760,11 @@ } ], "source": [ - "# print each letter of the string using for loop\n", - "# letter is a new variable that is the value of each iteration\n", + "# print each letter of the string using for loop with range built-in function call\n", + "# range enables us to iterate over every index in the string\n", "\n", - "for letter in day:\n", - " print(letter)" + "for idx in range(len(day)):\n", + " print(day[idx])" ] }, { @@ -773,22 +773,24 @@ "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'b' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "Input \u001b[0;32mIn [25]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# the 2nd variable must be defined\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m# 2nd var b undefined\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m a \u001b[38;5;129;01min\u001b[39;00m \u001b[43mb\u001b[49m: \n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(a)\n", - "\u001b[0;31mNameError\u001b[0m: name 'b' is not defined" + "name": "stdout", + "output_type": "stream", + "text": [ + "F\n", + "r\n", + "i\n", + "d\n", + "a\n", + "y\n" ] } ], "source": [ - "# the 2nd variable must be defined\n", - "# 2nd var b undefined\n", - "for a in b: \n", - " print(a)" + "# print each letter of the string using for loop\n", + "# letter is a new variable that is the value of each iteration\n", + "\n", + "for letter in day:\n", + " print(letter)" ] }, { @@ -797,24 +799,22 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "F\n", - "r\n", - "i\n", - "d\n", - "a\n", - "y\n" + "ename": "NameError", + "evalue": "name 'b' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_5224\\571427960.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# the 2nd variable must be defined\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;31m# 2nd var b undefined\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mNameError\u001b[0m: name 'b' is not defined" ] } ], "source": [ - "# print each letter of the string using for loop with range built-in function call\n", - "# range enables us to iterate over every index in the string\n", - "\n", - "for idx in range(len(day)):\n", - " print(day[idx])" + "# the 2nd variable must be defined\n", + "# 2nd var b undefined\n", + "for a in b: \n", + " print(a)" ] }, { @@ -898,13 +898,9 @@ "X\tThe letter is not in the word.\n", "_\tThe letter is in the word, but in the wrong place.\n", "O\tThe letter is in the correct place!\n", - "Guess the word: rance\n", - "RANCE\t____O\n", - "Guess the word: nacre\n", - "NACRE\t____O\n", - "Guess the word: crane\n", + "Guess the word: CRANE\n", "CRANE\tOOOOO\n", - "You won in 3 guesses!\n" + "You won in 1 guesses!\n" ] } ], @@ -946,18 +942,11 @@ "else:\n", " print(\"You won in {} guesses!\".format(current_num_guesses))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -971,7 +960,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.9.13" } }, "nbformat": 4, diff --git a/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec1.ipynb b/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec1.ipynb index 208f8fb..9f16aaa 100644 --- a/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec1.ipynb +++ b/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec1.ipynb @@ -497,8 +497,11 @@ "metadata": {}, "outputs": [], "source": [ - "# print each letter of the string using for loop\n", - "# letter is a new variable that is the value of each iteration\n" + "# print each letter of the string using for loop with range built-in function call\n", + "# range enables us to iterate over every index in the string\n", + "\n", + "for idx in range(???):\n", + " print(day[???])" ] }, { @@ -507,10 +510,8 @@ "metadata": {}, "outputs": [], "source": [ - "# the 2nd variable must be defined\n", - "# 2nd var b undefined\n", - "for a in b: \n", - " print(a)" + "# print each letter of the string using for loop\n", + "# letter is a new variable that is the value of each iteration\n" ] }, { @@ -519,11 +520,10 @@ "metadata": {}, "outputs": [], "source": [ - "# print each letter of the string using for loop with range built-in function call\n", - "# range enables us to iterate over every index in the string\n", - "\n", - "for idx in range(???):\n", - " print(day[???])" + "# the 2nd variable must be defined\n", + "# 2nd var b undefined\n", + "for a in b: \n", + " print(a)" ] }, { @@ -622,7 +622,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -636,7 +636,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.9.13" } }, "nbformat": 4, diff --git a/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec2.ipynb b/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec2.ipynb index 208f8fb..9f16aaa 100644 --- a/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec2.ipynb +++ b/s23/Gurmail_lecture_notes/13_Strings/lec_13_Strings_template_Gurmail_lec2.ipynb @@ -497,8 +497,11 @@ "metadata": {}, "outputs": [], "source": [ - "# print each letter of the string using for loop\n", - "# letter is a new variable that is the value of each iteration\n" + "# print each letter of the string using for loop with range built-in function call\n", + "# range enables us to iterate over every index in the string\n", + "\n", + "for idx in range(???):\n", + " print(day[???])" ] }, { @@ -507,10 +510,8 @@ "metadata": {}, "outputs": [], "source": [ - "# the 2nd variable must be defined\n", - "# 2nd var b undefined\n", - "for a in b: \n", - " print(a)" + "# print each letter of the string using for loop\n", + "# letter is a new variable that is the value of each iteration\n" ] }, { @@ -519,11 +520,10 @@ "metadata": {}, "outputs": [], "source": [ - "# print each letter of the string using for loop with range built-in function call\n", - "# range enables us to iterate over every index in the string\n", - "\n", - "for idx in range(???):\n", - " print(day[???])" + "# the 2nd variable must be defined\n", + "# 2nd var b undefined\n", + "for a in b: \n", + " print(a)" ] }, { @@ -622,7 +622,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -636,7 +636,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.9.13" } }, "nbformat": 4, -- GitLab