diff --git a/Ex1_Python_KhinThanHtay.ipynb b/Ex1_Python_KhinThanHtay.ipynb new file mode 100644 index 0000000..15a293e --- /dev/null +++ b/Ex1_Python_KhinThanHtay.ipynb @@ -0,0 +1,497 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "view-in-github" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "thgO68_HZ0Aa" + }, + "source": [ + "# Introduction" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PIh3i0c_Z_yP" + }, + "source": [ + "This section introduces the Python Programming uisng Colab. Follow the instructions and complete the exercises." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gCw6SfeFZ78l" + }, + "source": [ + "# Ex 1 : Check Version" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6Vm-27iLabjm" + }, + "source": [ + "Using the below cell, Import the required library and check the version of the python in your environment. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "PJDYHB4AXVdc" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.12.4 | packaged by Anaconda, Inc. | (main, Jun 18 2024, 10:07:17) [Clang 14.0.6 ]'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import sys\n", + "sys.version" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5qTEiwGlawf5" + }, + "source": [ + "# Ex2 : Convert Currency. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XH8K1p0ypVCg" + }, + "source": [ + "Write a program that asks the user for the amount in usd and converts it to British pounds. The exchange rate is from usd to BP is given as 0.82" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "x9xQXOnRa0MS", + "outputId": "64294c78-0769-4728-f781-9204a1aa51e3" + }, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the amount in USD: 20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "20 usd is equivalent to 16.4 british pound\n" + ] + } + ], + "source": [ + "usd_amount = input (\"Enter the amount in USD: \")\n", + "bp_amount = int(usd_amount) *0.82\n", + "print(\"{} usd is equivalent to {} british pound\".format(usd_amount, bp_amount))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ePfECwUIpli4" + }, + "source": [ + "# Ex 3: Temperature Converter" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Y60hUWDsp3pK" + }, + "source": [ + "Write a program that convert temperature in Feranhite to celsius. " + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "G9PbO6qPoUfn" + }, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the temperature in Feranhite: 80\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80 Feranhite is equivalent to 26 Celsius\n" + ] + } + ], + "source": [ + "temp_Feranhite = input (\"Enter the temperature in Feranhite: \")\n", + "temp_Celsius = int((int(temp_Feranhite) - 32) * 5/9)\n", + "print(\"{} Feranhite is equivalent to {} Celsius\".format(temp_Feranhite, temp_Celsius))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "a2kNRO9Vp7Qz" + }, + "source": [ + "# Ex 4: Daily Maths" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "lItKon9qqEUn" + }, + "source": [ + "You are working in a retail shop. Write a program that computes the total cost for a customer that bought 3 differnt types of fruits : apple, orange, mango. Ask the user to enter the quantity and price for each type. " + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "id": "mIQFjH6wqDma" + }, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter quantity of apple : 2\n", + "Enter unit price of apple : 2\n", + "Enter quantity of orange : 2\n", + "Enter unit price of orange : 2\n", + "Enter quantity of mango : 2\n", + "Enter unit price of mango : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total cost of 3 different types of fruits : 12\n" + ] + } + ], + "source": [ + "qty_apple = int(input (\"Enter quantity of apple :\"))\n", + "unitPrice_apple = int(input (\"Enter unit price of apple :\"))\n", + "total_apple = qty_apple * unitPrice_apple\n", + "\n", + "qty_orange = int(input (\"Enter quantity of orange :\"))\n", + "unitPrice_orange = int(input (\"Enter unit price of orange :\"))\n", + "total_orange = qty_orange * unitPrice_orange\n", + "\n", + "qty_mango = int(input (\"Enter quantity of mango :\"))\n", + "unitPrice_mango = int(input (\"Enter unit price of mango :\"))\n", + "total_mango = qty_mango * unitPrice_mango\n", + "\n", + "total_cost = total_apple + total_orange + total_mango\n", + "print (\"total cost of 3 different types of fruits :\", total_cost)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "31fXlmEQqgvW" + }, + "source": [ + "# Ex 5 : Greeting" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "zvnmj8MGrJIw" + }, + "source": [ + "Write a program to greet the customer who provides the user name. Your program should ask the name of the customer and print \"Hello + customer name\"" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "id": "Z6ynxZMarIXh" + }, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter your name : Krystal\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello Krystal\n" + ] + } + ], + "source": [ + "customer_name = input (\"Enter your name :\")\n", + "print(\"Hello \"+ customer_name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Ex 6: Random Number\n", + "Write a program that generates a random number, x, between 1 and 50, a random number y between 2 and 5, and computes x^y." + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A random number between 1 and 10: 10\n" + ] + } + ], + "source": [ + "from random import randint\n", + "x = randint(1,10)\n", + "print('A random number between 1 and 10: ', x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Ex 7: Greet many times.\n", + "Write a program that generates a random number between 1 and 10 and prints your name that many times." + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generated random number between 1 and 10: 2\n", + "Khin Than Htay\n", + "Khin Than Htay\n" + ] + } + ], + "source": [ + "from random import randint\n", + "x = randint(1,10)\n", + "print(\"Generated random number between 1 and 10: \", x)\n", + "\n", + "name = \"Khin Than Htay\"\n", + "for i in range (x):\n", + " print(name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Ex 8: Computing. \n", + "Write a program that asks the user to enter two numbers, x and y, and computes |x-y|/(x+y)." + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter value of x: 3\n", + "Enter value of y: 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "result of two numbers: 0.25\n" + ] + } + ], + "source": [ + "x = int(input (\"Enter value of x: \"))\n", + "y = int(input (\"Enter value of y: \"))\n", + "result = abs(x-y)/(x + y)\n", + "print(\"result of two numbers: \", result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Ex 9: Computing\n", + "\n", + "Write a program that asks the user for a number of seconds and prints out how many minutes and seconds that is. For instance, 200 seconds is 3 minutes and 20 seconds." + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter number of seconds to compute : 125\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "result will be 2 minutes and 5 seconds\n" + ] + } + ], + "source": [ + "number_of_seconds = int(input (\"Enter number of seconds to compute :\"))\n", + "minutes = int(number_of_seconds // 60)\n", + "seconds = int(number_of_seconds % 60) #modulo for seconds\n", + "\n", + "print(\"result will be {} minutes and {} seconds\".format(minutes, seconds))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Ex 10: Using Math Module\n", + "\n", + "Write a program that asks the user for a number and then prints out the sine, cosine, and tangent of that number." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "num = float(input(\"Enter a number:\"))\n", + "sine_value = math.sin(num)\n", + "print(sine_value)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a number: 23\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-0.8462204041751706\n", + "-0.5328330203333975\n", + "1.588153083391274\n" + ] + } + ], + "source": [ + "import math\n", + "num = float(input (\"Enter a number: \"))\n", + "sine_value = math.sin(num)\n", + "print(sine_value)\n", + "cos_value = math.cos(num)\n", + "print(cos_value)\n", + "tan_value = math.tan(num)\n", + "print(tan_value)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "collapsed_sections": [], + "include_colab_link": true, + "name": "Ex1_Python.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}