From 688680d737648bafedc30443890cfec57632afb6 Mon Sep 17 00:00:00 2001 From: thisiszhu22 Date: Mon, 7 Oct 2024 14:52:12 +0800 Subject: [PATCH 1/3] name --- zhu22.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 zhu22.txt diff --git a/zhu22.txt b/zhu22.txt new file mode 100644 index 0000000..2404bdd --- /dev/null +++ b/zhu22.txt @@ -0,0 +1 @@ +Aye Thida Aung From ae9b247c2a18226e4f3d21162867c4ee42241fde Mon Sep 17 00:00:00 2001 From: ZHU <148061459+thisiszhu22@users.noreply.github.com> Date: Fri, 10 Oct 2025 13:24:29 +0800 Subject: [PATCH 2/3] Created using Colab --- DAC_001_Intro_to_Python_Tutorial.ipynb | 463 +++++++++++++++++++++++++ 1 file changed, 463 insertions(+) create mode 100644 DAC_001_Intro_to_Python_Tutorial.ipynb diff --git a/DAC_001_Intro_to_Python_Tutorial.ipynb b/DAC_001_Intro_to_Python_Tutorial.ipynb new file mode 100644 index 0000000..7fbf595 --- /dev/null +++ b/DAC_001_Intro_to_Python_Tutorial.ipynb @@ -0,0 +1,463 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyM1FkiW2isL1AtVmL8Tlap2", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 1: Lists Task: (a) Create a list named fruits with the items \"apple\", \"orange\", and \"banana\". (b) Add \"tomato\" to the end of the fruits list. (c) Remove \"apple\" from the fruits list.\n", + "\n" + ], + "metadata": { + "id": "YueCjHtrleRC" + } + }, + { + "cell_type": "code", + "source": [ + "fruits=[\"apple\",\"orange\",\"banana\"]\n", + "fruits.append(\"tomato\")\n", + "print(fruits)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "6wqHnczFnkMk", + "outputId": "28eadccc-5a9a-44ce-bd82-a127da1c1184" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "['apple', 'orange', 'banana', 'tomato']\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 2: Tuples Task: (a) Create a tuple named subjects with the following elements: \"physics\", \"chemistry\", \"english\", \"math\", and \"biology\". (b) Attempt to append \"literature\" to the tuple and observe the result. Suggest an alternative way to add an element to a tuple. (c) Count the number of elements in the subjects tuple.\n" + ], + "metadata": { + "id": "D40NXOXKltUi" + } + }, + { + "cell_type": "code", + "source": [ + "subjects=(\"physics\",\"chemistry\",\"english\",\"math\",\"biology\")\n", + "subjects_list=(list(subjects))\n", + "print(type(subjects_list))\n", + "\n", + "subjects_list.append(\"literature\")\n", + "print(subjects_list)\n", + "\n", + "subjects=(tuple(subjects_list))\n", + "print(type(subjects))\n", + "print(subjects)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "KIuZsFuj37QU", + "outputId": "51719a87-d7af-43fa-cd63-1a4bc19c0710" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "['physics', 'chemistry', 'english', 'math', 'biology', 'literature']\n", + "\n", + "('physics', 'chemistry', 'english', 'math', 'biology', 'literature')\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 3: Sorting Lists Task: (a) Create a list named students_id with the values [10, 6, 7, 8, 9, 3]. (b) Sort the list in descending order and reinitialize it as sorted_students_id. (c) Remove all elements from the sorted_students_id list." + ], + "metadata": { + "id": "awPe_2nWmBWc" + } + }, + { + "cell_type": "code", + "source": [ + "student_id=[10,6,7,8,9,3]\n", + "\n", + "sorted_students_id=sorted(student_id)\n", + "print(sorted_students_id)\n", + "sorted_students_id.reverse()\n", + "print(sorted_students_id)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "HMtOkkmSFnJh", + "outputId": "ad421ac2-5ddd-4916-acfc-e21584a73ab3" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[3, 6, 7, 8, 9, 10]\n", + "[10, 9, 8, 7, 6, 3]\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 4: Generating Lists Task: Generate a list of numbers starting from 15 and decreasing by 3 each step, until the number is positive (not inclusive of zero). Store it in a variable named desc_list." + ], + "metadata": { + "id": "bthJETONmE-7" + } + }, + { + "cell_type": "code", + "source": [ + "desc_list=list(range(15,0,-3))\n", + "print(desc_list)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "EHarFgeHGpST", + "outputId": "442c384f-0b0e-4086-8660-857298e85cb3" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[15, 12, 9, 6, 3]\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 5: Generating Lists Task: Generate a list of numbers starting from 2, increasing by 2 each step, until the list contains 14 elements. Store it in a variable named asc_list." + ], + "metadata": { + "id": "izXbWVsrmTAH" + } + }, + { + "cell_type": "code", + "source": [ + "asc_list=list(range(2,30,2))\n", + "print(asc_list)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "xg60F9IoHIdy", + "outputId": "61c15100-e0d1-47cc-ecbc-b7fade7a0f4a" + }, + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "test_list=list(range(0,9,1))\n", + "print(test_list)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "uQRBEgW14gD9", + "outputId": "b890041e-02b6-48b1-81ab-0e7982790e3c" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[0, 1, 2, 3, 4, 5, 6, 7, 8]\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 6: Combining and Separating Lists Task: Combine the lists generated in Questions 4 and 5 into a single list named combined_list. Separate the even and odd numbers from combined_list into two separate lists: even_numbers and odd_numbers.\n", + "\n" + ], + "metadata": { + "id": "31hVTmN6manZ" + } + }, + { + "cell_type": "code", + "source": [ + "combined_list=desc_list+asc_list\n", + "print(combined_list)\n", + "\n", + "even_numbers=[]\n", + "odd_numbers=[]\n", + "for num in combined_list:\n", + " if num%2 == 0:\n", + " even_numbers.append(num)\n", + " else:\n", + " odd_numbers.append(num)\n", + "\n", + "print(even_numbers)\n", + "print(odd_numbers)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "0yXjZjXIJYX-", + "outputId": "b99cc0b4-0e30-463b-8fe0-99a1ecaf30f3" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[15, 12, 9, 6, 3, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]\n", + "[12, 6, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]\n", + "[15, 9, 3]\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 7: Functions Task: Create a function circle_properties(radius) that takes in the radius of a circle and returns both the area and circumference.\n", + "\n" + ], + "metadata": { + "id": "hoxRaGhVmeiF" + } + }, + { + "cell_type": "code", + "source": [ + "import math\n", + "def circle_properties(radius):\n", + " area=math.pi * (radius**2)\n", + " circumference=2*math.pi *radius\n", + " return area,circumference\n", + "\n", + "circle_properties(5)\n", + "print(\"Area:\",area)\n", + "print(\"Circumference:\",circumference)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "vIh6_EmvMtyS", + "outputId": "20f24a50-25e4-4494-d305-82960b1287c2" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Area: 78.53981633974483\n", + "Circumference: 31.41592653589793\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 8: Custom Function Task: Define a function that performs a task you find interesting. Demonstrate how this function works.\n", + "\n" + ], + "metadata": { + "id": "iF5YbQbHmiIV" + } + }, + { + "cell_type": "code", + "source": [ + "def bmi_calculator( weight, height): # kg and meter\n", + " bmi= round (weight/(height ** 2))\n", + " if bmi< 18.5:\n", + " category =\"Underweight\"\n", + " elif bmi<25:\n", + " category=\"Normal weight\"\n", + " elif bmi< 30:\n", + " category=\"Overweight\"\n", + " else:\n", + " category=\"Obese\"\n", + "\n", + " return bmi, category\n", + "\n", + "result=bmi_calculator(78,1.54)\n", + "print(\"YOUR BMI is \", result)\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "-VPHHzdoSPeL", + "outputId": "eac83b82-6b2a-4c8c-815b-0629e8f63d47" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "YOUR BMI is (33, 'Obese')\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 9: Creating and Manipulating Dictionaries Task: (a) Create a dictionary named student_grades with the following keys and values: \"Alice\": 85, \"Bob\": 90, and \"Charlie\": 78. (b) Add a new student, \"David\", with a grade of 92 to the student_grades dictionary. (c) Update \"Alice\"'s grade to 88.\n", + "\n", + "\n" + ], + "metadata": { + "id": "i8YxmMqMzGDs" + } + }, + { + "cell_type": "code", + "source": [ + "student_grades={\n", + " \"Alice\":85,\n", + " \"Bob\":90,\n", + " \"Charlie\":78\n", + "}\n", + "print(student_grades)\n", + "\n", + "student_grades.update({'David':92})\n", + "print(student_grades)\n", + "\n", + "student_grades['Alice']=88\n", + "print(student_grades)" + ], + "metadata": { + "id": "Y8gOprvdzLKO", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "69cc61c8-dd45-4cf8-b567-9e49200956fd" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "{'Alice': 85, 'Bob': 90, 'Charlie': 78}\n", + "{'Alice': 85, 'Bob': 90, 'Charlie': 78, 'David': 92}\n", + "{'Alice': 88, 'Bob': 90, 'Charlie': 78, 'David': 92}\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Question 10: Using Dictionaries to Count Occurrences Task: Given the list of fruits [\"apple\", \"banana\", \"apple\", \"orange\", \"banana\", \"apple\"], create a dictionary named fruit_count that counts the number of times each fruit appears in the list." + ], + "metadata": { + "id": "pUR4eB2LmrVZ" + } + }, + { + "cell_type": "code", + "source": [ + "fruits=[\"apple\",\"banana\",\"apple\",\"orange\",\"banana\",\"apple\"]\n", + "fruit_count={}\n", + "\n", + "for fruit in fruits:\n", + " if fruit in fruit_count:\n", + " fruit_count[fruit]+=1\n", + " else:\n", + " fruit_count[fruit]=1\n", + "\n", + "print(fruit_count)\n", + "\n", + "\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "ua1ivdm8ix9S", + "outputId": "6d695f86-4a4f-401b-a8e5-e5b15654dab8" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "{'apple': 3, 'banana': 2, 'orange': 1}\n" + ] + } + ] + } + ] +} \ No newline at end of file From a685dcf31e2ba90e6d6bacadc5c67afbf2ef1b5c Mon Sep 17 00:00:00 2001 From: ZHU <148061459+thisiszhu22@users.noreply.github.com> Date: Fri, 10 Oct 2025 13:32:36 +0800 Subject: [PATCH 3/3] Delete DAC_001_Intro_to_Python_Tutorial.ipynb --- DAC_001_Intro_to_Python_Tutorial.ipynb | 463 ------------------------- 1 file changed, 463 deletions(-) delete mode 100644 DAC_001_Intro_to_Python_Tutorial.ipynb diff --git a/DAC_001_Intro_to_Python_Tutorial.ipynb b/DAC_001_Intro_to_Python_Tutorial.ipynb deleted file mode 100644 index 7fbf595..0000000 --- a/DAC_001_Intro_to_Python_Tutorial.ipynb +++ /dev/null @@ -1,463 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [], - "authorship_tag": "ABX9TyM1FkiW2isL1AtVmL8Tlap2", - "include_colab_link": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 1: Lists Task: (a) Create a list named fruits with the items \"apple\", \"orange\", and \"banana\". (b) Add \"tomato\" to the end of the fruits list. (c) Remove \"apple\" from the fruits list.\n", - "\n" - ], - "metadata": { - "id": "YueCjHtrleRC" - } - }, - { - "cell_type": "code", - "source": [ - "fruits=[\"apple\",\"orange\",\"banana\"]\n", - "fruits.append(\"tomato\")\n", - "print(fruits)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "6wqHnczFnkMk", - "outputId": "28eadccc-5a9a-44ce-bd82-a127da1c1184" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "['apple', 'orange', 'banana', 'tomato']\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 2: Tuples Task: (a) Create a tuple named subjects with the following elements: \"physics\", \"chemistry\", \"english\", \"math\", and \"biology\". (b) Attempt to append \"literature\" to the tuple and observe the result. Suggest an alternative way to add an element to a tuple. (c) Count the number of elements in the subjects tuple.\n" - ], - "metadata": { - "id": "D40NXOXKltUi" - } - }, - { - "cell_type": "code", - "source": [ - "subjects=(\"physics\",\"chemistry\",\"english\",\"math\",\"biology\")\n", - "subjects_list=(list(subjects))\n", - "print(type(subjects_list))\n", - "\n", - "subjects_list.append(\"literature\")\n", - "print(subjects_list)\n", - "\n", - "subjects=(tuple(subjects_list))\n", - "print(type(subjects))\n", - "print(subjects)\n" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "KIuZsFuj37QU", - "outputId": "51719a87-d7af-43fa-cd63-1a4bc19c0710" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "\n", - "['physics', 'chemistry', 'english', 'math', 'biology', 'literature']\n", - "\n", - "('physics', 'chemistry', 'english', 'math', 'biology', 'literature')\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 3: Sorting Lists Task: (a) Create a list named students_id with the values [10, 6, 7, 8, 9, 3]. (b) Sort the list in descending order and reinitialize it as sorted_students_id. (c) Remove all elements from the sorted_students_id list." - ], - "metadata": { - "id": "awPe_2nWmBWc" - } - }, - { - "cell_type": "code", - "source": [ - "student_id=[10,6,7,8,9,3]\n", - "\n", - "sorted_students_id=sorted(student_id)\n", - "print(sorted_students_id)\n", - "sorted_students_id.reverse()\n", - "print(sorted_students_id)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "HMtOkkmSFnJh", - "outputId": "ad421ac2-5ddd-4916-acfc-e21584a73ab3" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[3, 6, 7, 8, 9, 10]\n", - "[10, 9, 8, 7, 6, 3]\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 4: Generating Lists Task: Generate a list of numbers starting from 15 and decreasing by 3 each step, until the number is positive (not inclusive of zero). Store it in a variable named desc_list." - ], - "metadata": { - "id": "bthJETONmE-7" - } - }, - { - "cell_type": "code", - "source": [ - "desc_list=list(range(15,0,-3))\n", - "print(desc_list)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "EHarFgeHGpST", - "outputId": "442c384f-0b0e-4086-8660-857298e85cb3" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[15, 12, 9, 6, 3]\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 5: Generating Lists Task: Generate a list of numbers starting from 2, increasing by 2 each step, until the list contains 14 elements. Store it in a variable named asc_list." - ], - "metadata": { - "id": "izXbWVsrmTAH" - } - }, - { - "cell_type": "code", - "source": [ - "asc_list=list(range(2,30,2))\n", - "print(asc_list)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "xg60F9IoHIdy", - "outputId": "61c15100-e0d1-47cc-ecbc-b7fade7a0f4a" - }, - "execution_count": 1, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]\n" - ] - } - ] - }, - { - "cell_type": "code", - "source": [ - "test_list=list(range(0,9,1))\n", - "print(test_list)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "uQRBEgW14gD9", - "outputId": "b890041e-02b6-48b1-81ab-0e7982790e3c" - }, - "execution_count": 2, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[0, 1, 2, 3, 4, 5, 6, 7, 8]\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 6: Combining and Separating Lists Task: Combine the lists generated in Questions 4 and 5 into a single list named combined_list. Separate the even and odd numbers from combined_list into two separate lists: even_numbers and odd_numbers.\n", - "\n" - ], - "metadata": { - "id": "31hVTmN6manZ" - } - }, - { - "cell_type": "code", - "source": [ - "combined_list=desc_list+asc_list\n", - "print(combined_list)\n", - "\n", - "even_numbers=[]\n", - "odd_numbers=[]\n", - "for num in combined_list:\n", - " if num%2 == 0:\n", - " even_numbers.append(num)\n", - " else:\n", - " odd_numbers.append(num)\n", - "\n", - "print(even_numbers)\n", - "print(odd_numbers)\n" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "0yXjZjXIJYX-", - "outputId": "b99cc0b4-0e30-463b-8fe0-99a1ecaf30f3" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "[15, 12, 9, 6, 3, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]\n", - "[12, 6, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]\n", - "[15, 9, 3]\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 7: Functions Task: Create a function circle_properties(radius) that takes in the radius of a circle and returns both the area and circumference.\n", - "\n" - ], - "metadata": { - "id": "hoxRaGhVmeiF" - } - }, - { - "cell_type": "code", - "source": [ - "import math\n", - "def circle_properties(radius):\n", - " area=math.pi * (radius**2)\n", - " circumference=2*math.pi *radius\n", - " return area,circumference\n", - "\n", - "circle_properties(5)\n", - "print(\"Area:\",area)\n", - "print(\"Circumference:\",circumference)" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "vIh6_EmvMtyS", - "outputId": "20f24a50-25e4-4494-d305-82960b1287c2" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Area: 78.53981633974483\n", - "Circumference: 31.41592653589793\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 8: Custom Function Task: Define a function that performs a task you find interesting. Demonstrate how this function works.\n", - "\n" - ], - "metadata": { - "id": "iF5YbQbHmiIV" - } - }, - { - "cell_type": "code", - "source": [ - "def bmi_calculator( weight, height): # kg and meter\n", - " bmi= round (weight/(height ** 2))\n", - " if bmi< 18.5:\n", - " category =\"Underweight\"\n", - " elif bmi<25:\n", - " category=\"Normal weight\"\n", - " elif bmi< 30:\n", - " category=\"Overweight\"\n", - " else:\n", - " category=\"Obese\"\n", - "\n", - " return bmi, category\n", - "\n", - "result=bmi_calculator(78,1.54)\n", - "print(\"YOUR BMI is \", result)\n" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "-VPHHzdoSPeL", - "outputId": "eac83b82-6b2a-4c8c-815b-0629e8f63d47" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "YOUR BMI is (33, 'Obese')\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 9: Creating and Manipulating Dictionaries Task: (a) Create a dictionary named student_grades with the following keys and values: \"Alice\": 85, \"Bob\": 90, and \"Charlie\": 78. (b) Add a new student, \"David\", with a grade of 92 to the student_grades dictionary. (c) Update \"Alice\"'s grade to 88.\n", - "\n", - "\n" - ], - "metadata": { - "id": "i8YxmMqMzGDs" - } - }, - { - "cell_type": "code", - "source": [ - "student_grades={\n", - " \"Alice\":85,\n", - " \"Bob\":90,\n", - " \"Charlie\":78\n", - "}\n", - "print(student_grades)\n", - "\n", - "student_grades.update({'David':92})\n", - "print(student_grades)\n", - "\n", - "student_grades['Alice']=88\n", - "print(student_grades)" - ], - "metadata": { - "id": "Y8gOprvdzLKO", - "colab": { - "base_uri": "https://localhost:8080/" - }, - "outputId": "69cc61c8-dd45-4cf8-b567-9e49200956fd" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "{'Alice': 85, 'Bob': 90, 'Charlie': 78}\n", - "{'Alice': 85, 'Bob': 90, 'Charlie': 78, 'David': 92}\n", - "{'Alice': 88, 'Bob': 90, 'Charlie': 78, 'David': 92}\n" - ] - } - ] - }, - { - "cell_type": "markdown", - "source": [ - "Question 10: Using Dictionaries to Count Occurrences Task: Given the list of fruits [\"apple\", \"banana\", \"apple\", \"orange\", \"banana\", \"apple\"], create a dictionary named fruit_count that counts the number of times each fruit appears in the list." - ], - "metadata": { - "id": "pUR4eB2LmrVZ" - } - }, - { - "cell_type": "code", - "source": [ - "fruits=[\"apple\",\"banana\",\"apple\",\"orange\",\"banana\",\"apple\"]\n", - "fruit_count={}\n", - "\n", - "for fruit in fruits:\n", - " if fruit in fruit_count:\n", - " fruit_count[fruit]+=1\n", - " else:\n", - " fruit_count[fruit]=1\n", - "\n", - "print(fruit_count)\n", - "\n", - "\n" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "ua1ivdm8ix9S", - "outputId": "6d695f86-4a4f-401b-a8e5-e5b15654dab8" - }, - "execution_count": null, - "outputs": [ - { - "output_type": "stream", - "name": "stdout", - "text": [ - "{'apple': 3, 'banana': 2, 'orange': 1}\n" - ] - } - ] - } - ] -} \ No newline at end of file