diff --git a/02_activities/assignments/assignment_1.ipynb b/02_activities/assignments/assignment_1.ipynb index cbfd8c709..977dbe1c5 100644 --- a/02_activities/assignments/assignment_1.ipynb +++ b/02_activities/assignments/assignment_1.ipynb @@ -56,13 +56,124 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# This is a function, which we will learn more about next week. For testing purposes, we will write our code in the function\n", "def anagram_checker(word_a, word_b):\n", - " # Your code here\n", + "\n", + " # using list function to create a list of each letter in the word_a & word_b\n", + " # using string.lower() method to change the string to lowercase.\n", + " # sort function will sort the alphabets in ascending order which is default. It modifies the elements in a list and doesn't return the sorted list.\n", + " alphabet_list_a = list(word_a.lower())\n", + " alphabet_list_a.sort()\n", + " alphabet_list_b = list(word_b.lower())\n", + " alphabet_list_b.sort()\n", + "\n", + " # == is for comparing two lists. It compares two lists elementwise. \n", + " return(alphabet_list_a == alphabet_list_b)\n", + "\n", + "# Run your code to check using the words below:\n", + "anagram_checker(\"Silent\", \"listen\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"Night\")" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"night\", \"Thing\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Solution# 2\n", + "Using for loop" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def anagram_checker(word_a, word_b):\n", + " \n", + " # Creatinig an empty list and changing word_a to lowercase\n", + " alphabet_list_a = []\n", + " word_a = word_a.lower()\n", + "\n", + "# for loop goes through each index of the string (from 0 to (length - 1)) \n", + "# 1. It retrieves the letter at the current index\n", + "# 2. Adds the letter to the list. For each iteration, it keeps adding the letters to the updated list from the previous iteration. \n", + " for i in range(0, len(word_a)):\n", + " alphabet_list_a.append(word_a[i])\n", + "\n", + " alphabet_list_b = []\n", + " word_b = word_b.lower()\n", + " \n", + " for i in range(0, len(word_b)):\n", + " alphabet_list_b.append(word_b[i])\n", + "\n", + " # == is for comparing two lists. It compares two lists elementwise. \n", + " return(sorted(alphabet_list_a) == sorted(alphabet_list_b))\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\")" @@ -70,18 +181,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Night\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"night\", \"Thing\")" ] @@ -97,12 +230,119 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def anagram_checker(word_a, word_b, is_case_sensitive):\n", + "\n", + "# Using if else to set the conditions about the case sensitivity\n", + " if is_case_sensitive == False:\n", + " \n", + " alphabet_list_a = list(word_a.lower())\n", + " alphabet_list_a.sort()\n", + " alphabet_list_b = list(word_b.lower())\n", + " alphabet_list_b.sort()\n", + "\n", + " return(alphabet_list_a == alphabet_list_b)\n", + "\n", + " else:\n", + " \n", + " alphabet_list_a = list(word_a)\n", + " alphabet_list_a.sort()\n", + " alphabet_list_b = list(word_b)\n", + " alphabet_list_b.sort()\n", + "\n", + " return(alphabet_list_a == alphabet_list_b)\n", + "\n", + "# Run your code to check using the words below:\n", + "anagram_checker(\"Silent\", \"listen\", False) # True" + ] + }, + { + "cell_type": "code", + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "anagram_checker(\"Silent\", \"Listen\", True) # False" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Modifying Solution# 2" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def anagram_checker(word_a, word_b, is_case_sensitive):\n", - " # Modify your existing code here\n", + "\n", + " if is_case_sensitive == False:\n", + "\n", + " alphabet_list_a = []\n", + " word_a = word_a.lower()\n", + "\n", + " for i in range(0, len(word_a)):\n", + " alphabet_list_a.append(word_a[i])\n", + "\n", + " alphabet_list_b = []\n", + " word_b = word_b.lower()\n", + " \n", + " for i in range(0, len(word_b)):\n", + " alphabet_list_b.append(word_b[i])\n", + "\n", + " return(sorted(alphabet_list_a) == sorted(alphabet_list_b))\n", + "\n", + " else:\n", + "\n", + " alphabet_list_a = []\n", + " for i in range(0, len(word_a)):\n", + " alphabet_list_a.append(word_a[i])\n", + "\n", + " alphabet_list_b = []\n", + " for i in range(0, len(word_b)):\n", + " alphabet_list_b.append(word_b[i])\n", + "\n", + " return(sorted(alphabet_list_a) == sorted(alphabet_list_b))\n", "\n", "# Run your code to check using the words below:\n", "anagram_checker(\"Silent\", \"listen\", False) # True" @@ -110,9 +350,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "anagram_checker(\"Silent\", \"Listen\", True) # False" ] @@ -130,7 +381,7 @@ ], "metadata": { "kernelspec": { - "display_name": "new-learner", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -144,7 +395,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.15" } }, "nbformat": 4, diff --git a/02_activities/homework/01_data_types.ipynb b/02_activities/homework/01_data_types.ipynb index f60123d4b..09bf9a129 100644 --- a/02_activities/homework/01_data_types.ipynb +++ b/02_activities/homework/01_data_types.ipynb @@ -1 +1,240 @@ -{"cells":[{"cell_type":"markdown","metadata":{"id":"jNAI57ELh-I8"},"source":["# Getting Started: Python Fundamentals\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"5xeRB_0jiT5n"},"source":["### 1. What types are involved in the following expressions? What data type will each expression evaluate to?\n","\n","`8 * 2.5`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":158,"status":"ok","timestamp":1667929890889,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"C6c48sSBOUeE","outputId":"3628ffce-faf6-4d23-daff-5e09edf76541"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"4eICUfHi_Z-K"},"source":["`9 / 2`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":43,"status":"ok","timestamp":1667929891449,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"QVdbNoA2OiQ_","outputId":"ab9f4fac-b1cc-4afc-cc54-10592b92abb1"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"DhrJoWbj_cNe"},"source":["`9 // -2`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":39,"status":"ok","timestamp":1667929891450,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"cSsGq3r0Opx6","outputId":"13df11ef-d136-4a42-884e-be1e369aae52"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"lW4UnVfw_eYy"},"source":["`1.5 * 2 >= 7 - 3`"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":34,"status":"ok","timestamp":1667929891452,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"54N6gcNPOylS","outputId":"938208fc-c4c3-4e58-dd18-b50d3acc84d8"},"outputs":[],"source":["# Your code here"]},{"cell_type":"markdown","metadata":{"id":"5T-ytiTw-KvJ"},"source":["### 2. In which order will the expressions be evaluated.\n","\n","`6 * 3 + 7 * 4`\n","\n","\n","
\n"," Answer\n","\n"," `*` > `*` > `+` \n","
\n","\n","\n","`5 - 2 * 3 ** 4`\n","\n","
\n"," Answer\n","\n"," `**` > `*` > `-`\n","
\n","\n","`(5 - 2) * 3 ** 4`\n","\n","
\n"," Answer\n","\n"," `(-)` > `**` > `*` \n","
\n","\n","`5 + 2 >= 3 * 4`\n","\n","
\n"," Answer\n","\n"," `*` > `+` > `>=`\n","
"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMhUBNX+UP2C+YDtVSxQKBK","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "jNAI57ELh-I8" + }, + "source": [ + "# Getting Started: Python Fundamentals\n", + "## Practice Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5xeRB_0jiT5n" + }, + "source": [ + "### 1. What types are involved in the following expressions? What data type will each expression evaluate to?\n", + "\n", + "`8 * 2.5`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 158, + "status": "ok", + "timestamp": 1667929890889, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "C6c48sSBOUeE", + "outputId": "3628ffce-faf6-4d23-daff-5e09edf76541" + }, + "outputs": [], + "source": [ + "# 8 is an integer\n", + "# 2.5 is float\n", + "# float\n", + "# 20.0" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4eICUfHi_Z-K" + }, + "source": [ + "`9 / 2`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 43, + "status": "ok", + "timestamp": 1667929891449, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "QVdbNoA2OiQ_", + "outputId": "ab9f4fac-b1cc-4afc-cc54-10592b92abb1" + }, + "outputs": [], + "source": [ + "# 9 is an integer\n", + "# 2 is an integer\n", + "# / is the division and gives results as float data type\n", + "# 4.5" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DhrJoWbj_cNe" + }, + "source": [ + "`9 // -2`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 39, + "status": "ok", + "timestamp": 1667929891450, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "cSsGq3r0Opx6", + "outputId": "13df11ef-d136-4a42-884e-be1e369aae52" + }, + "outputs": [], + "source": [ + "# 9 is an integer\n", + "# // is the floor division\n", + "# -2 is an integer\n", + "# the result will be an integer rounded down\n", + "# -5" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lW4UnVfw_eYy" + }, + "source": [ + "`1.5 * 2 >= 7 - 3`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "executionInfo": { + "elapsed": 34, + "status": "ok", + "timestamp": 1667929891452, + "user": { + "displayName": "Kaylie Lau", + "userId": "01284785813595846851" + }, + "user_tz": 300 + }, + "id": "54N6gcNPOylS", + "outputId": "938208fc-c4c3-4e58-dd18-b50d3acc84d8" + }, + "outputs": [], + "source": [ + "# 1.5 is float\n", + "# * is multiplication\n", + "# 2, 7, 3 are integers\n", + "# >= is greater than equal to\n", + "# - substraction\n", + "# result will be Boolean (FALSE)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5T-ytiTw-KvJ" + }, + "source": [ + "### 2. In which order will the expressions be evaluated.\n", + "\n", + "`6 * 3 + 7 * 4`\n", + "\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `*` > `*` > `+` \n", + "
\n", + "\n", + "\n", + "`5 - 2 * 3 ** 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `**` > `*` > `-`\n", + "
\n", + "\n", + "`(5 - 2) * 3 ** 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `(-)` > `**` > `*` \n", + "
\n", + "\n", + "`5 + 2 >= 3 * 4`\n", + "\n", + "
\n", + " Answer\n", + "\n", + " `*` > `+` > `>=`\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 6 * 3, 7 * 4, 18 + 28 \n", + "# = 46\n", + "# 3 ** 4 (81), 2 * 81 (162), 5 - 162 \n", + "# = -157\n", + "# (5-2), 3 ** 4, 3 * 81 \n", + "# = 243\n", + "# 3 * 4, 5 + 2 \n", + "# FALSE" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMhUBNX+UP2C+YDtVSxQKBK", + "collapsed_sections": [], + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Data Type Nov 26.ipynb b/Data Type Nov 26.ipynb new file mode 100644 index 000000000..3863f85b5 --- /dev/null +++ b/Data Type Nov 26.ipynb @@ -0,0 +1,291 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# November 26th, 2024" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello world\n" + ] + } + ], + "source": [ + "print(\"hello world\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4+2" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-5" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "9 // -2" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1.5 * 2 >= 7 - 3" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "46" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "6 * 3 + 7 * 4" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-157" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5 - 2 * 3 ** 4" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "243" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(5-2)* 3 ** 4" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "9//5\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.8" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "9/5" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "def c_to_f(degrees_c):\n", + " degrees_f = (9/5) * degrees_c + 32\n", + " return degrees_f" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "50.0" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c_to_f(10)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dsi_participant", + "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.9.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}