{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "### **Chapter 1 Exercise**"
      ],
      "metadata": {
        "id": "-gxiky3QPMnT"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Exercise 1**"
      ],
      "metadata": {
        "id": "rvMyq-3pXdus"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "id": "cDVIwCbTPF7S"
      },
      "outputs": [],
      "source": [
        "def print_odd_numbers():\n",
        "    for number in range(101, 200, 2):\n",
        "        print(number)"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "print_odd_numbers()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "uVnS_-peXaHq",
        "outputId": "aa56bf79-7057-4256-ad22-cd26f2e58e3c"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "101\n",
            "103\n",
            "105\n",
            "107\n",
            "109\n",
            "111\n",
            "113\n",
            "115\n",
            "117\n",
            "119\n",
            "121\n",
            "123\n",
            "125\n",
            "127\n",
            "129\n",
            "131\n",
            "133\n",
            "135\n",
            "137\n",
            "139\n",
            "141\n",
            "143\n",
            "145\n",
            "147\n",
            "149\n",
            "151\n",
            "153\n",
            "155\n",
            "157\n",
            "159\n",
            "161\n",
            "163\n",
            "165\n",
            "167\n",
            "169\n",
            "171\n",
            "173\n",
            "175\n",
            "177\n",
            "179\n",
            "181\n",
            "183\n",
            "185\n",
            "187\n",
            "189\n",
            "191\n",
            "193\n",
            "195\n",
            "197\n",
            "199\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Exercise 2**"
      ],
      "metadata": {
        "id": "PkG1YQWBXhV3"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def is_prime(n):\n",
        "    \"\"\"Check if a number is prime.\"\"\"\n",
        "    if n <= 1:\n",
        "        return False\n",
        "    for i in range(2, int(n ** 0.5) + 1):\n",
        "        if n % i == 0:\n",
        "            return False\n",
        "    return True\n",
        "\n",
        "def find_primes_in_range(start, end):\n",
        "    \"\"\"Find all prime numbers in a given range.\"\"\"\n",
        "    primes = []\n",
        "    for num in range(start, end + 1):\n",
        "        if is_prime(num):\n",
        "            primes.append(num)\n",
        "    return primes\n",
        "\n",
        "# Define the range\n",
        "start = 1000\n",
        "end = 1500\n",
        "\n",
        "# Find and display prime numbers in the range\n",
        "prime_numbers = find_primes_in_range(start, end)\n",
        "print(f\"Prime numbers from {start} to {end}:\")\n",
        "for prime in prime_numbers:\n",
        "    print(prime)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "yYJTnlV3Xj23",
        "outputId": "be96edc5-ee00-49a8-e213-d59d824688d8"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Prime numbers from 1000 to 1500:\n",
            "1009\n",
            "1013\n",
            "1019\n",
            "1021\n",
            "1031\n",
            "1033\n",
            "1039\n",
            "1049\n",
            "1051\n",
            "1061\n",
            "1063\n",
            "1069\n",
            "1087\n",
            "1091\n",
            "1093\n",
            "1097\n",
            "1103\n",
            "1109\n",
            "1117\n",
            "1123\n",
            "1129\n",
            "1151\n",
            "1153\n",
            "1163\n",
            "1171\n",
            "1181\n",
            "1187\n",
            "1193\n",
            "1201\n",
            "1213\n",
            "1217\n",
            "1223\n",
            "1229\n",
            "1231\n",
            "1237\n",
            "1249\n",
            "1259\n",
            "1277\n",
            "1279\n",
            "1283\n",
            "1289\n",
            "1291\n",
            "1297\n",
            "1301\n",
            "1303\n",
            "1307\n",
            "1319\n",
            "1321\n",
            "1327\n",
            "1361\n",
            "1367\n",
            "1373\n",
            "1381\n",
            "1399\n",
            "1409\n",
            "1423\n",
            "1427\n",
            "1429\n",
            "1433\n",
            "1439\n",
            "1447\n",
            "1451\n",
            "1453\n",
            "1459\n",
            "1471\n",
            "1481\n",
            "1483\n",
            "1487\n",
            "1489\n",
            "1493\n",
            "1499\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Exercise 3"
      ],
      "metadata": {
        "id": "L2xbhI-bXuqv"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def find_smallest(num1, num2, num3):\n",
        "    \"\"\"Return the smallest of the three numbers.\"\"\"\n",
        "    return min(num1, num2, num3)\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Taking input from the user\n",
        "    number1 = float(input(\"Enter the first number: \"))\n",
        "    number2 = float(input(\"Enter the second number: \"))\n",
        "    number3 = float(input(\"Enter the third number: \"))\n",
        "\n",
        "    # Finding the smallest number\n",
        "    smallest = find_smallest(number1, number2, number3)\n",
        "\n",
        "    # Printing the result\n",
        "    print(f\"The smallest number among {number1}, {number2}, and {number3} is {smallest}.\")\n",
        "except ValueError:\n",
        "    print(\"Please enter valid numbers.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "t3zQI00RX1RQ",
        "outputId": "3d67fb86-bf43-4db7-c33e-55d1f8967407"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter the first number: 3\n",
            "Enter the second number: 1\n",
            "Enter the third number: 5\n",
            "The smallest number among 3.0, 1.0, and 5.0 is 1.0.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Exercise 4**"
      ],
      "metadata": {
        "id": "ly-FICDqYNro"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Given list\n",
        "Ten = [\"92\", \"54\", \"23\", \"10\", \"44\", \"05\", \"67\", \"76\", \"34\", \"82\"]\n",
        "\n",
        "# Print the original list\n",
        "print(\"Original List:\", Ten)\n",
        "\n",
        "# Create a new list which has the first four numbers\n",
        "first_four = Ten[:4]\n",
        "print(\"First Four Numbers:\", first_four)\n",
        "\n",
        "# Create a new list which has the last four numbers\n",
        "last_four = Ten[-4:]\n",
        "print(\"Last Four Numbers:\", last_four)\n",
        "\n",
        "# Create a new list which has numbers between 44 to 82\n",
        "numbers_between_44_and_82 = [num for num in Ten if 44 <= int(num) <= 82]\n",
        "print(\"Numbers Between 44 and 82:\", numbers_between_44_and_82)\n",
        "\n",
        "# Create a new list which has numbers at odd places\n",
        "numbers_at_odd_places = Ten[::2]\n",
        "print(\"Numbers at Odd Places:\", numbers_at_odd_places)\n",
        "\n",
        "# Create a new list which has numbers at even places\n",
        "numbers_at_even_places = Ten[1::2]\n",
        "print(\"Numbers at Even Places:\", numbers_at_even_places)\n",
        "\n",
        "# Create a new list which is the reverse of the list Ten\n",
        "reversed_list = Ten[::-1]\n",
        "print(\"Reversed List:\", reversed_list)\n",
        "\n",
        "# Create a new list which has the first two and last two numbers\n",
        "first_two_and_last_two = Ten[:2] + Ten[-2:]\n",
        "print(\"First Two and Last Two Numbers:\", first_two_and_last_two)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "6bx4KJLeYP9H",
        "outputId": "1dbba419-3445-4306-8ba1-43830f7202fe"
      },
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Original List: ['92', '54', '23', '10', '44', '05', '67', '76', '34', '82']\n",
            "First Four Numbers: ['92', '54', '23', '10']\n",
            "Last Four Numbers: ['67', '76', '34', '82']\n",
            "Numbers Between 44 and 82: ['54', '44', '67', '76', '82']\n",
            "Numbers at Odd Places: ['92', '23', '44', '67', '34']\n",
            "Numbers at Even Places: ['54', '10', '05', '76', '82']\n",
            "Reversed List: ['82', '34', '76', '67', '05', '44', '10', '23', '54', '92']\n",
            "First Two and Last Two Numbers: ['92', '54', '34', '82']\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Exercise 5**"
      ],
      "metadata": {
        "id": "8vL25zQrYRxH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "\n",
        "# Data\n",
        "students = [\"student1\", \"student2\", \"student3\", \"student4\", \"student5\", \"student6\", \"student7\"]\n",
        "maths = [82, 80, 45, 36, 94, 59, 60]\n",
        "science = [47, 33, 59, 62, 61, 64, 33]\n",
        "english = [39, 32, 90, 29, 87, 75, 91]\n",
        "hindi = [30, 63, 51, 57, 36, 59, 52]\n",
        "\n",
        "# Create a dataframe\n",
        "df = pd.DataFrame({\n",
        "    'Name': students,\n",
        "    'Maths': maths,\n",
        "    'Science': science,\n",
        "    'English': english,\n",
        "    'Hindi': hindi\n",
        "})\n",
        "\n",
        "# Calculate total and percentage\n",
        "df['Total'] = df[['Maths', 'Science', 'English', 'Hindi']].sum(axis=1)\n",
        "df['Percentage'] = df['Total'] / 4\n",
        "\n",
        "# Add Result column\n",
        "df['Result'] = df['Percentage'].apply(lambda x: 'PASS' if x >= 40 else 'FAIL')\n",
        "\n",
        "# Add Division column\n",
        "def get_division(percentage):\n",
        "    if percentage >= 60:\n",
        "        return 'FIRST'\n",
        "    elif 50 <= percentage < 60:\n",
        "        return 'SECOND'\n",
        "    elif 40 <= percentage < 50:\n",
        "        return 'THIRD'\n",
        "    else:\n",
        "        return 'FAIL'\n",
        "\n",
        "df['Division'] = df['Percentage'].apply(get_division)\n",
        "\n",
        "# Sort the dataframe by Division\n",
        "sorted_by_division = df.sort_values(by='Division')\n",
        "print(\"DataFrame sorted by Division:\")\n",
        "print(sorted_by_division)\n",
        "\n",
        "# Sort the dataframe by Total in ascending order\n",
        "sorted_by_total = df.sort_values(by='Total')\n",
        "print(\"\\nDataFrame sorted by Total (ascending):\")\n",
        "print(sorted_by_total)\n",
        "\n",
        "# Filter students with Percentage equal to 60\n",
        "students_with_60_percentage = df[df['Percentage'] == 60]\n",
        "print(\"\\nStudents with 60% marks:\")\n",
        "print(students_with_60_percentage)\n",
        "\n",
        "# Filter students with THIRD Division\n",
        "third_division_students = df[df['Division'] == 'THIRD']\n",
        "print(\"\\nStudents with THIRD Division:\")\n",
        "print(third_division_students)\n",
        "\n",
        "# Extract only the Division column\n",
        "division_column = df[['Division']]\n",
        "print(\"\\nDivision column:\")\n",
        "print(division_column)\n",
        "\n",
        "# Extract only the third row\n",
        "third_row = df.iloc[2]\n",
        "print(\"\\nThird row:\")\n",
        "print(third_row)\n",
        "\n",
        "# Create a new dataframe with Name and Division only\n",
        "name_and_division_df = df[['Name', 'Division']]\n",
        "print(\"\\nNew DataFrame with Name and Division only:\")\n",
        "print(name_and_division_df)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "y4ZA2Yc1YUO3",
        "outputId": "14d23302-5160-43e0-80fc-d5cb262ea38e"
      },
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "DataFrame sorted by Division:\n",
            "       Name  Maths  Science  English  Hindi  Total  Percentage Result Division\n",
            "2  student3     45       59       90     51    245       61.25   PASS    FIRST\n",
            "4  student5     94       61       87     36    278       69.50   PASS    FIRST\n",
            "5  student6     59       64       75     59    257       64.25   PASS    FIRST\n",
            "1  student2     80       33       32     63    208       52.00   PASS   SECOND\n",
            "6  student7     60       33       91     52    236       59.00   PASS   SECOND\n",
            "0  student1     82       47       39     30    198       49.50   PASS    THIRD\n",
            "3  student4     36       62       29     57    184       46.00   PASS    THIRD\n",
            "\n",
            "DataFrame sorted by Total (ascending):\n",
            "       Name  Maths  Science  English  Hindi  Total  Percentage Result Division\n",
            "3  student4     36       62       29     57    184       46.00   PASS    THIRD\n",
            "0  student1     82       47       39     30    198       49.50   PASS    THIRD\n",
            "1  student2     80       33       32     63    208       52.00   PASS   SECOND\n",
            "6  student7     60       33       91     52    236       59.00   PASS   SECOND\n",
            "2  student3     45       59       90     51    245       61.25   PASS    FIRST\n",
            "5  student6     59       64       75     59    257       64.25   PASS    FIRST\n",
            "4  student5     94       61       87     36    278       69.50   PASS    FIRST\n",
            "\n",
            "Students with 60% marks:\n",
            "Empty DataFrame\n",
            "Columns: [Name, Maths, Science, English, Hindi, Total, Percentage, Result, Division]\n",
            "Index: []\n",
            "\n",
            "Students with THIRD Division:\n",
            "       Name  Maths  Science  English  Hindi  Total  Percentage Result Division\n",
            "0  student1     82       47       39     30    198        49.5   PASS    THIRD\n",
            "3  student4     36       62       29     57    184        46.0   PASS    THIRD\n",
            "\n",
            "Division column:\n",
            "  Division\n",
            "0    THIRD\n",
            "1   SECOND\n",
            "2    FIRST\n",
            "3    THIRD\n",
            "4    FIRST\n",
            "5    FIRST\n",
            "6   SECOND\n",
            "\n",
            "Third row:\n",
            "Name          student3\n",
            "Maths               45\n",
            "Science             59\n",
            "English             90\n",
            "Hindi               51\n",
            "Total              245\n",
            "Percentage       61.25\n",
            "Result            PASS\n",
            "Division         FIRST\n",
            "Name: 2, dtype: object\n",
            "\n",
            "New DataFrame with Name and Division only:\n",
            "       Name Division\n",
            "0  student1    THIRD\n",
            "1  student2   SECOND\n",
            "2  student3    FIRST\n",
            "3  student4    THIRD\n",
            "4  student5    FIRST\n",
            "5  student6    FIRST\n",
            "6  student7   SECOND\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Exercise 6**"
      ],
      "metadata": {
        "id": "GfPfgcP-YtbW"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import statistics as st\n",
        "\n",
        "# Given list of numbers\n",
        "numbers = [17, 43, 33, 61, 62, 15, 26, 17, 28, 49]\n",
        "\n",
        "# Use lambda function to identify ODD numbers\n",
        "odd_numbers = list(filter(lambda x: x % 2 != 0, numbers))\n",
        "print(\"Odd numbers:\", odd_numbers)\n",
        "\n",
        "# Use lambda function to calculate the cube of these numbers\n",
        "cubed_numbers = list(map(lambda x: x ** 3, numbers))\n",
        "print(\"Cubed numbers:\", cubed_numbers)\n",
        "\n",
        "# Calculate mean, median, mode, standard deviation, and variance\n",
        "mean = st.mean(numbers)\n",
        "median = st.median(numbers)\n",
        "mode = st.mode(numbers)\n",
        "stdev = st.stdev(numbers)\n",
        "variance = st.variance(numbers)\n",
        "\n",
        "print(f\"Mean: {mean}\")\n",
        "print(f\"Median: {median}\")\n",
        "print(f\"Mode: {mode}\")\n",
        "print(f\"Standard Deviation: {stdev}\")\n",
        "print(f\"Variance: {variance}\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "andv9XbAYwvf",
        "outputId": "a3b8a7d8-9ea0-4de3-be23-89d54111327d"
      },
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Odd numbers: [17, 43, 33, 61, 15, 17, 49]\n",
            "Cubed numbers: [4913, 79507, 35937, 226981, 238328, 3375, 17576, 4913, 21952, 117649]\n",
            "Mean: 35.1\n",
            "Median: 30.5\n",
            "Mode: 17\n",
            "Standard Deviation: 17.785449733482203\n",
            "Variance: 316.3222222222222\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Exercise 7**"
      ],
      "metadata": {
        "id": "TDIMIOmfZEiH"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def is_prime(number):\n",
        "    \"\"\"Check if a number is prime.\"\"\"\n",
        "    if number <= 1:\n",
        "        return False\n",
        "    for i in range(2, int(number ** 0.5) + 1):\n",
        "        if number % i == 0:\n",
        "            return False\n",
        "    return True\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Taking input from the user\n",
        "    user_input = int(input(\"Enter a number: \"))\n",
        "\n",
        "    # Checking if the number is prime\n",
        "    if is_prime(user_input):\n",
        "        print(f\"The number {user_input} is prime.\")\n",
        "    else:\n",
        "        print(f\"The number {user_input} is not prime.\")\n",
        "except ValueError:\n",
        "    print(\"Please enter a valid integer.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "IzaN3H24ZGvv",
        "outputId": "3d7e8533-71bf-41e7-efcd-1cd7d0772cbc"
      },
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter a number: 7\n",
            "The number 7 is prime.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# **Exercise 8**"
      ],
      "metadata": {
        "id": "HE2ELH0YZQy_"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def fibonacci_series(n):\n",
        "    \"\"\"Print Fibonacci series up to n.\"\"\"\n",
        "    a, b = 0, 1\n",
        "    print(\"Fibonacci series up to\", n, \":\")\n",
        "    while a <= n:\n",
        "        print(a, end=\" \")\n",
        "        a, b = b, a + b\n",
        "    print()\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Taking input from the user\n",
        "    user_input = int(input(\"Enter a number: \"))\n",
        "\n",
        "    # Printing the Fibonacci series up to the given number\n",
        "    fibonacci_series(user_input)\n",
        "except ValueError:\n",
        "    print(\"Please enter a valid integer.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "2PL3TmfoZVJU",
        "outputId": "7a1897ee-b06d-4c02-87be-0eaf55082e79"
      },
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter a number: 11\n",
            "Fibonacci series up to 11 :\n",
            "0 1 1 2 3 5 8 \n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Exercise 9**"
      ],
      "metadata": {
        "id": "7kBLvRsYZxgf"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def calculate_shaded_area(length, breadth):\n",
        "    \"\"\"Calculate the area of the shaded region.\"\"\"\n",
        "    if length <= 2 or breadth <= 2:\n",
        "        return \"Length and breadth must be greater than 2 meters.\"\n",
        "\n",
        "    outer_area = length * breadth\n",
        "    inner_length = length - 2  # Subtract 2 meters for the uniform width of 1 meter on each side\n",
        "    inner_breadth = breadth - 2  # Subtract 2 meters for the uniform width of 1 meter on each side\n",
        "    inner_area = inner_length * inner_breadth\n",
        "\n",
        "    shaded_area = outer_area - inner_area\n",
        "    return shaded_area\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Taking input from the user\n",
        "    length = float(input(\"Enter the length (L) of the bigger rectangle in meters: \"))\n",
        "    breadth = float(input(\"Enter the breadth (B) of the bigger rectangle in meters: \"))\n",
        "\n",
        "    # Calculate and print the area of the shaded region\n",
        "    result = calculate_shaded_area(length, breadth)\n",
        "    print(f\"The area of the shaded region is: {result} square meters\")\n",
        "except ValueError:\n",
        "    print(\"Please enter valid numerical values for length and breadth.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "gp4TyQ-kZ0Ew",
        "outputId": "369ab7b8-9c7c-4ec6-ce1a-d1e06fbb5327"
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Enter the length (L) of the bigger rectangle in meters: 100\n",
            "Enter the breadth (B) of the bigger rectangle in meters: 20\n",
            "The area of the shaded region is: 236.0 square meters\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Exercise 10**"
      ],
      "metadata": {
        "id": "s-1r5bw_Z4tX"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import math\n",
        "\n",
        "def calculate_circle_area(diameter):\n",
        "    \"\"\"Calculate the area of a circle given its diameter.\"\"\"\n",
        "    radius = diameter / 2\n",
        "    area = math.pi * (radius ** 2)\n",
        "    return area\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Given diameter\n",
        "    diameter = 2  # meters\n",
        "\n",
        "    # Calculate the area of the circle\n",
        "    area = calculate_circle_area(diameter)\n",
        "\n",
        "    # Print the result\n",
        "    print(f\"The area of a circle with a diameter of {diameter} meters is: {area:.2f} square meters\")\n",
        "except ValueError:\n",
        "    print(\"Please enter a valid numerical value for the diameter.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "HqejPWaYZ7uB",
        "outputId": "c37df3d2-508e-4857-e654-45c6f82a24e6"
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The area of a circle with a diameter of 2 meters is: 3.14 square meters\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Exercise 11**"
      ],
      "metadata": {
        "id": "QRf3yf76aH__"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import math\n",
        "\n",
        "def calculate_hypotenuse(base, height):\n",
        "    \"\"\"Calculate the hypotenuse of a right-angled triangle given its base and height.\"\"\"\n",
        "    hypotenuse = math.sqrt(base**2 + height**2)\n",
        "    return hypotenuse\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Given base and height\n",
        "    base = 10  # meters\n",
        "    height = 12  # meters\n",
        "\n",
        "    # Calculate the hypotenuse\n",
        "    hypotenuse = calculate_hypotenuse(base, height)\n",
        "\n",
        "    # Print the result\n",
        "    print(f\"The hypotenuse of a right-angled triangle with base {base} meters and height {height} meters is: {hypotenuse:.2f} meters\")\n",
        "except ValueError:\n",
        "    print(\"Please enter valid numerical values for base and height.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "0IFm9uVSaKIn",
        "outputId": "aaa16165-8450-492d-f7b2-c2e89f040756"
      },
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The hypotenuse of a right-angled triangle with base 10 meters and height 12 meters is: 15.62 meters\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Exercise 12**"
      ],
      "metadata": {
        "id": "ykvnUR_GaapX"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import math\n",
        "\n",
        "def calculate_distance(x1, y1, x2, y2):\n",
        "    \"\"\"Calculate the distance between two points (x1, y1) and (x2, y2).\"\"\"\n",
        "    distance = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)\n",
        "    return distance\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Coordinates of points A and B\n",
        "    x1, y1 = 7, 8\n",
        "    x2, y2 = 2, 3\n",
        "\n",
        "    # Calculate the distance between A and B\n",
        "    distance = calculate_distance(x1, y1, x2, y2)\n",
        "\n",
        "    # Print the result\n",
        "    print(f\"The distance between points A({x1}, {y1}) and B({x2}, {y2}) is: {distance:.2f} units\")\n",
        "except ValueError:\n",
        "    print(\"Please enter valid numerical values for coordinates.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "S_cIb53XafNn",
        "outputId": "5d5ff857-743a-4b86-814e-3433bbfac014"
      },
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The distance between points A(7, 8) and B(2, 3) is: 7.07 units\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Exercise 13**"
      ],
      "metadata": {
        "id": "-55ZppG5andJ"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def calculate_simple_interest(principal, rate, time):\n",
        "    \"\"\"Calculate simple interest.\"\"\"\n",
        "    interest = principal * rate * time\n",
        "    return interest\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Given values\n",
        "    principal = 10000  # initial investment in dollars\n",
        "    annual_rate = 0.05  # annual interest rate (5%)\n",
        "    time_in_years = 3  # time in years\n",
        "\n",
        "    # Calculate the interest\n",
        "    interest = calculate_simple_interest(principal, annual_rate, time_in_years)\n",
        "\n",
        "    # Print the result\n",
        "    print(f\"The amount of interest earned on an investment of ${principal} at an annual interest rate of {annual_rate*100}% over {time_in_years} years is: ${interest:.2f}\")\n",
        "except ValueError:\n",
        "    print(\"Please enter valid numerical values for principal, rate, and time.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "D6pCifrIaprQ",
        "outputId": "f3a1aeaf-244c-4057-b074-1a763b88a318"
      },
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The amount of interest earned on an investment of $10000 at an annual interest rate of 5.0% over 3 years is: $1500.00\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Exercise 14**"
      ],
      "metadata": {
        "id": "3-h5Vu2za5H7"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def calculate_compound_interest(principal, rate, times_compounded, years):\n",
        "    \"\"\"Calculate the total amount in the account with compound interest.\"\"\"\n",
        "    amount = principal * (1 + rate / times_compounded) ** (times_compounded * years)\n",
        "    return amount\n",
        "\n",
        "# Main program\n",
        "try:\n",
        "    # Given values\n",
        "    principal = 5000  # initial deposit in dollars\n",
        "    annual_rate = 0.04  # annual interest rate (4%)\n",
        "    times_compounded = 4  # interest compounded quarterly\n",
        "    years = 5  # time in years\n",
        "\n",
        "    # Calculate the total amount\n",
        "    total_amount = calculate_compound_interest(principal, annual_rate, times_compounded, years)\n",
        "\n",
        "    # Print the result\n",
        "    print(f\"The total amount in the account after {years} years is: ${total_amount:.2f}\")\n",
        "except ValueError:\n",
        "    print(\"Please enter valid numerical values for principal, rate, times compounded, and years.\")"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 0
        },
        "id": "-F3NeoyKa7Mn",
        "outputId": "28ec3582-6cd9-4caf-a0b3-aa1f14f06029"
      },
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "The total amount in the account after 5 years is: $6100.95\n"
          ]
        }
      ]
    }
  ]
}