From 149d0fe1d0360dcd526a3562254070b301c6a07b Mon Sep 17 00:00:00 2001 From: SharonWai Date: Fri, 6 Jun 2025 08:45:03 +1000 Subject: [PATCH 1/6] Created using Colab --- Ex2_datatypes_SharonWai.ipynb | 243 ++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 Ex2_datatypes_SharonWai.ipynb diff --git a/Ex2_datatypes_SharonWai.ipynb b/Ex2_datatypes_SharonWai.ipynb new file mode 100644 index 0000000..f0640dc --- /dev/null +++ b/Ex2_datatypes_SharonWai.ipynb @@ -0,0 +1,243 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "X_Unw3z9u2-7" + }, + "source": [ + "Ex 1 : Check the lenght of the string \"My name is python\"" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "KnvAtrwqQ6ZK", + "outputId": "c1bd1989-c921-4d59-d8db-a2312c6b6e68", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "17" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ], + "source": [ + "len(\"My name is python\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "A1yfv87NQ6ZL" + }, + "source": [ + "Ex 2: Check the number of times \"python\" (regardless of cases: PYTHON, python, Python\" appears in the paragraph : \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "_xP6ZW5PQ6ZM" + }, + "outputs": [], + "source": [ + "s = \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vqRx69aFQ6ZN" + }, + "source": [ + "Ex 3: Combine two lists : ls1 = [\"apple\", \"banana\", \"cherry\"] and ls2 = [\"apple\", \"banana\", \"cherry\", \"apple\", \"cherry\"]. Print the number of elements in new list." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "znsNqaRcQ6ZN" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "KJUyRxQLQ6ZN" + }, + "source": [ + "Ex 4: Create a dictionary for the following table:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nfM3q05MQ6ZO" + }, + "source": [ + "| Name | Age |\n", + "| --- | --- |\n", + "| Myo | 32 |\n", + "| Thida | 64 |" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Tic0nWr4Q6ZO" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7-eYCjTOQ6ZO" + }, + "source": [ + "Ex 5: Combine two sets and print the combined set and its length.\n", + "set1 = {\"Name\", \"age\", \"Height\"}\n", + "set2 = {\"Name\", \"status\", \"Education\"}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "B9AgapteQ6ZP" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ClUfmz0gQ6ZP" + }, + "source": [ + "Ex 6: Write a program that asks the user to enter a string. The program should create a new string called new_string from the user's string such that the second character is changed to an asterisk and three exclamation points are attached to the end of the string. Finally, print new_string." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "uOQXGTlDQ6ZP" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GWCUDmOEQ6ZP" + }, + "source": [ + "Ex 7: Write a program that converts the given string 's' to lowercase, removes all Punctuation marks such as period, hyphen, and commas from 's', and prints the resulting string." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "NQomUIQDQ6ZP" + }, + "outputs": [], + "source": [ + "s = \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\"\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-5u0izwFQ6ZQ" + }, + "source": [ + "Ex 8: L1 and L2 should be identical. Write a program that finds the missing number in L2." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Yk4yPg7hQ6ZQ" + }, + "outputs": [], + "source": [ + "from random import randint\n", + "L1 = list(range(1,101))\n", + "L2 = L1.copy()\n", + "L2.remove(randint(1,101))\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_SFDaSthQ6ZQ" + }, + "source": [ + "Ex 9: Write a program to copy the ls1 = [\"apple\", \"banana\", \"cherry\"] to a new list. Add the element \"blueberry\" to the new list, but keep the original list the same." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "gMc7McCDQ6ZQ" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "Ex_2_datatypes.ipynb", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.12.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file From 7e8fd7572487bfbd03a1be460548acc957a70a9e Mon Sep 17 00:00:00 2001 From: SharonWai Date: Fri, 6 Jun 2025 09:52:55 +1000 Subject: [PATCH 2/6] Created using Colab --- Ex2_datatypes_SharonWai.ipynb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Ex2_datatypes_SharonWai.ipynb b/Ex2_datatypes_SharonWai.ipynb index f0640dc..812552b 100644 --- a/Ex2_datatypes_SharonWai.ipynb +++ b/Ex2_datatypes_SharonWai.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "id": "KnvAtrwqQ6ZK", "outputId": "c1bd1989-c921-4d59-d8db-a2312c6b6e68", @@ -62,7 +62,9 @@ }, "outputs": [], "source": [ - "s = \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\"" + "s = \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\"\n", + "count = s.lower().count(\"python\")\n", + "print(len(count))" ] }, { From 0da3302c7f836b3a2857c611ffb03de6578d6f61 Mon Sep 17 00:00:00 2001 From: SharonWai Date: Fri, 13 Jun 2025 15:44:31 +1000 Subject: [PATCH 3/6] Created using Colab --- Ex3_ConditionEx_SharonWai.ipynb | 113 ++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 Ex3_ConditionEx_SharonWai.ipynb diff --git a/Ex3_ConditionEx_SharonWai.ipynb b/Ex3_ConditionEx_SharonWai.ipynb new file mode 100644 index 0000000..8eba5c2 --- /dev/null +++ b/Ex3_ConditionEx_SharonWai.ipynb @@ -0,0 +1,113 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Ex3_ConditionEx.ipynb", + "provenance": [], + "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": [ + "Write a program that asks the user to enter a length in centimeters. If the user enters a negative length, the program should tell the user that the entry is invalid. Otherwise, the program should convert the length to inches and print out the result. There are 2.54 centimeters in an inch.\n" + ], + "metadata": { + "id": "r9njLbxcvG0w" + } + }, + { + "cell_type": "code", + "source": [ + "length_cm = float(input(\"Enter length in centimeters:\"))\n", + "if length_cm < 0:\n", + " print(\"Entry is invalid\")\n", + "else:\n", + " inches_cm = 1 / 2.54\n", + " length_inches = length_cm*inches_cm\n", + " print(f\"{length_cm} centimeter is equal to {length_inches} inches\")" + ], + "metadata": { + "id": "76EFWr1AvMy4", + "outputId": "0d8e5317-a746-48cf-e5f1-a631c9c8a54b", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter length in centimeters:10\n", + "10.0 centimeter is equal to 3.9370078740157477 inches\n" + ] + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "Ask the user to enter a temperature in Celsius. The program should print a message based on the temperature:\n", + "\n", + "* If the temperature is less than -273.15, print that the temperature is invalid because it is below absolute zero.\n", + "* If it is exactly -273.15, print that the temperature is absolute 0.\n", + "* If the temperature is between -273.15 and 0, print that the temperature is below freezing.\n", + "* If it is 0, print that the temperature is at the freezing point.\n", + "* If it is between 0 and 100, print that the temperature is in the normal range.\n", + "* If it is 100, print that the temperature is at the boiling point.\n", + "* If it is above 100, print that the temperature is above the boiling point." + ], + "metadata": { + "id": "zvaDTmuhvNWJ" + } + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "UiCbUIcwvqxO" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Write a program that asks the user how many credits they have taken. If they have taken 23 or less, print that the student is a freshman. If they have taken between 24 and 53, print that they are a sophomore. The range for juniors is 54 to 83, and for seniors it is 84 and over." + ], + "metadata": { + "id": "hoczytNLvrnd" + } + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "r8_O-_zLvurf" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From 3eede5f5f575d528f9530a619363863285b2a514 Mon Sep 17 00:00:00 2001 From: SharonWai Date: Fri, 13 Jun 2025 15:56:33 +1000 Subject: [PATCH 4/6] Created using Colab --- Ex3_ConditionEx_SharonWai.ipynb | 77 ++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/Ex3_ConditionEx_SharonWai.ipynb b/Ex3_ConditionEx_SharonWai.ipynb index 8eba5c2..ad16a61 100644 --- a/Ex3_ConditionEx_SharonWai.ipynb +++ b/Ex3_ConditionEx_SharonWai.ipynb @@ -48,10 +48,10 @@ ], "metadata": { "id": "76EFWr1AvMy4", - "outputId": "0d8e5317-a746-48cf-e5f1-a631c9c8a54b", "colab": { "base_uri": "https://localhost:8080/" - } + }, + "outputId": "0d8e5317-a746-48cf-e5f1-a631c9c8a54b" }, "execution_count": 5, "outputs": [ @@ -84,12 +84,42 @@ }, { "cell_type": "code", - "source": [], + "source": [ + "Temp = input(\"Enter a temperature in Celsius:\")\n", + "Temp = float(Temp)\n", + "if Temp <-273.15:\n", + " print(\"The temperature is invalid because it is below absolute zero\")\n", + "elif Temp == -273.15:\n", + " print(\"The temperature is absolute 0\")\n", + "elif -273.15>Temp>0:\n", + " print(\"The temperature is below freezing\")\n", + "elif Temp == 0:\n", + " print(\"The temperature is at the freezing point\")\n", + "elif 0>Temp>100:\n", + " print(\"The temperature is in the normal range\")\n", + "elif Temp == 100:\n", + " print(\"The temperature is at the boiling point\")\n", + "else:\n", + " print(\"The temperature is above the boiling point\")" + ], "metadata": { - "id": "UiCbUIcwvqxO" + "id": "UiCbUIcwvqxO", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "38ea1cff-d552-4300-8cc1-434f9bbd66fd" }, - "execution_count": null, - "outputs": [] + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter a temperature in Celsius:105\n", + "The temperature is above the boiling point\n" + ] + } + ] }, { "cell_type": "markdown", @@ -100,11 +130,44 @@ "id": "hoczytNLvrnd" } }, + { + "cell_type": "code", + "source": [ + "Credit = input(\"How many credits users have taken?\")\n", + "Credit = int(Credit)\n", + "if Credit <= 23:\n", + " print(\"The student is a freshman\")\n", + "elif Credit >= 24 and Credit <=53:\n", + " print(\"The student is a sophomore\")\n", + "elif Credit >= 54 and Credit <=83:\n", + " print(\"The student is a junior\")\n", + "else:\n", + " print(\"The student is a senior\")" + ], + "metadata": { + "id": "r8_O-_zLvurf", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "55c9aeb3-6033-4cca-dfb4-8233ba4a965f" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "How many credits users have taken?85\n", + "The student is a senior\n" + ] + } + ] + }, { "cell_type": "code", "source": [], "metadata": { - "id": "r8_O-_zLvurf" + "id": "luK9rtam3C7_" }, "execution_count": null, "outputs": [] From 02c277cfbc0053ccca2bc62771f8b9b03ce4e237 Mon Sep 17 00:00:00 2001 From: SharonWai Date: Fri, 13 Jun 2025 22:18:02 +1000 Subject: [PATCH 5/6] Created using Colab --- Ex3_ConditionEx_SharonWai.ipynb | 85 +++++++++++++++++---------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/Ex3_ConditionEx_SharonWai.ipynb b/Ex3_ConditionEx_SharonWai.ipynb index ad16a61..8320305 100644 --- a/Ex3_ConditionEx_SharonWai.ipynb +++ b/Ex3_ConditionEx_SharonWai.ipynb @@ -38,29 +38,30 @@ { "cell_type": "code", "source": [ - "length_cm = float(input(\"Enter length in centimeters:\"))\n", + "length_cm = input(\"Enter a length in centimeters: \")\n", + "length_cm = float(length_cm)\n", "if length_cm < 0:\n", - " print(\"Entry is invalid\")\n", + " print (\"Entry is invalid\")\n", "else:\n", - " inches_cm = 1 / 2.54\n", - " length_inches = length_cm*inches_cm\n", - " print(f\"{length_cm} centimeter is equal to {length_inches} inches\")" + " inches_cm = length_cm / 2.54\n", + " length_in = inches_cm * length_cm\n", + " print(f\"{length_cm} is equal to {length_in}\")\n" ], "metadata": { "id": "76EFWr1AvMy4", + "outputId": "c29bec63-9afd-4a39-ff89-701d235afacf", "colab": { "base_uri": "https://localhost:8080/" - }, - "outputId": "0d8e5317-a746-48cf-e5f1-a631c9c8a54b" + } }, - "execution_count": 5, + "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "Enter length in centimeters:10\n", - "10.0 centimeter is equal to 3.9370078740157477 inches\n" + "Enter a length in centimeters: 10\n", + "10.0 is equal to 39.37007874015748\n" ] } ] @@ -85,38 +86,39 @@ { "cell_type": "code", "source": [ - "Temp = input(\"Enter a temperature in Celsius:\")\n", + "Temp = input(\"Enter a Temperature in Celsius: \")\n", "Temp = float(Temp)\n", - "if Temp <-273.15:\n", - " print(\"The temperature is invalid because it is below absolute zero\")\n", + "\n", + "if Temp < -273.15:\n", + " print(\"The temperature is invalid because it is below absolute zero.\")\n", "elif Temp == -273.15:\n", - " print(\"The temperature is absolute 0\")\n", - "elif -273.15>Temp>0:\n", - " print(\"The temperature is below freezing\")\n", + " print(\"The temperature is absolute 0.\")\n", + "elif Temp > -273.15 and Temp < 0:\n", + " print (\"The temperature is below freezing.\")\n", "elif Temp == 0:\n", - " print(\"The temperature is at the freezing point\")\n", - "elif 0>Temp>100:\n", - " print(\"The temperature is in the normal range\")\n", + " print (\"The temperature is at the freezing point.\")\n", + "elif Temp > 0 and Temp < 100:\n", + " print (\"The temperature is in the normal range.\")\n", "elif Temp == 100:\n", - " print(\"The temperature is at the boiling point\")\n", + " print (\"The temperature is at the boiling point.\")\n", "else:\n", - " print(\"The temperature is above the boiling point\")" + " print(\"The temperature is above the boiling point.\")" ], "metadata": { "id": "UiCbUIcwvqxO", + "outputId": "0326ecaa-4b6c-45a6-9cee-7ff3d6bc85bc", "colab": { "base_uri": "https://localhost:8080/" - }, - "outputId": "38ea1cff-d552-4300-8cc1-434f9bbd66fd" + } }, - "execution_count": 6, + "execution_count": 22, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "Enter a temperature in Celsius:105\n", - "The temperature is above the boiling point\n" + "Enter a Temperature in Celsius: 100\n", + "The temperature is at the boiling point.\n" ] } ] @@ -133,32 +135,33 @@ { "cell_type": "code", "source": [ - "Credit = input(\"How many credits users have taken?\")\n", - "Credit = int(Credit)\n", - "if Credit <= 23:\n", - " print(\"The student is a freshman\")\n", - "elif Credit >= 24 and Credit <=53:\n", - " print(\"The student is a sophomore\")\n", - "elif Credit >= 54 and Credit <=83:\n", - " print(\"The student is a junior\")\n", + "Credits = input(\"How many credits have you taken: \")\n", + "Credits = int(Credits)\n", + "\n", + "if Credits <= 23:\n", + " print(\"The student is a freshman.\")\n", + "elif Credits >= 24 and Credits <= 53:\n", + " print(\"The student is a sophomore.\")\n", + "elif Credits >= 54 and Credits <= 83:\n", + " print(\"The student is junior.\")\n", "else:\n", - " print(\"The student is a senior\")" + " print(\"The student is senior.\")\n" ], "metadata": { "id": "r8_O-_zLvurf", + "outputId": "91121453-1f60-494c-d8f7-d63c9d8dda28", "colab": { "base_uri": "https://localhost:8080/" - }, - "outputId": "55c9aeb3-6033-4cca-dfb4-8233ba4a965f" + } }, - "execution_count": 7, + "execution_count": 26, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ - "How many credits users have taken?85\n", - "The student is a senior\n" + "How many credits have you taken: 85\n", + "The student is senior.\n" ] } ] @@ -167,7 +170,7 @@ "cell_type": "code", "source": [], "metadata": { - "id": "luK9rtam3C7_" + "id": "P-e4rq_8OR9-" }, "execution_count": null, "outputs": [] From 7472890a790ea8217a47d46820cbddce5c7cfcdf Mon Sep 17 00:00:00 2001 From: SharonWai Date: Thu, 19 Jun 2025 08:09:38 +1000 Subject: [PATCH 6/6] Rename Ex2_datatypes_SharonWai.ipynb to SharonWai/Ex2_datatypes_SharonWai.ipynb Move Exercise 02 file to Sharon Wai --- .../Ex2_datatypes_SharonWai.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Ex2_datatypes_SharonWai.ipynb => SharonWai/Ex2_datatypes_SharonWai.ipynb (99%) diff --git a/Ex2_datatypes_SharonWai.ipynb b/SharonWai/Ex2_datatypes_SharonWai.ipynb similarity index 99% rename from Ex2_datatypes_SharonWai.ipynb rename to SharonWai/Ex2_datatypes_SharonWai.ipynb index 812552b..b5834cd 100644 --- a/Ex2_datatypes_SharonWai.ipynb +++ b/SharonWai/Ex2_datatypes_SharonWai.ipynb @@ -242,4 +242,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}