diff --git a/Ex3_ConditionEx_SharonWai.ipynb b/Ex3_ConditionEx_SharonWai.ipynb new file mode 100644 index 0000000..8320305 --- /dev/null +++ b/Ex3_ConditionEx_SharonWai.ipynb @@ -0,0 +1,179 @@ +{ + "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 = input(\"Enter a length in centimeters: \")\n", + "length_cm = float(length_cm)\n", + "if length_cm < 0:\n", + " print (\"Entry is invalid\")\n", + "else:\n", + " 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/" + } + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter a length in centimeters: 10\n", + "10.0 is equal to 39.37007874015748\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": [ + "Temp = input(\"Enter a Temperature in Celsius: \")\n", + "Temp = float(Temp)\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 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 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", + "else:\n", + " print(\"The temperature is above the boiling point.\")" + ], + "metadata": { + "id": "UiCbUIcwvqxO", + "outputId": "0326ecaa-4b6c-45a6-9cee-7ff3d6bc85bc", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 22, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter a Temperature in Celsius: 100\n", + "The temperature is at the boiling point.\n" + ] + } + ] + }, + { + "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": [ + "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 senior.\")\n" + ], + "metadata": { + "id": "r8_O-_zLvurf", + "outputId": "91121453-1f60-494c-d8f7-d63c9d8dda28", + "colab": { + "base_uri": "https://localhost:8080/" + } + }, + "execution_count": 26, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "How many credits have you taken: 85\n", + "The student is senior.\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "P-e4rq_8OR9-" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/SharonWai/Ex2_datatypes_SharonWai.ipynb b/SharonWai/Ex2_datatypes_SharonWai.ipynb new file mode 100644 index 0000000..b5834cd --- /dev/null +++ b/SharonWai/Ex2_datatypes_SharonWai.ipynb @@ -0,0 +1,245 @@ +{ + "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": null, + "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.\"\n", + "count = s.lower().count(\"python\")\n", + "print(len(count))" + ] + }, + { + "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 +}