/ 01_python_fundamentals / Mission_01.ipynb
Mission_01.ipynb
   1  {
   2    "nbformat": 4,
   3    "nbformat_minor": 0,
   4    "metadata": {
   5      "colab": {
   6        "provenance": [],
   7        "authorship_tag": "ABX9TyPB/IsiACzZYUL4y7Z08yL2",
   8        "include_colab_link": true
   9      },
  10      "kernelspec": {
  11        "name": "python3",
  12        "display_name": "Python 3"
  13      },
  14      "language_info": {
  15        "name": "python"
  16      }
  17    },
  18    "cells": [
  19      {
  20        "cell_type": "markdown",
  21        "metadata": {
  22          "id": "view-in-github",
  23          "colab_type": "text"
  24        },
  25        "source": [
  26          "<a href=\"https://colab.research.google.com/github/JaeMoonJeong/AI-ML-Portfolio/blob/Jae-Moon/01_python_fundamentals/Mission_01.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
  27        ]
  28      },
  29      {
  30        "cell_type": "markdown",
  31        "source": [
  32          "# 🐍 I. Python Practice Fundamentals"
  33        ],
  34        "metadata": {
  35          "id": "pZv0kaXfh_OW"
  36        }
  37      },
  38      {
  39        "cell_type": "markdown",
  40        "source": [
  41          "___\n",
  42          "## Basic (7 Problems)"
  43        ],
  44        "metadata": {
  45          "id": "GM1juVx3kDRA"
  46        }
  47      },
  48      {
  49        "cell_type": "markdown",
  50        "source": [
  51          "### Problem 1. Print Multiples of Three"
  52        ],
  53        "metadata": {
  54          "id": "YdclbZDbkDOZ"
  55        }
  56      },
  57      {
  58        "cell_type": "markdown",
  59        "source": [
  60          "* **Problem Description**: Write a function that prints only the multiples of 3 from 1 up to $n$.\n",
  61          "* **Function Signature**: `print_multiples_of_three(n: int) -> None`\n",
  62          "* **Input/Output Examples**:\n",
  63          "    * Input: `7` / Output: `3`, `6`\n",
  64          "    * Input: `30` / Output: `3`, `6`, `9`, `12`, `15`, `18`, `21`, `24`, `27`, `30`"
  65        ],
  66        "metadata": {
  67          "id": "Z5YtPwIJiEBX"
  68        }
  69      },
  70      {
  71        "cell_type": "code",
  72        "source": [
  73          "# Problems\n",
  74          "def print_multiples_of_three(n):\n",
  75          "    for i in range (int(n/3)):\n",
  76          "        print (3*(i+1));\n",
  77          "\n"
  78        ],
  79        "metadata": {
  80          "id": "9pMYi7l_jRw4"
  81        },
  82        "execution_count": null,
  83        "outputs": []
  84      },
  85      {
  86        "cell_type": "code",
  87        "source": [
  88          "# LetsGo\n",
  89          "print_multiples_of_three(7)"
  90        ],
  91        "metadata": {
  92          "id": "MR6I-zGWjUQ_",
  93          "colab": {
  94            "base_uri": "https://localhost:8080/"
  95          },
  96          "outputId": "445548fb-6d2d-4ef5-fb11-a16237e75283"
  97        },
  98        "execution_count": null,
  99        "outputs": [
 100          {
 101            "output_type": "stream",
 102            "name": "stdout",
 103            "text": [
 104              "3\n",
 105              "6\n"
 106            ]
 107          }
 108        ]
 109      },
 110      {
 111        "cell_type": "markdown",
 112        "source": [
 113          "### Problem 2. Remove Vowels\n",
 114          "\n",
 115          "* **Problem Description**: Write a function that returns a string with the vowels (a, e, i, o, u) removed from the input string.\n",
 116          "* **Function Signature**: `remove_vowels(s: str) -> str`\n",
 117          "* **Input/Output Examples**:\n",
 118          "    * Input: `\"codeit\"` / Output: `\"cdt\"`\n",
 119          "    * Input: `\"python programming\"` / Output: `\"pythn prgrmmng\"`"
 120        ],
 121        "metadata": {
 122          "id": "9Eg7jLbYkDLi"
 123        }
 124      },
 125      {
 126        "cell_type": "markdown",
 127        "source": [
 128          "- **βœ… Python `len()` Function Summary:**\n",
 129          "    - The `len()` function returns the **number of items (length)** contained within a **Sequence data type** (e.g., String, List, Tuple) in Python.\n",
 130          "\n",
 131          "- **Usage Syntax:**\n",
 132          "    - `len(sequence_variable_or_value)`\n",
 133          "\n",
 134          "- **How it Works (Relevant to Engineering Data):**\n",
 135          "    - **Input:** Any sequence, such as a material code string, a list of measurements, or a file name.\n",
 136          "    - **Output:** The **precise count of elements** within that input.\n",
 137          "    - **Counting Rule:** `len()` accurately counts every Unicode character as a single unit, including **letters, numbers, special characters, and spaces**.\n",
 138          "\n",
 139          "- **Example and Result:**\n",
 140          "    - `len(\"KAIST 연ꡬ\")`\n",
 141          "        - **Result:** **8**\n",
 142          "        - **Composition:** `K`, `A`, `I`, `S`, `T`, **(space)**, `μ—°`, `ꡬ` (8 characters total)\n",
 143          "\n",
 144          "---"
 145        ],
 146        "metadata": {
 147          "id": "t_h3igye_gTd"
 148        }
 149      },
 150      {
 151        "cell_type": "code",
 152        "source": [
 153          "def remove_vowels(s):\n",
 154          "    # 1. Define all vowels (both lowercase and uppercase) to be removed.\n",
 155          "    VOWELS = \"aeiouAEIOU\"\n",
 156          "\n",
 157          "    # 2. Initialize an empty string to store the characters that are NOT vowels.\n",
 158          "    removed_one = \"\"\n",
 159          "\n",
 160          "    # 3. Iterate through each character ('char') in the input string 's'.\n",
 161          "    for char in s:\n",
 162          "        # 4. Check if the current character is NOT present in the VOWELS set.\n",
 163          "        #    This is the core filtering logic.\n",
 164          "        if char not in VOWELS:\n",
 165          "            # 5. If the character is a consonant (or any non-vowel), append it to the result string.\n",
 166          "            removed_one += char\n",
 167          "\n",
 168          "    # 6. Return the new string containing only consonants.\n",
 169          "    return removed_one"
 170        ],
 171        "metadata": {
 172          "id": "WvlOnCCT9v42"
 173        },
 174        "execution_count": null,
 175        "outputs": []
 176      },
 177      {
 178        "cell_type": "code",
 179        "source": [
 180          "# Lets Go\n",
 181          "print(remove_vowels(\"codeit\"))"
 182        ],
 183        "metadata": {
 184          "colab": {
 185            "base_uri": "https://localhost:8080/"
 186          },
 187          "id": "QbxGGTM494An",
 188          "outputId": "dcd4c028-ee61-411c-8c3d-496091bdd5f6"
 189        },
 190        "execution_count": null,
 191        "outputs": [
 192          {
 193            "output_type": "stream",
 194            "name": "stdout",
 195            "text": [
 196              "cdt\n"
 197            ]
 198          }
 199        ]
 200      },
 201      {
 202        "cell_type": "markdown",
 203        "source": [
 204          "### Problem 3. Compare Numbers\n",
 205          "\n",
 206          "* **Problem Description**: Write a function that takes two numbers and returns the larger and smaller number. If the numbers are equal, return the number once.\n",
 207          "* **Function Signature**: `compare_numbers(num1: int, num2: int) -> tuple[int, int] or int`\n",
 208          "* **Input/Output Examples**:\n",
 209          "    * Input: `10, 20` / Output: `(20, 10)`\n",
 210          "    * Input: `30, 30` / Output: `30`"
 211        ],
 212        "metadata": {
 213          "id": "jUzEejEDkDI7"
 214        }
 215      },
 216      {
 217        "cell_type": "code",
 218        "source": [
 219          "def compare_numbers(a, b):\n",
 220          "    # Check if both 'a' and 'b' are integers using the isinstance() function.\n",
 221          "    if not (isinstance(a, int) and isinstance(b, int)):\n",
 222          "        # If either 'a' or 'b' is not an integer, print an error message.\n",
 223          "        print(\"This is not an integer. Please provide an integer type.\")\n",
 224          "        # Exit the function immediately to prevent further execution with invalid data.\n",
 225          "        return\n",
 226          "\n",
 227          "    # Check if 'a' is greater than 'b'.\n",
 228          "    if a > b:\n",
 229          "        # If 'a' is greater, print both numbers (a, b).\n",
 230          "        print(a, b)\n",
 231          "    # Check if 'a' is less than 'b'.\n",
 232          "    elif a < b:\n",
 233          "        # If 'b' is greater, print the numbers in the order (b, a).\n",
 234          "        print(b, a)\n",
 235          "    # If neither condition is met, 'a' and 'b' must be equal.\n",
 236          "    else:\n",
 237          "        # If they are equal, print 'a' (or 'b', as they are the same).\n",
 238          "        print(a)\n",
 239          "\n",
 240          "    # Implicitly returns None. (Return 없이도 μžλ™κ°’ λ°˜ν™˜)"
 241        ],
 242        "metadata": {
 243          "id": "PL47lV-RDncQ"
 244        },
 245        "execution_count": null,
 246        "outputs": []
 247      },
 248      {
 249        "cell_type": "code",
 250        "source": [
 251          "compare_numbers(10, 20)\n",
 252          "compare_numbers(30, 30)"
 253        ],
 254        "metadata": {
 255          "colab": {
 256            "base_uri": "https://localhost:8080/"
 257          },
 258          "id": "2NibBrlXDqhS",
 259          "outputId": "96fac317-4829-4caa-a103-b24f5fa68491"
 260        },
 261        "execution_count": null,
 262        "outputs": [
 263          {
 264            "output_type": "stream",
 265            "name": "stdout",
 266            "text": [
 267              "20 10\n",
 268              "30\n"
 269            ]
 270          }
 271        ]
 272      },
 273      {
 274        "cell_type": "markdown",
 275        "source": [
 276          "### Problem 4. Return String Length\n",
 277          "\n",
 278          "* **Problem Description**: Write a function that returns the length of a string. If the string is empty, return the message: \"λ¬Έμžμ—΄μ΄ λΉ„μ–΄ μžˆμŠ΅λ‹ˆλ‹€.\"\n",
 279          "* **Function Signature**: `check_string_length(string) -> int or str`\n",
 280          "* **Input/Output Examples**:\n",
 281          "    * Input: `\"Python\"` / Output: `6`\n",
 282          "    * Input: `\"\"` / Output: `\"\"The string is empty.\"`"
 283        ],
 284        "metadata": {
 285          "id": "tAQ2OpvqkDGV"
 286        }
 287      },
 288      {
 289        "cell_type": "code",
 290        "source": [
 291          "def check_string_length(input_string):\n",
 292          "    leng = len(input_string)\n",
 293          "    print(leng)"
 294        ],
 295        "metadata": {
 296          "id": "lnl7rZj1RN_j"
 297        },
 298        "execution_count": null,
 299        "outputs": []
 300      },
 301      {
 302        "cell_type": "code",
 303        "source": [
 304          "check_string_length(\"Python\")\n",
 305          "check_string_length(\"\")"
 306        ],
 307        "metadata": {
 308          "colab": {
 309            "base_uri": "https://localhost:8080/"
 310          },
 311          "id": "GiPO3aamRVSN",
 312          "outputId": "c495e11f-1693-4f53-8b3c-e254e27c1b07"
 313        },
 314        "execution_count": null,
 315        "outputs": [
 316          {
 317            "output_type": "stream",
 318            "name": "stdout",
 319            "text": [
 320              "6\n",
 321              "0\n"
 322            ]
 323          }
 324        ]
 325      },
 326      {
 327        "cell_type": "markdown",
 328        "source": [
 329          "### Problem 5. Calculate Total Sum\n",
 330          "\n",
 331          "* **Problem Description**: Write a function that calculates the sum of all integers from 0 up to a user-provided number $n$.\n",
 332          "* **Function Signature**: `sum_up_to_n(n) -> int`\n",
 333          "* **Input/Output Examples**:\n",
 334          "    * Input: `3` / Output: `6`\n",
 335          "    * Input: `10` / Output: `55`"
 336        ],
 337        "metadata": {
 338          "id": "MJaBnT9fkDDd"
 339        }
 340      },
 341      {
 342        "cell_type": "markdown",
 343        "source": [
 344          "---\n",
 345          "- **Range function Functionality:**\n",
 346          "    - The `range()` function is Python's highly efficient tool used primarily in `for` loops to **generate a sequence of integers**.\n",
 347          "    - It generates numbers **on demand**, saving memory compared to creating a full list of numbers.\n",
 348          "\n",
 349          "- **Usage Syntax (Three Forms):**\n",
 350          "    - **1. `range(stop)`:** Generates numbers **starting from 0** up to (but **not including**) the `stop` number.\n",
 351          "        - *Example:* `range(5)` β†’ 0, 1, 2, 3, 4\n",
 352          "    - **2. `range(start, stop)`:** Generates numbers starting from `start` up to (but **not including**) the `stop` number.\n",
 353          "        - *Example:* `range(2, 7)` β†’ 2, 3, 4, 5, 6\n",
 354          "    - **3. `range(start, stop, step)`:** Generates numbers from `start` to `stop` (exclusive), incrementing by the specified `step`.\n",
 355          "        - *Example:* `range(1, 10, 2)` β†’ 1, 3, 5, 7, 9\n",
 356          "\n",
 357          "- **Key Rule (Crucial for Engineers):**\n",
 358          "    - The **`stop` value is always exclusive**. If you need to include `N` in your sequence (e.g., $1$ to $N$), you must set the stop value to **`N + 1`** (e.g., `range(1, N + 1)`).\n",
 359          "\n",
 360          "---"
 361        ],
 362        "metadata": {
 363          "id": "qnWJBcZTUyEr"
 364        }
 365      },
 366      {
 367        "cell_type": "code",
 368        "source": [
 369          "def sum_up_to_n(n):\n",
 370          "    sum = 0\n",
 371          "    for i in range(1,n+1):\n",
 372          "        sum += i\n",
 373          "    print(sum)"
 374        ],
 375        "metadata": {
 376          "id": "V-lI5AowTd1M"
 377        },
 378        "execution_count": null,
 379        "outputs": []
 380      },
 381      {
 382        "cell_type": "code",
 383        "source": [
 384          "sum_up_to_n(3)\n",
 385          "sum_up_to_n(10)"
 386        ],
 387        "metadata": {
 388          "colab": {
 389            "base_uri": "https://localhost:8080/"
 390          },
 391          "id": "aRK5o5NYTqNL",
 392          "outputId": "00d7f27c-3de1-4f98-aa8f-82c6bda6e468"
 393        },
 394        "execution_count": null,
 395        "outputs": [
 396          {
 397            "output_type": "stream",
 398            "name": "stdout",
 399            "text": [
 400              "6\n",
 401              "55\n"
 402            ]
 403          }
 404        ]
 405      },
 406      {
 407        "cell_type": "markdown",
 408        "source": [
 409          "### Problem 6. Calculate Even Sum\n",
 410          "\n",
 411          "* **Problem Description**: Write a function that calculates the sum of even numbers from 1 up to a user-provided number $n$. If the user enters 0, the program should terminate.\n",
 412          "* **Function Signature**: `sum_even_numbers(n: int) -> str`\n",
 413          "* **Input/Output Examples**:\n",
 414          "    * Input: `9` / Output: `\"1λΆ€ν„° 9κΉŒμ§€μ˜ 짝수 합은 20μž…λ‹ˆλ‹€.\"`\n",
 415          "    * Input: `0` / Output: `\"μ’…λ£Œ\"`"
 416        ],
 417        "metadata": {
 418          "id": "6Vx4TRYBkDA3"
 419        }
 420      },
 421      {
 422        "cell_type": "code",
 423        "source": [
 424          "def sum_even_numbers(n):\n",
 425          "    # Check for the exit condition (Input Validation).\n",
 426          "    if n == 0:\n",
 427          "        print(\"μ’…λ£Œ\")\n",
 428          "        return  # Exit the function if n is 0 (Implicitly returns None).\n",
 429          "\n",
 430          "    sum = 0\n",
 431          "    # Loop from 1 up to 'n' (inclusive).\n",
 432          "    for i in range(1, n + 1):\n",
 433          "        # Check if the current number 'i' is even (remainder is 0).\n",
 434          "        if i % 2 == 0:\n",
 435          "            # Add the even number to the total sum.\n",
 436          "            sum += i\n",
 437          "\n",
 438          "    # Print the final result using an f-string.\n",
 439          "    print(f\"1λΆ€ν„° {n}κΉŒμ§€μ˜ 짝수 합은 {sum} μž…λ‹ˆλ‹€\")\n",
 440          "    # Implicitly returns None."
 441        ],
 442        "metadata": {
 443          "id": "z2C0Pqc9VT88"
 444        },
 445        "execution_count": null,
 446        "outputs": []
 447      },
 448      {
 449        "cell_type": "code",
 450        "source": [
 451          "sum_even_numbers(9)\n",
 452          "sum_even_numbers(0)"
 453        ],
 454        "metadata": {
 455          "colab": {
 456            "base_uri": "https://localhost:8080/"
 457          },
 458          "id": "JzhUvoGyWJMt",
 459          "outputId": "8d18f036-bdb5-4f3c-d3ba-167659b66ee4"
 460        },
 461        "execution_count": null,
 462        "outputs": [
 463          {
 464            "output_type": "stream",
 465            "name": "stdout",
 466            "text": [
 467              "1λΆ€ν„° 9κΉŒμ§€μ˜ 짝수 합은 20 μž…λ‹ˆλ‹€\n",
 468              "μ’…λ£Œ\n"
 469            ]
 470          }
 471        ]
 472      },
 473      {
 474        "cell_type": "markdown",
 475        "source": [
 476          "### Problem 7. Divide Two Numbers\n",
 477          "\n",
 478          "* **Problem Description**: Write a program that divides two numbers entered by the user. If an exception occurs, the function should return \"Invalid input.\" . Use the `try-except` statement.\n",
 479          "* **Function Signature**: `divide_numbers(a, b) -> int or float or str`\n",
 480          "* **Input/Output Examples**:\n",
 481          "    * Input: `42, 7` / Output: `6`\n",
 482          "    * Input: `135, 0` / Output: `\"Invalid input.\"`\n",
 483          "\n",
 484          "---"
 485        ],
 486        "metadata": {
 487          "id": "9HUTAa60kC-h"
 488        }
 489      },
 490      {
 491        "cell_type": "code",
 492        "source": [
 493          "def divide_numbers(a, b):\n",
 494          "    if not (isinstance(a, (int, float))):\n",
 495          "        print(\"Invalid input.\")\n",
 496          "        return\n",
 497          "\n",
 498          "\n",
 499          "    if not (isinstance(b, (int, float))):\n",
 500          "        print(\"Invalid input.\")\n",
 501          "        return\n",
 502          "\n",
 503          "    if b==0:\n",
 504          "        print(\"Invalid input.\")\n",
 505          "        return\n",
 506          "\n",
 507          "    divided_number = a/b\n",
 508          "    print(a/b)"
 509        ],
 510        "metadata": {
 511          "id": "N6dPP2UAW0ni"
 512        },
 513        "execution_count": null,
 514        "outputs": []
 515      },
 516      {
 517        "cell_type": "code",
 518        "source": [
 519          "divide_numbers(42, 7)\n",
 520          "divide_numbers(135, 0)"
 521        ],
 522        "metadata": {
 523          "colab": {
 524            "base_uri": "https://localhost:8080/"
 525          },
 526          "id": "65lBP2OPXh0n",
 527          "outputId": "61a2d626-5f8c-4d1b-e842-61730ac4cd94"
 528        },
 529        "execution_count": null,
 530        "outputs": [
 531          {
 532            "output_type": "stream",
 533            "name": "stdout",
 534            "text": [
 535              "6.0\n",
 536              "Invalid input.\n"
 537            ]
 538          }
 539        ]
 540      },
 541      {
 542        "cell_type": "markdown",
 543        "source": [
 544          "___\n",
 545          "\n",
 546          "## Application (3 Problems)"
 547        ],
 548        "metadata": {
 549          "id": "_tzn09R9kC76"
 550        }
 551      },
 552      {
 553        "cell_type": "markdown",
 554        "source": [
 555          "### Problem 1. String Compression Game\n",
 556          "\n",
 557          "* **Problem Description**: Compress a given string by replacing consecutive repeating characters with the character and its count.\n",
 558          "* **Function Signature**: `compress_string(s: str) -> str`\n",
 559          "* **Input/Output Examples**:\n",
 560          "    * Input: `\"aaabbaaa\"` / Output: `\"a3b2a3\"`\n",
 561          "    * Input: `\"aabcccccaaa\"` / Output: `\"a2b1c5a3\"`"
 562        ],
 563        "metadata": {
 564          "id": "A_tWs-C7kC5U"
 565        }
 566      },
 567      {
 568        "cell_type": "code",
 569        "source": [
 570          "def compress_string(string):\n",
 571          "    # Set the first character as the memory for comparison.\n",
 572          "    memory = string[0]\n",
 573          "    output = \"\"\n",
 574          "    # Start the counter for the current character at 1.\n",
 575          "    count = 1\n",
 576          "    leng = len(string)\n",
 577          "\n",
 578          "    # Loop starts from the second character (index 1).\n",
 579          "    for i in range(1, leng):\n",
 580          "        # If the current character is the same as the memory:\n",
 581          "        if memory == string[i]:\n",
 582          "            count += 1 # Increment the count.\n",
 583          "\n",
 584          "        # If the current character is different (end of a run):\n",
 585          "        else:\n",
 586          "            # Append the previous character and its count to the output.\n",
 587          "            output += memory\n",
 588          "            output += str(count)\n",
 589          "\n",
 590          "            # Reset the count to 1 for the new character.\n",
 591          "            count = 1\n",
 592          "            # Update the memory to the new character.\n",
 593          "            memory = string[i]\n",
 594          "\n",
 595          "    # After the loop finishes, append the last remaining character and its count.\n",
 596          "    output += memory\n",
 597          "    output += str(count)\n",
 598          "\n",
 599          "    print(output)"
 600        ],
 601        "metadata": {
 602          "id": "r9aYE1WHajfH"
 603        },
 604        "execution_count": null,
 605        "outputs": []
 606      },
 607      {
 608        "cell_type": "code",
 609        "source": [
 610          "compress_string(\"aaabbaaa\")\n",
 611          "compress_string(\"aabcccccaaa\")"
 612        ],
 613        "metadata": {
 614          "colab": {
 615            "base_uri": "https://localhost:8080/"
 616          },
 617          "id": "ICW8VZUJehJG",
 618          "outputId": "83ed32c4-f10c-4371-8c37-969cd71e7b26"
 619        },
 620        "execution_count": null,
 621        "outputs": [
 622          {
 623            "output_type": "stream",
 624            "name": "stdout",
 625            "text": [
 626              "a3b2a3\n",
 627              "a2b1c5a3\n"
 628            ]
 629          }
 630        ]
 631      },
 632      {
 633        "cell_type": "markdown",
 634        "source": [
 635          "### Problem 2. Addition Program (Input Validation)\n",
 636          "\n",
 637          "* **Problem Description**: Takes two numbers from the user and calculates their sum. If the input is not a number, it requests a numerical input again.\n",
 638          "* **Function Signature**: `add_numbers() -> None`\n",
 639          "* **Input/Output Examples (Simulated)**:\n",
 640          "\n",
 641          "- **Input:**\n",
 642          "    - `Enter the first number: 10`\n",
 643          "    - `Enter the second number: twenty`\n",
 644          "    - `Enter the first number: 10`\n",
 645          "    - `Enter the second number: 20`\n",
 646          "\n",
 647          "- **Output:**\n",
 648          "    - `Please enter a valid number.`\n",
 649          "    - `10 + 20 = 30`\n",
 650          "\n",
 651          "---"
 652        ],
 653        "metadata": {
 654          "id": "d-pFkZOekC2c"
 655        }
 656      },
 657      {
 658        "cell_type": "markdown",
 659        "source": [
 660          "  - **🎯 Try - Except Function:**\n",
 661          "\n",
 662          "      - The `try` and `except` blocks form Python's **Exception Handling** mechanism. Their primary function is to prevent a program from **crashing (terminating abruptly)** when a runtime error occurs.\n",
 663          "      - They ensure that when an unexpected issue arises (like a user entering text instead of a number), the program can **recover gracefully** and continue running.\n",
 664          "\n",
 665          "  - **πŸ›‘οΈ Logical Flow (How It Works):**\n",
 666          "\n",
 667          "      - **`try:`** Place the **risky code** inside this block. This is the code you want to execute, but which might cause an error (e.g., trying to convert a non-numeric string to an integer: `int(\"twenty\")`).\n",
 668          "      - **`except [ErrorName]:`** This block is executed **ONLY IF** the specified error (like `ValueError` or `ZeroDivisionError`) occurs within the `try` block. It contains the code to handle the problem (e.g., printing an error message, asking for input again)."
 669        ],
 670        "metadata": {
 671          "id": "GB1QcmIFtZSq"
 672        }
 673      },
 674      {
 675        "cell_type": "code",
 676        "source": [
 677          "def add_numbers_safe():\n",
 678          "    try:\n",
 679          "        # Get and convert the first input to an integer.\n",
 680          "        a_str = input(\"Enter the first number: \")\n",
 681          "        int_a = int(a_str)\n",
 682          "\n",
 683          "        # Get and convert the second input to an integer.\n",
 684          "        b_str = input(\"Enter the second number: \")\n",
 685          "        int_b = int(b_str)\n",
 686          "\n",
 687          "    except ValueError:\n",
 688          "        # If conversion fails (non-number input), handle the error.\n",
 689          "        print(\"Error: Please enter a valid integer.\")\n",
 690          "        return # Exit gracefully to prevent crashing.\n",
 691          "\n",
 692          "    # Calculate the total sum.\n",
 693          "    total = int_a + int_b\n",
 694          "    # Print the final result.\n",
 695          "    print(f\"{a_str} + {b_str} = {total}\")"
 696        ],
 697        "metadata": {
 698          "id": "tELnWClupk1J"
 699        },
 700        "execution_count": null,
 701        "outputs": []
 702      },
 703      {
 704        "cell_type": "code",
 705        "source": [
 706          "add_numbers()"
 707        ],
 708        "metadata": {
 709          "colab": {
 710            "base_uri": "https://localhost:8080/"
 711          },
 712          "id": "7jH13cNTp0-u",
 713          "outputId": "459f7f3a-d263-48d0-904d-cbc4ed375e0d"
 714        },
 715        "execution_count": null,
 716        "outputs": [
 717          {
 718            "output_type": "stream",
 719            "name": "stdout",
 720            "text": [
 721              "Enter the first number: 10\n",
 722              "Enter the second number: 20\n",
 723              "10 + 20 = 30\n"
 724            ]
 725          }
 726        ]
 727      },
 728      {
 729        "cell_type": "markdown",
 730        "source": [
 731          "### Problem 3. Countdown Timer\n",
 732          "\n",
 733          "* **Problem Description**: Receives time (seconds) from the user, counts down, printing the remaining time every second, and prints \"Timer done!\" when finished.\n",
 734          "* **Function Signature**: `count_down(seconds: int) -> None`\n",
 735          "* **Input/Output Examples**:\n",
 736          "    * Input: `5` / Output: `\"Timer Start!\"`, `5`, `4`, `3`, `2`, `1`, `\"Timer done!\"`"
 737        ],
 738        "metadata": {
 739          "id": "-UaGuTXkkCz1"
 740        }
 741      },
 742      {
 743        "cell_type": "code",
 744        "source": [
 745          "import time\n",
 746          "\n",
 747          "def count_down(seconds: int) -> None:\n",
 748          "    # Print the timer start message.\n",
 749          "    print(\"Timer Start!\")\n",
 750          "\n",
 751          "    # Store the input seconds in the counter variable.\n",
 752          "    current_time = seconds\n",
 753          "\n",
 754          "    # Loop as long as the current time is greater than zero.\n",
 755          "    while current_time > 0:\n",
 756          "        # Print the current time remaining.\n",
 757          "        print(current_time)\n",
 758          "\n",
 759          "        # Pause the program execution for 1 second.\n",
 760          "        time.sleep(1)\n",
 761          "\n",
 762          "        # Decrement the time by 1.\n",
 763          "        current_time -= 1\n",
 764          "\n",
 765          "    # Print the termination message when the countdown is finished.\n",
 766          "    print(\"Timer done!\")"
 767        ],
 768        "metadata": {
 769          "id": "UUI4EXRKu2-w"
 770        },
 771        "execution_count": null,
 772        "outputs": []
 773      },
 774      {
 775        "cell_type": "code",
 776        "source": [
 777          "count_down(5)"
 778        ],
 779        "metadata": {
 780          "colab": {
 781            "base_uri": "https://localhost:8080/"
 782          },
 783          "id": "qaODqBrhu5X1",
 784          "outputId": "da17060a-574d-4247-9127-ad7f3450e8b8"
 785        },
 786        "execution_count": null,
 787        "outputs": [
 788          {
 789            "output_type": "stream",
 790            "name": "stdout",
 791            "text": [
 792              "Timer Start!\n",
 793              "5\n",
 794              "4\n",
 795              "3\n",
 796              "2\n",
 797              "1\n",
 798              "Timer done!\n"
 799            ]
 800          }
 801        ]
 802      },
 803      {
 804        "cell_type": "markdown",
 805        "source": [
 806          "___\n",
 807          "# 🧱 II. Objects and Classes"
 808        ],
 809        "metadata": {
 810          "id": "cZ3FkK8CkCxg"
 811        }
 812      },
 813      {
 814        "cell_type": "markdown",
 815        "source": [
 816          "## Basic (2 Problems)"
 817        ],
 818        "metadata": {
 819          "id": "J9KqVDzjkCu5"
 820        }
 821      },
 822      {
 823        "cell_type": "markdown",
 824        "source": [
 825          "### Problem 1. Time Tracker Class (TimeTracker)\n",
 826          "\n",
 827          "* **Problem Description**: Implement a `TimeTracker` class to record start time, stop time, and calculate elapsed time in **minutes**. Use the `datetime` module.\n",
 828          "* **Methods**: `start`, `stop`, `get_elapsed_time`\n",
 829          "\n"
 830        ],
 831        "metadata": {
 832          "id": "aE11AQpfkCsj"
 833        }
 834      },
 835      {
 836        "cell_type": "code",
 837        "source": [
 838          "from datetime import datetime\n",
 839          "from typing import Optional\n",
 840          "\n",
 841          "class TimeTracker:\n",
 842          "    def __init__(self):\n",
 843          "        # Initialize start and stop time variables to None.\n",
 844          "        self.start_time: Optional[datetime] = None\n",
 845          "        self.stop_time: Optional[datetime] = None\n",
 846          "\n",
 847          "    def start(self) -> None:\n",
 848          "        \"\"\"Records the current time to start the timer.\"\"\"\n",
 849          "        # Record the current system time using datetime.now().\n",
 850          "        self.start_time = datetime.now()\n",
 851          "        # Reset stop_time in case the timer is being restarted.\n",
 852          "        self.stop_time = None\n",
 853          "        print(f\"Timer started at: {self.start_time.strftime('%Y-%m-%d %H:%M:%S')}\")\n",
 854          "\n",
 855          "    def stop(self) -> None:\n",
 856          "        \"\"\"Records the current time to stop the timer.\"\"\"\n",
 857          "        # Check if the timer was started before stopping.\n",
 858          "        if self.start_time is None:\n",
 859          "            print(\"Error: Timer has not been started yet.\")\n",
 860          "            return\n",
 861          "\n",
 862          "        # Record the current time as the stop time.\n",
 863          "        self.stop_time = datetime.now()\n",
 864          "        print(f\"Timer stopped at: {self.stop_time.strftime('%Y-%m-%d %H:%M:%S')}\")\n",
 865          "\n",
 866          "    def get_elapsed_time(self) -> Optional[float]:\n",
 867          "        \"\"\"Calculates the elapsed time between start and stop in minutes.\"\"\"\n",
 868          "        # Check for error if the timer was never started.\n",
 869          "        if self.start_time is None:\n",
 870          "            print(\"Error: Timer has not been started.\")\n",
 871          "            return None\n",
 872          "\n",
 873          "        # If the timer is still running, calculate time up to the present moment.\n",
 874          "        if self.stop_time is None:\n",
 875          "            time_difference = datetime.now() - self.start_time\n",
 876          "        # Otherwise, calculate time between recorded start and stop times.\n",
 877          "        else:\n",
 878          "            time_difference = self.stop_time - self.start_time\n",
 879          "\n",
 880          "        # Convert the timedelta object to total seconds, then divide by 60 for minutes.\n",
 881          "        elapsed_minutes = time_difference.total_seconds() / 60\n",
 882          "\n",
 883          "        # Return the elapsed time, rounded to two decimal places.\n",
 884          "        return round(elapsed_minutes, 2)"
 885        ],
 886        "metadata": {
 887          "id": "o3KTL0igZmIg"
 888        },
 889        "execution_count": null,
 890        "outputs": []
 891      },
 892      {
 893        "cell_type": "markdown",
 894        "source": [
 895          "### Problem 2. Contact Book Class\n",
 896          "\n",
 897          "* **Problem Description**: Implement a `Contact` class to store name, phone number, and email address. Implement `__str__` to return a nicely formatted string of the information.\n",
 898          "* **Methods**: `__init__`, `__str__`"
 899        ],
 900        "metadata": {
 901          "id": "m8dJoQ9ZkCp9"
 902        }
 903      },
 904      {
 905        "cell_type": "code",
 906        "source": [
 907          "class Contact:\n",
 908          "    # Constructor method: Initializes a new Contact object\n",
 909          "    def __init__ (self, name, phone, email):\n",
 910          "        self.name = name    # Assign input name to the object's attribute (order is important, not name = self.name)\n",
 911          "        self.phone = phone  # Assign input phone to the object's attribute\n",
 912          "        self.email = email  # Assign input email to the object's attribute\n",
 913          "\n",
 914          "    # String representation method (Standard Python Magic Method)\n",
 915          "    # Called by print() or str() for user-friendly output.\n",
 916          "    def __str__(self):\n",
 917          "        # Logic: Must RETURN a string representation of the object's state.\n",
 918          "        # This string is then printed externally when print(object) is called.\n",
 919          "        return f\"name : {self.name} \\n phone : {self.phone} \\n email : {self.email}\"\n",
 920          "        # order is same with printf()"
 921        ],
 922        "metadata": {
 923          "id": "E5hD3WTAhX6K"
 924        },
 925        "execution_count": null,
 926        "outputs": []
 927      },
 928      {
 929        "cell_type": "code",
 930        "source": [
 931          "# Usage Example\n",
 932          "friend = Contact(\"Jane Doe\", \"010-1234-5678\", \"jane@example.com\")\n",
 933          "print(friend)"
 934        ],
 935        "metadata": {
 936          "colab": {
 937            "base_uri": "https://localhost:8080/"
 938          },
 939          "id": "vU3kpns_iEWj",
 940          "outputId": "df1dbc0e-52db-45e7-ad5c-ea929b100c7e"
 941        },
 942        "execution_count": null,
 943        "outputs": [
 944          {
 945            "output_type": "stream",
 946            "name": "stdout",
 947            "text": [
 948              "name : Jane Doe \n",
 949              " phone : 010-1234-5678 \n",
 950              " email : jane@example.com\n"
 951            ]
 952          }
 953        ]
 954      },
 955      {
 956        "cell_type": "markdown",
 957        "source": [
 958          "## Application (4 Problems)"
 959        ],
 960        "metadata": {
 961          "id": "bmCkHXZAmHEV"
 962        }
 963      },
 964      {
 965        "cell_type": "markdown",
 966        "source": [
 967          "#### Problem 1. Voting System Class\n",
 968          "\n",
 969          "* **Problem Description**: Implement a `VoteSystem` class to add candidates, record votes, and display results. Use a dictionary for management. Candidates cannot be duplicated or voted for if unregistered.\n",
 970          "* **Methods**: `add_candidate`, `vote`, `get_results`\n",
 971          "\n",
 972          "  - **Exercise Description**\n",
 973          "\n",
 974          "    Start a project to implement a `VoteSystem` class for a simple voting system. This system manages a list of candidates and provides functionality to tally votes for each candidate.\n",
 975          "\n",
 976          "    The `VoteSystem` class must provide the following features:\n",
 977          "\n",
 978          "      - Candidate Registration\n",
 979          "      - Voting Functionality\n",
 980          "      - View Voting Results\n",
 981          "\n",
 982          "  - **Methods to Implement**\n",
 983          "\n",
 984          "      - `add_candidate`: Registers a candidate. Takes a candidate's name as input and adds them to the list.\n",
 985          "      - `vote`: Votes for a specific candidate. Takes the name of the candidate you wish to vote for as input.\n",
 986          "      - `get_results`: Prints the vote count for each candidate.\n",
 987          "\n",
 988          "  - **Example Execution Results**\n",
 989          "\n",
 990          "      - Example of the output when running the following code:\n",
 991          "\n",
 992          "        ```python\n",
 993          "        voting_system = VoteSystem()\n",
 994          "        voting_system.add_candidate(\"Alice\")\n",
 995          "        voting_system.add_candidate(\"Bob\")\n",
 996          "        voting_system.add_candidate(\"Charlie\")\n",
 997          "\n",
 998          "        voting_system.vote(\"Alice\")\n",
 999          "        voting_system.vote(\"Alice\")\n",
1000          "        voting_system.vote(\"Bob\")\n",
1001          "\n",
1002          "        voting_system.get_results()\n",
1003          "        ```\n",
1004          "\n",
1005          "      - **Expected Output:**\n",
1006          "\n",
1007          "        ```\n",
1008          "        Candidate Alice successfully registered.\n",
1009          "        Candidate Bob successfully registered.\n",
1010          "        Candidate Charlie successfully registered.\n",
1011          "        Voted for Alice.\n",
1012          "        Voted for Alice.\n",
1013          "        Voted for Bob.\n",
1014          "        Voting Results:\n",
1015          "        Alice: 2 votes\n",
1016          "        Bob: 1 vote\n",
1017          "        Charlie: 0 votes\n",
1018          "        ```\n",
1019          "\n",
1020          "  - **Requirements**\n",
1021          "\n",
1022          "      - Duplicate candidate registration is not allowed.\n",
1023          "      - You cannot vote for a candidate who is not registered.\n",
1024          "      - Manage each candidate's name and vote count using a **dictionary**.\n",
1025          "\n",
1026          "-----\n",
1027          "\n",
1028          "Would you like me to provide a template code or a hint for using the dictionary to get you started?"
1029        ],
1030        "metadata": {
1031          "id": "vGdNA05epFJU"
1032        }
1033      },
1034      {
1035        "cell_type": "markdown",
1036        "source": [
1037          "**Basic Structure of a Dictionary {}**\n",
1038          "\n",
1039          "  * **Key:** A unique label used to retrieve data (e.g., Candidate Name).\n",
1040          "  * **Value:** The actual data associated with that label (e.g., Vote Count).\n",
1041          "\n",
1042          "However, the **Value** slot is not limited to a single number. If necessary, you can store larger data structures, such as a **List** or **another Dictionary**, in their entirety.\n",
1043          "\n",
1044          "-----\n",
1045          "\n",
1046          "**1. Current Exercise Approach (Simplest)**\n",
1047          "A single number (Value) maps to a single name (Key). This is the most suitable form for this assignment.\n",
1048          "\n",
1049          "```python\n",
1050          "# { \"Name\" : Vote Count }\n",
1051          "candidate = {\n",
1052          "    \"Alice\": 0,\n",
1053          "    \"Bob\": 1\n",
1054          "}\n",
1055          "```\n",
1056          "\n",
1057          "**2. When More Information is Needed (Using Lists)**\n",
1058          "A list containing `[Vote Count, Party]` is stored as the Value for a Key.\n",
1059          "\n",
1060          "```python\n",
1061          "# { \"Name\" : [Vote Count, Party] }\n",
1062          "candidate = {\n",
1063          "    \"Alice\": [0, \"Democrat\"],\n",
1064          "    \"Bob\": [1, \"Republican\"]\n",
1065          "}\n",
1066          "```\n",
1067          "\n",
1068          "**3. When More Information is Needed (Nested Dictionary)**\n",
1069          "Another dictionary containing detailed information is stored as the Value for a Key.\n",
1070          "\n",
1071          "```python\n",
1072          "# { \"Name\" : {Details} }\n",
1073          "candidate = {\n",
1074          "    \"Alice\": {\"votes\": 0, \"party\": \"Democrat\"},\n",
1075          "    \"Bob\": {\"votes\": 1, \"party\": \"Republican\"}\n",
1076          "}\n",
1077          "```\n",
1078          "\n",
1079          "**Summary**\n",
1080          "While the syntax of a dictionary always follows a 1:1 correspondence (Key:Value), **what you place in the Value slot** determines its capabilityβ€”ranging from holding simple numbers to storing complex information."
1081        ],
1082        "metadata": {
1083          "id": "qtwrfjEoxjK6"
1084        }
1085      },
1086      {
1087        "cell_type": "code",
1088        "source": [
1089          "class VoteSystem:\n",
1090          "    def __init__(self):\n",
1091          "        # Initialize an empty dictionary to store 'name: votes'\n",
1092          "        self.candidate = {}\n",
1093          "\n",
1094          "    def add_candidate(self, name):\n",
1095          "        # Add the 'name' as a key and set its value (votes) to 0\n",
1096          "        self.candidate[name] = 0\n",
1097          "\n",
1098          "    def vote(self, name):\n",
1099          "        # Increment the vote count for the specific key\n",
1100          "        self.candidate[name] += 1\n",
1101          "        # Note: self.candidate[name] accesses the integer value (votes)\n",
1102          "\n",
1103          "    def get_results(self):\n",
1104          "        # .items() is required to loop through both keys (names) and values (votes) together # self.[ν•¨μˆ˜λͺ…].items()λ₯Ό λΆ™μ—¬μ•Ό 그에 κ΄€ν•œ λ†ˆλ“€μ΄ 닀같이 λ‚˜μ˜¨λ‹€.\n",
1105          "        for ppl, value in self.candidate.items():\n",
1106          "            print(f\"{ppl} {value}\")"
1107        ],
1108        "metadata": {
1109          "id": "4m4zYKfwpDPc"
1110        },
1111        "execution_count": 47,
1112        "outputs": []
1113      },
1114      {
1115        "cell_type": "code",
1116        "source": [
1117          "# Usage Example\n",
1118          "voting_system = VoteSystem()\n",
1119          "voting_system.add_candidate(\"Alice\")\n",
1120          "voting_system.add_candidate(\"Bob\")\n",
1121          "voting_system.add_candidate(\"Charlie\")\n",
1122          "\n",
1123          "voting_system.vote(\"Alice\")\n",
1124          "voting_system.vote(\"Alice\")\n",
1125          "voting_system.vote(\"Bob\")\n",
1126          "\n",
1127          "voting_system.get_results()"
1128        ],
1129        "metadata": {
1130          "colab": {
1131            "base_uri": "https://localhost:8080/"
1132          },
1133          "id": "4Nd_54Rfq7Yl",
1134          "outputId": "cfb73844-db95-4ebf-8a57-4f51fd0e0ad8"
1135        },
1136        "execution_count": 48,
1137        "outputs": [
1138          {
1139            "output_type": "stream",
1140            "name": "stdout",
1141            "text": [
1142              "Alice 2\n",
1143              "Bob 1\n",
1144              "Charlie 0\n"
1145            ]
1146          }
1147        ]
1148      },
1149      {
1150        "cell_type": "markdown",
1151        "source": [
1152          "#### Problem 2. Bank Account Class\n",
1153          "\n",
1154          "  - **Exercise Description**\n",
1155          "\n",
1156          "    Start a project to implement a `BankAccount` class for a simple bank account management system. This class manages an individual's account information and provides basic banking transaction functionalities.\n",
1157          "\n",
1158          "    The `BankAccount` class must manage the following information:\n",
1159          "\n",
1160          "      - Account Number\n",
1161          "      - Account Holder Name\n",
1162          "      - Current Balance\n",
1163          "\n",
1164          "  - **Methods to Implement**\n",
1165          "\n",
1166          "      - `__init__`: Initializes the account number, account holder name, and initial balance when the object is created.\n",
1167          "      - `deposit`: Deposits money into the account. Takes the deposit amount as an argument and updates the balance.\n",
1168          "      - `withdraw`: Withdraws money from the account. Takes the withdrawal amount as an argument. Allows withdrawal and updates the balance **only if there are sufficient funds**.\n",
1169          "      - `get_balance`: Returns the current account balance.\n",
1170          "\n",
1171          "  - **Example Execution Results**\n",
1172          "\n",
1173          "      - Example of the output when running the following code:\n",
1174          "\n",
1175          "        ```python\n",
1176          "        my_account = BankAccount(\"123-456-789\", \"Cheolsu Kim\", 100000)\n",
1177          "        my_account.deposit(50000)\n",
1178          "        my_account.withdraw(20000)\n",
1179          "        print(f\"Current Balance: {my_account.get_balance()} won\")\n",
1180          "        ```\n",
1181          "\n",
1182          "      - **Expected Output:**\n",
1183          "\n",
1184          "        ```\n",
1185          "        Account 123-456-789 for Cheolsu Kim has been opened. Initial balance: 100000 won.\n",
1186          "        50000 won deposited. Current balance: 150000 won.\n",
1187          "        20000 won withdrawn. Current balance: 130000 won.\n",
1188          "        Current Balance: 130000 won\n",
1189          "        ```\n",
1190          "\n",
1191          "  - **Requirements**\n",
1192          "\n",
1193          "      - If a withdrawal attempt exceeds the current balance, the withdrawal must be denied, and a warning message should be printed.\n",
1194          "      - All amounts must be capable of being processed as integers or floats.\n",
1195          "      - You must implement all features: account creation, deposit, withdrawal, and balance inquiry.\n",
1196          "\n",
1197          "-----\n",
1198          "\n",
1199          "Would you like a template code to help you structure the `__init__` method?"
1200        ],
1201        "metadata": {
1202          "id": "KKMZc_UcmHBe"
1203        }
1204      },
1205      {
1206        "cell_type": "code",
1207        "source": [
1208          "class BankAccount:\n",
1209          "    def __init__(self, acc_num, name, money):\n",
1210          "        # Initialize self.account as a dictionary containing all account details\n",
1211          "        # Key: Account Holder Name, Value: [Account Number, Balance]\n",
1212          "        self.account = {\n",
1213          "            name: [acc_num, money]\n",
1214          "        }\n",
1215          "        self.name = name  # Storing the name separately for easy dictionary access (Key)\n",
1216          "        print(f\"Account created for {self.name}. Initial balance: {money}\")\n",
1217          "\n",
1218          "    def deposit(self, dep):\n",
1219          "        account_list = self.account[self.name]\n",
1220          "        # Index 1 of the list holds the balance\n",
1221          "        account_list[1] += dep\n",
1222          "        print(f\"Deposit successful. Current balance for {self.name}: {account_list[1]}\")\n",
1223          "\n",
1224          "    def withdraw(self, wit):\n",
1225          "        account_list = self.account[self.name]\n",
1226          "        # Note: This code currently lacks the balance check ('if self.balance >= amount').\n",
1227          "        account_list[1] -= wit\n",
1228          "        print(f\"Withdrawal successful. Current balance for {self.name}: {account_list[1]}\")\n",
1229          "\n",
1230          "    def get_balance(self):\n",
1231          "        # This method currently prints the entire dictionary structure\n",
1232          "        print(f\"Current account data is: {self.account}\")\n",
1233          "\n",
1234          "        # To strictly fulfill the original requirement (return balance), you would use:\n",
1235          "        # return self.account[self.name][1]"
1236        ],
1237        "metadata": {
1238          "id": "onhqMf_uB1sX"
1239        },
1240        "execution_count": 86,
1241        "outputs": []
1242      },
1243      {
1244        "cell_type": "code",
1245        "source": [
1246          "# Using Example\n",
1247          "my_account = BankAccount(\"123-456-789\", \"κΉ€μ² μˆ˜\", 100000)\n",
1248          "my_account.deposit(50000)\n",
1249          "my_account.withdraw(180000)"
1250        ],
1251        "metadata": {
1252          "colab": {
1253            "base_uri": "https://localhost:8080/"
1254          },
1255          "id": "O7OTX4cPDLeA",
1256          "outputId": "1d42dc3b-7d08-4156-fdee-bd4ccf4dd6d8"
1257        },
1258        "execution_count": 87,
1259        "outputs": [
1260          {
1261            "output_type": "stream",
1262            "name": "stdout",
1263            "text": [
1264              "Account created for κΉ€μ² μˆ˜. Initial balance: 100000\n",
1265              "Deposit successful. Current balance for κΉ€μ² μˆ˜: 150000\n",
1266              "Withdrawal successful. Current balance for κΉ€μ² μˆ˜: -30000\n"
1267            ]
1268          }
1269        ]
1270      },
1271      {
1272        "cell_type": "markdown",
1273        "source": [
1274          "#### Problem 3. Employee Management Class\n",
1275          "\n",
1276          "* **Problem Description**: Implement an `EmployeeManager` class using a **class variable** (`all_employees`) to store all employee data and a **class method** (`calculate_average_salary`) to calculate the average salary.\n",
1277          "* **Methods**: `__init__`, `calculate_average_salary` (Class Method)\n",
1278          "\n"
1279        ],
1280        "metadata": {
1281          "id": "EhTnvs5ZmG-m"
1282        }
1283      },
1284      {
1285        "cell_type": "code",
1286        "source": [
1287          "class EmployeeManager:\n",
1288          "    # Class variable to store all employee records (name as key)\n",
1289          "    employee_records = {} # λ”•μ…”λ„ˆλ¦¬λ₯Ό μ „μ²΄λ‘œ λΆˆλŸ¬μ•Ό μ–Έμ œλ“ μ§€ 쓰일 수 μžˆλŠ” 것듀이 됨.\n",
1290          "\n",
1291          "    # Constructor: Initializes a new employee and adds them to the class record\n",
1292          "    def __init__(self, name, balance):\n",
1293          "        new_employee_details = {\n",
1294          "            \"name\": name,\n",
1295          "            \"balance\": balance\n",
1296          "        }\n",
1297          "        # Prints employee's name and salary in English\n",
1298          "        print(f\"The salary of {name} is {balance}\")\n",
1299          "        # Adds the new employee's details to the class-level dictionary\n",
1300          "        EmployeeManager.employee_records[name] = new_employee_details # μ΄λŸ°μ‹μœΌλ‘œ μΆ”κ°€ν•΄μ•Ό, λ”•μ…”λ„ˆλ¦¬μ— 좔가됨. (이게 μ—†μœΌλ©΄, κ·Έλƒ₯ λ¦¬μŠ€νŠΈλŠ” λˆ„μ μ΄ μ•„λ‹Œ 항상 μ΄ˆκΈ°ν™”λ¨.)\n",
1301          "\n",
1302          "    # Static method: Calculates the average salary of all recorded employees\n",
1303          "    def calculate_average_salary():\n",
1304          "        sum_sal = 0  # Initialize total salary sum\n",
1305          "        num = 0      # Initialize employee count\n",
1306          "\n",
1307          "        # Iterate through all employee records stored in the class variable\n",
1308          "        for name, details in EmployeeManager.employee_records.items():\n",
1309          "            sum_sal += details[\"balance\"]\n",
1310          "            num += 1\n",
1311          "\n",
1312          "        # Check to prevent division by zero\n",
1313          "        if num == 0:\n",
1314          "            return 0\n",
1315          "\n",
1316          "        average = sum_sal / num  # Calculate the average salary\n",
1317          "\n",
1318          "        return average"
1319        ],
1320        "metadata": {
1321          "id": "e9fc83LVK2ey"
1322        },
1323        "execution_count": 139,
1324        "outputs": []
1325      },
1326      {
1327        "cell_type": "code",
1328        "source": [
1329          "# Usage Example\n",
1330          "emp1 = EmployeeManager(\"Alison\", 50000)\n",
1331          "emp2 = EmployeeManager(\"Moon\", 60000)\n",
1332          "\n",
1333          "EmployeeManager.calculate_average_salary()"
1334        ],
1335        "metadata": {
1336          "colab": {
1337            "base_uri": "https://localhost:8080/"
1338          },
1339          "id": "YW38jDLNLyYP",
1340          "outputId": "9df66817-b011-45f5-e3c4-6f3b6cd584cb"
1341        },
1342        "execution_count": 142,
1343        "outputs": [
1344          {
1345            "output_type": "stream",
1346            "name": "stdout",
1347            "text": [
1348              "The salary of Alison is 50000\n",
1349              "The salary of Moon is 60000\n"
1350            ]
1351          },
1352          {
1353            "output_type": "execute_result",
1354            "data": {
1355              "text/plain": [
1356                "55000.0"
1357              ]
1358            },
1359            "metadata": {},
1360            "execution_count": 142
1361          }
1362        ]
1363      },
1364      {
1365        "cell_type": "markdown",
1366        "source": [
1367          "#### Problem 4. Franchise Restaurant Reservation Class\n",
1368          "\n",
1369          "* **Problem Description**: Implement a `ReservationSystem` class to manage branch reservations. Use a **class method** (`sum_reservations`) to sum the total reservations across multiple instances.\n",
1370          "* **Methods**: `__init__`, `add_reservation`, `list_reservations`, `sum_reservations` (Class Method)\n",
1371          "\n",
1372          "-----\n",
1373          "\n",
1374          "## 🍽️ Restaurant Reservation System Development Exercise\n",
1375          "\n",
1376          "### **Exercise Description**\n",
1377          "\n",
1378          "You are working on the IT team for a multi-branch restaurant chain. Your mission is to develop a system that manages reservations for each branch and allows for centralized monitoring of the reservation status. This system must be capable of managing the reservation status of individual branches and effectively processing customer reservation requests.\n",
1379          "\n",
1380          "The `ReservationSystem` class must manage reservations for each restaurant branch and provide the following functionalities:\n",
1381          "\n",
1382          "  * **Add Reservation**: Adds a customer's reservation request to the system, specifying the branch, time/date, and number of guests.\n",
1383          "  * **Cancel Reservation**: Allows a customer to cancel a reservation, removing the booking from the system.\n",
1384          "  * **List Reservations**: Displays the current reservation status for a specific branch.\n",
1385          "  * **Aggregate Reservations (Summation)**: Calculates the total number of reservations across all branches. This method should sum up the reservations from all `ReservationSystem` instances.\n",
1386          "\n",
1387          "-----\n",
1388          "\n",
1389          "### **Methods to Implement**\n",
1390          "\n",
1391          "  * `__init__`: Initializes the name of the restaurant branch and manages the list of reservations.\n",
1392          "  * `add_reservation`: Adds a new reservation. This method should accept and store the customer's **name**, **reservation date/time**, and **number of guests**.\n",
1393          "  * `list_reservations`: Prints the current status of all reservations for the current branch.\n",
1394          "  * `sum_reservations`: **(Class Method)** Aggregates the total number of reservations from a given list of `ReservationSystem` instances.\n",
1395          "\n",
1396          "-----\n",
1397          "\n",
1398          "### **Example Execution and Expected Output**\n",
1399          "\n",
1400          "The following code execution demonstrates the required functionality:\n",
1401          "\n",
1402          "```python\n",
1403          "restaurant1 = ReservationSystem(\"Gangnam Branch\")\n",
1404          "restaurant2 = ReservationSystem(\"Hongdae Branch\")\n",
1405          "\n",
1406          "restaurant1.add_reservation(\"Gildong Hong\", \"2024-05-20\", 4)\n",
1407          "restaurant2.add_reservation(\"Cheolsu Kim\", \"2024-05-21\", 2)\n",
1408          "\n",
1409          "restaurant1.list_reservations()\n",
1410          "restaurant2.list_reservations()\n",
1411          "\n",
1412          "total_reservations = ReservationSystem.sum_reservations([restaurant1, restaurant2])\n",
1413          "print(f\"Total restaurant reservations: {total_reservations}\")\n",
1414          "```\n",
1415          "\n",
1416          "**Expected Output:** ->λ”°λ‘œ 관리가 될 수 μžˆλ„λ‘ 클래슀 λ³€μˆ˜μ“°λ©΄ μ•ˆλΌ!\n",
1417          "\n",
1418          "```\n",
1419          "Gangnam Branch Reservation List:\n",
1420          "- Gildong Hong, 2024-05-20, 4 guests\n",
1421          "Hongdae Branch Reservation List:\n",
1422          "- Cheolsu Kim, 2024-05-21, 2 guests\n",
1423          "Total restaurant reservations: 2\n",
1424          "```\n",
1425          "\n",
1426          "-----"
1427        ],
1428        "metadata": {
1429          "id": "lKsRoT3RmG7v"
1430        }
1431      },
1432      {
1433        "cell_type": "code",
1434        "source": [
1435          "class ReservationSystem:\n",
1436          "    # If ReservationSystem objects are created, both objects would share the same reservation list, making per-branch management impossible.\n",
1437          "    def __init__(self, name):\n",
1438          "        # We cannot use ReservationSystem.restaurant here, as there is no input value to initialize with (it would always be an empty dictionary).\n",
1439          "        self.branch_name = name # By using 'self', this variable becomes accessible by other instances.\n",
1440          "        self.reservations = {}\n",
1441          "        # pass is removed for efficiency.\n",
1442          "\n",
1443          "    def add_reservation(self, name, date, ppl):\n",
1444          "        details = {\n",
1445          "            \"date\": date,\n",
1446          "            \"ppl\": ppl\n",
1447          "        }\n",
1448          "        self.reservations[name] = details # Add reservation using customer name as key.\n",
1449          "\n",
1450          "    def list_reservations(self):\n",
1451          "        # NOTE: Print format is still incorrect and will cause issues.\n",
1452          "        for name, details in self.reservations.items():\n",
1453          "            print(f\"{self.branch_name} Reservation List: \\n {name}, Date : {details['date']}, Guests : {details['ppl']})\")\n",
1454          "\n",
1455          "    @staticmethod # No 'self' needed; saves unnecessary resource usage.\n",
1456          "    def sum_reservations(restaurant_list): # Changed parameter name to 'restaurant_list' for clarity.\n",
1457          "        total_count = 0\n",
1458          "        for rest in restaurant_list:\n",
1459          "            total_count += len(rest.reservations) # Accesses the instance variable set in __init__.\n",
1460          "        return total_count"
1461        ],
1462        "metadata": {
1463          "id": "arIv-fDCQczS"
1464        },
1465        "execution_count": 96,
1466        "outputs": []
1467      },
1468      {
1469        "cell_type": "code",
1470        "source": [
1471          "# Usage Example\n",
1472          "restaurant1 = ReservationSystem(\"GangNam\")\n",
1473          "restaurant2 = ReservationSystem(\"HongDae\")\n",
1474          "\n",
1475          "print(restaurant1)\n",
1476          "print(restaurant2)\n",
1477          "\n",
1478          "restaurant1.add_reservation(\"Moon\", \"2024-05-20\", 4)\n",
1479          "restaurant2.add_reservation(\"Star\", \"2024-05-21\", 2)\n",
1480          "\n",
1481          "restaurant1.list_reservations()\n",
1482          "restaurant2.list_reservations()\n",
1483          "\n",
1484          "total_reservations = ReservationSystem.sum_reservations([restaurant1, restaurant2])\n",
1485          "print(f\"Total Reservations: {total_reservations}\")"
1486        ],
1487        "metadata": {
1488          "colab": {
1489            "base_uri": "https://localhost:8080/"
1490          },
1491          "id": "YAmD1CKMQixJ",
1492          "outputId": "f1483ee1-0505-46e9-cb38-4bf6eaaeec44"
1493        },
1494        "execution_count": 99,
1495        "outputs": [
1496          {
1497            "output_type": "stream",
1498            "name": "stdout",
1499            "text": [
1500              "<__main__.ReservationSystem object at 0x7d030d603e00>\n",
1501              "<__main__.ReservationSystem object at 0x7d030d602f90>\n",
1502              "GangNam Reservation List: \n",
1503              " Moon, Date : 2024-05-20, Guests : 4)\n",
1504              "HongDae Reservation List: \n",
1505              " Star, Date : 2024-05-21, Guests : 2)\n",
1506              "Total Reservations: 2\n"
1507            ]
1508          }
1509        ]
1510      },
1511      {
1512        "cell_type": "markdown",
1513        "source": [
1514          "---\n",
1515          "\n",
1516          "# 🧠 III. Advanced Challenges"
1517        ],
1518        "metadata": {
1519          "id": "LSLDdFH3mG4n"
1520        }
1521      },
1522      {
1523        "cell_type": "markdown",
1524        "source": [
1525          "## Advanced (3 Problems)"
1526        ],
1527        "metadata": {
1528          "id": "BV1XGnNQpTOG"
1529        }
1530      },
1531      {
1532        "cell_type": "markdown",
1533        "source": [
1534          "#### Problem 1. Time Management Program\n",
1535          "\n",
1536          "* **Problem Description**: Load tasks and durations from a CSV. Prompt the user for remaining time. Select the maximum number of tasks that fit within that time and print them, sorted by shortest duration.\n",
1537          "\n",
1538          "-----\n",
1539          "\n",
1540          "**Practice Exercise**\n",
1541          "\n",
1542          "This program assists the user in completing the **maximum number of tasks** within a limited time frame. A list of tasks and their corresponding time requirements are stored in a CSV file. The user inputs this data and their available time. The program selects the maximum number of feasible tasks that fit within the user's available time. The selected tasks are then **sorted by the shortest required time** and printed, allowing the user to manage their schedule efficiently.\n",
1543          "\n",
1544          "-----\n",
1545          "\n",
1546          "**Functional Requirements**\n",
1547          "\n",
1548          "  * **Data Reading:** The program prompts the user for the CSV file path and reads the file. The file includes each task and its time requirement.\n",
1549          "  * **Task Selection:** The program receives the user's available time. Based on this time limit, it selects the maximum possible number of tasks that can be completed.\n",
1550          "  * **Output Results:** The selected tasks are printed, sorted by the shortest required time. The output format is a list showing the task name and its estimated time requirement.\n",
1551          "\n",
1552          "-----\n",
1553          "\n",
1554          "**Input and Output Example**\n",
1555          "\n",
1556          "  * **CSV File Example (`tasks.csv`):**\n",
1557          "\n",
1558          "    ```csv\n",
1559          "    Task,Time_Required\n",
1560          "    Study,120\n",
1561          "    Exercise,60\n",
1562          "    Budgeting,30\n",
1563          "    Watch Movie,150\n",
1564          "    ```\n",
1565          "\n",
1566          "  * **Input:**\n",
1567          "\n",
1568          "    ```\n",
1569          "    Available Time (minutes): 210\n",
1570          "    ```\n",
1571          "\n",
1572          "  * **Output:**\n",
1573          "\n",
1574          "    ```\n",
1575          "    Selected Tasks:\n",
1576          "    1. Budgeting - Estimated Time: 30 minutes\n",
1577          "    2. Exercise - Estimated Time: 60 minutes\n",
1578          "    3. Study - Estimated Time: 120 minutes\n",
1579          "    ```\n",
1580          "\n",
1581          "---"
1582        ],
1583        "metadata": {
1584          "id": "-R4wA5dsmG1z"
1585        }
1586      },
1587      {
1588        "cell_type": "code",
1589        "source": [
1590          "import csv\n",
1591          "# Code to create an example file (for simulation purposes)\n",
1592          "def write_tasks_to_csv(filename, tasks):\n",
1593          "    # Open the file in write mode ('w')\n",
1594          "    with open(filename, 'w', newline='', encoding='utf-8') as csvfile:\n",
1595          "        fieldnames = ['Task', 'Time_Required']\n",
1596          "        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)\n",
1597          "\n",
1598          "        # Write the header row\n",
1599          "        writer.writeheader()\n",
1600          "\n",
1601          "        # Write the data rows\n",
1602          "        for task, time in tasks:\n",
1603          "            writer.writerow({'Task': task, 'Time_Required': time})\n",
1604          "\n",
1605          "# Task and time data\n",
1606          "tasks = [\n",
1607          "    ('Study', 120),\n",
1608          "    ('Exercise', 60),\n",
1609          "    ('Budgeting', 30),\n",
1610          "    ('Watch Movie', 150)\n",
1611          "]\n",
1612          "\n",
1613          "# Save to CSV file\n",
1614          "write_tasks_to_csv('tasks.csv', tasks)"
1615        ],
1616        "metadata": {
1617          "id": "NFwTGJdLz-XQ"
1618        },
1619        "execution_count": 120,
1620        "outputs": []
1621      },
1622      {
1623        "cell_type": "code",
1624        "source": [
1625          "import csv\n",
1626          "import operator # <--- 이 쀄을 μ½”λ“œ μ΅œμƒλ‹¨μ— μΆ”κ°€ν•΄μ•Ό ν•©λ‹ˆλ‹€.\n",
1627          "\n",
1628          "# Problems\n",
1629          "def load_tasks(filename):\n",
1630          "    all_tasks=[]\n",
1631          "    with open(filename, mode='r', encoding='utf-8') as file:\n",
1632          "        reader = csv.reader(file)\n",
1633          "        next(reader)  #fieldnames = ['Task', 'Time_Required'] κ±΄λ„ˆλ›°κΈ°\n",
1634          "\n",
1635          "        for row in reader:\n",
1636          "            task_name = row[0]\n",
1637          "            time_required = int(row[1]) # μ‹œκ°„μ„ μ •μˆ˜λ‘œ λ³€ν™˜ (맀우 μ€‘μš”)\n",
1638          "            all_tasks.append((task_name, time_required))\n",
1639          "\n",
1640          "    return all_tasks\n",
1641          "\n",
1642          "def suggest_tasks(tasks, remaining_time):\n",
1643          "    sorted_tasks = sorted(all_tasks, key=operator.itemgetter(1))\n",
1644          "    available_time = int(input(\"⏳ 남은 μ‹œκ°„(λΆ„)을 μž…λ ₯ν•˜μ„Έμš”: \"))\n",
1645          "\n",
1646          "    length = len(sorted_tasks)\n",
1647          "\n",
1648          "\n",
1649          "    using_time=0\n",
1650          "    print(\"Seleted tasks :\")\n",
1651          "    for a in range(length):\n",
1652          "\n",
1653          "        using_time += sorted_tasks[a][1]\n",
1654          "        if using_time <= available_time:\n",
1655          "            print(f\"{sorted_tasks[a][0]} - Estimated Time: {sorted_tasks[a][1]}\")\n",
1656          "\n",
1657          "def main():\n",
1658          "    pass"
1659        ],
1660        "metadata": {
1661          "id": "T0J674Hk0A5B"
1662        },
1663        "execution_count": 175,
1664        "outputs": []
1665      },
1666      {
1667        "cell_type": "code",
1668        "source": [
1669          "\n",
1670          "# ν”„λ‘œκ·Έλž¨ μ‹€ν–‰\n",
1671          "\n",
1672          "all_tasks=load_tasks('tasks.csv')\n",
1673          "print (all_tasks)\n",
1674          "\n",
1675          "suggest_tasks(all_tasks, 120)\n",
1676          "\n",
1677          "if __name__ == \"__main__\":\n",
1678          "    main()"
1679        ],
1680        "metadata": {
1681          "colab": {
1682            "base_uri": "https://localhost:8080/"
1683          },
1684          "id": "DdFT6cq50Nlu",
1685          "outputId": "d0427cfc-5100-4a8d-def3-3ee09ded3e7b"
1686        },
1687        "execution_count": 176,
1688        "outputs": [
1689          {
1690            "output_type": "stream",
1691            "name": "stdout",
1692            "text": [
1693              "[('Study', 120), ('Exercise', 60), ('Budgeting', 30), ('Watch Movie', 150)]\n",
1694              "⏳ 남은 μ‹œκ°„(λΆ„)을 μž…λ ₯ν•˜μ„Έμš”: 120\n",
1695              "Seleted tasks :\n",
1696              "Budgeting - Estimated Time: 30\n",
1697              "Exercise - Estimated Time: 60\n"
1698            ]
1699          }
1700        ]
1701      },
1702      {
1703        "cell_type": "markdown",
1704        "source": [
1705          "#### Problem 2. Math Puzzle: Sum of Primes\n",
1706          "\n",
1707          "* **Problem Description**: Calculate the sum of all prime numbers up to a user-provided number $n$. Consider an efficient method like the Sieve of Eratosthenes.\n",
1708          "\n",
1709          "\n",
1710          "  - **Lab Description**\n",
1711          "    This program prompts the user to enter a number and calculates the sum of all prime numbers up to and including that number. A prime number is a natural number greater than 1 that is divisible only by 1 and itself. You are free to choose the method for identifying prime numbers; however, you should implement an efficient algorithm.\n",
1712          "\n",
1713          "  - **Functional Requirements**\n",
1714          "\n",
1715          "      - **Prime Identification:** Determine the primality of every natural number up to the given limit. (Hint: Sieve of Eratosthenes)\n",
1716          "      - **Summation:** Calculate the sum of the identified prime numbers.\n",
1717          "      - **Output:** Display the calculated sum of the primes. The output format must include the upper limit entered by the user and the resulting sum.\n",
1718          "\n",
1719          "  - **Input/Output Example**\n",
1720          "\n",
1721          "      - Input:\n",
1722          "\n",
1723          "    <!-- end list -->\n",
1724          "\n",
1725          "    ```\n",
1726          "    Up to what number would you like to calculate the sum of primes?: 10\n",
1727          "    ```\n",
1728          "\n",
1729          "      - Output:\n",
1730          "\n",
1731          "    <!-- end list -->\n",
1732          "\n",
1733          "    ```\n",
1734          "    The sum of primes up to 10 is 17.\n",
1735          "    ```\n",
1736          "\n",
1737          "-----\n"
1738        ],
1739        "metadata": {
1740          "id": "QaS72fo9mGy4"
1741        }
1742      },
1743      {
1744        "cell_type": "code",
1745        "source": [
1746          "up=input(\"Up to what number would you like to calculate the sum of primes\")\n",
1747          "\n",
1748          "number=list(range(2,int(up)+1))\n",
1749          "sum = 0\n",
1750          "\n",
1751          "for num_1 in range(2,int(up)):\n",
1752          "    for num_2 in range(2,int(up)):\n",
1753          "        mul = num_1*num_2\n",
1754          "\n",
1755          "        if mul > int(up):\n",
1756          "            break\n",
1757          "\n",
1758          "        if mul in number:\n",
1759          "            number.remove(mul)\n",
1760          "\n",
1761          "for n in range(len(number)):\n",
1762          "    sum += number[n]\n",
1763          "\n",
1764          "\n",
1765          "print(f\"The sum of primes up to 10 is {sum}\")"
1766        ],
1767        "metadata": {
1768          "colab": {
1769            "base_uri": "https://localhost:8080/"
1770          },
1771          "id": "gR49AnkhQ94Q",
1772          "outputId": "d4df35e5-7a56-4161-dede-a9da66f8e440"
1773        },
1774        "execution_count": 208,
1775        "outputs": [
1776          {
1777            "output_type": "stream",
1778            "name": "stdout",
1779            "text": [
1780              "Up to what number would you like to calculate the sum of primes10\n",
1781              "The sum of primes up to 10 is 17\n"
1782            ]
1783          }
1784        ]
1785      },
1786      {
1787        "cell_type": "markdown",
1788        "source": [
1789          "#### Problem 3. Library Management System\n",
1790          "\n",
1791          "* **Problem Description**: Implement a comprehensive system using four classes: `Book`, `Member`, `Rental`, and the managing `LibraryManagement` class, covering adding, renting, and returning books.\n",
1792          "\n",
1793          "---\n",
1794          "\n",
1795          "Here is the English translation of the lab description.\n",
1796          "\n",
1797          "-----\n",
1798          "\n",
1799          "  - **Lab Description**\n",
1800          "\n",
1801          "    You are working as a system developer at a local library, and you have been tasked with developing a system to effectively manage the library's books, members, and rental information. You need to implement a `LibraryManagement` class and several subclasses to comprehensively handle functions such as adding, deleting, and searching for books, as well as checking books out and returning them.\n",
1802          "\n",
1803          "  - **System Components**\n",
1804          "\n",
1805          "      - **Books**: Stores book information. Each book must include the title, author, publication year, and ISBN.\n",
1806          "      - **Members**: Manages member information. Each member has a name, member ID, and a list of currently rented books.\n",
1807          "      - **Rentals**: Handles book rental and return information. It links the member ID and book ISBN upon rental and records the rental date and return date.\n",
1808          "\n",
1809          "  - **Methods and Classes to Implement**\n",
1810          "\n",
1811          "    1.  **Book Class**:\n",
1812          "\n",
1813          "    <!-- end list -->\n",
1814          "\n",
1815          "      - A class that stores book information (title, author, publication year, ISBN).\n",
1816          "      - Each book object manages its own unique information.\n",
1817          "\n",
1818          "    <!-- end list -->\n",
1819          "\n",
1820          "    2.  **Member Class**:\n",
1821          "\n",
1822          "    <!-- end list -->\n",
1823          "\n",
1824          "      - A class that stores member information (name, member ID, list of currently rented books).\n",
1825          "      - It manages rental records for each member.\n",
1826          "\n",
1827          "    <!-- end list -->\n",
1828          "\n",
1829          "    3.  **Rental Class**:\n",
1830          "\n",
1831          "    <!-- end list -->\n",
1832          "\n",
1833          "      - A class that stores rental information (Member ID, Book ISBN, rental date, return date).\n",
1834          "      - It handles the rental and return processes.\n",
1835          "\n",
1836          "    <!-- end list -->\n",
1837          "\n",
1838          "    4.  **LibraryManagement**:\n",
1839          "\n",
1840          "    <!-- end list -->\n",
1841          "\n",
1842          "      - Contains methods and data structures to manage books, members, and rental information.\n",
1843          "      - Implements methods to add, delete, and search for books.\n",
1844          "      - Implements methods to register members and view member information.\n",
1845          "      - Implements methods to manage the rental and return processes.\n",
1846          "\n",
1847          "  - **Example**\n",
1848          "\n",
1849          "      - Below is an example of the output when the following code is executed:\n",
1850          "\n",
1851          "        ```python\n",
1852          "        # Initialize Library Management System\n",
1853          "        library_system = LibraryManagement()\n",
1854          "\n",
1855          "        # Add books\n",
1856          "        library_system.add_book(\"1984\", \"George Orwell\", 1949, \"978-0451524935\")\n",
1857          "        library_system.add_book(\"To Kill a Mockingbird\", \"Harper Lee\", 1960, \"978-0446310789\")\n",
1858          "        print()\n",
1859          "\n",
1860          "        # Register member\n",
1861          "        library_system.add_member(\"Hong Gil-dong\")\n",
1862          "        print()\n",
1863          "\n",
1864          "        # Rent book\n",
1865          "        library_system.rent_book(\"978-0451524935\", \"Hong Gil-dong\")\n",
1866          "        print()\n",
1867          "\n",
1868          "        # Print book information\n",
1869          "        library_system.print_books()\n",
1870          "        print()\n",
1871          "\n",
1872          "        # Print member information\n",
1873          "        library_system.print_members()\n",
1874          "\n",
1875          "        # Return book\n",
1876          "        library_system.return_book(\"978-0451524935\", \"Hong Gil-dong\")\n",
1877          "        print()\n",
1878          "\n",
1879          "        # Print member information\n",
1880          "        library_system.print_members()\n",
1881          "        ```\n",
1882          "\n",
1883          "      - Output Example:\n",
1884          "\n",
1885          "        ```\n",
1886          "        Book '1984' (Author: George Orwell, Year: 1949) has been added.\n",
1887          "        Book 'To Kill a Mockingbird' (Author: Harper Lee, Year: 1960) has been added.\n",
1888          "        Member 'Hong Gil-dong' has been registered.\n",
1889          "        Member 'Hong Gil-dong' has rented '1984'.\n",
1890          "        Book List:\n",
1891          "        - 1984 (Author: George Orwell, Year: 1949)\n",
1892          "        - To Kill a Mockingbird (Author: Harper Lee, Year: 1960)\n",
1893          "        Member List:\n",
1894          "        - Hong Gil-dong (Books Rented: 1984)\n",
1895          "        Member 'Hong Gil-dong' has returned '1984'.\n",
1896          "        Member List:\n",
1897          "        - Hong Gil-dong (Books Rented: None)\n",
1898          "        ```\n",
1899          "\n",
1900          "  - **Requirements**\n",
1901          "\n",
1902          "      - All classes and methods must include appropriate input validation and exception handling.\n",
1903          "      - The system must provide appropriate feedback based on user actions (e.g., when a book does not exist, or when member information is missing).\n",
1904          "\n",
1905          "-----\n",
1906          "\n",
1907          "**Would you like me to create the Python class structure (skeleton code) for this assignment?**"
1908        ],
1909        "metadata": {
1910          "id": "wsDknX9gmGwS"
1911        }
1912      },
1913      {
1914        "cell_type": "code",
1915        "source": [
1916          "class LibraryManagement:\n",
1917          "    def __init__(self):\n",
1918          "        # Repository for book info: { 'ISBN': {'title': title, 'author': author, 'year': year} }\n",
1919          "        self.books = {}\n",
1920          "        # Repository for member info: { 'Name': {'rented_books': [List of ISBNs]} }\n",
1921          "        self.members = {}\n",
1922          "\n",
1923          "    # 1. Add Book\n",
1924          "    def add_book(self, title, author, year, isbn):\n",
1925          "        if isbn in self.books:\n",
1926          "            print(f\"Error: Book with ISBN {isbn} already exists.\")\n",
1927          "            return\n",
1928          "\n",
1929          "        # Store detailed information as a dictionary instead of an object\n",
1930          "        self.books[isbn] = {\n",
1931          "            'title': title,\n",
1932          "            'author': author,\n",
1933          "            'year': year\n",
1934          "        }\n",
1935          "        print(f\"Book '{title}' has been added.\")\n",
1936          "\n",
1937          "    # 2. Add Member\n",
1938          "    def add_member(self, name):\n",
1939          "        if name in self.members:\n",
1940          "            print(f\"Error: Member '{name}' already exists.\")\n",
1941          "            return\n",
1942          "\n",
1943          "        # Initialize member with an empty list for rented books\n",
1944          "        self.members[name] = {'rented_books': []}\n",
1945          "        print(f\"Member '{name}' has been registered.\")\n",
1946          "\n",
1947          "    # 3. Rent Book\n",
1948          "    def rent_book(self, isbn, name):\n",
1949          "        # Validation: Check if book and member exist\n",
1950          "        if isbn not in self.books:\n",
1951          "            print(\"Error: Book not found.\")\n",
1952          "            return\n",
1953          "        if name not in self.members:\n",
1954          "            print(\"Error: Member not found.\")\n",
1955          "            return\n",
1956          "\n",
1957          "        # Add ISBN to the member's rental list\n",
1958          "        self.members[name]['rented_books'].append(isbn)\n",
1959          "\n",
1960          "        # Retrieve title for confirmation message\n",
1961          "        book_title = self.books[isbn]['title']\n",
1962          "        print(f\"Member '{name}' has rented '{book_title}'.\")\n",
1963          "\n",
1964          "    # 4. Return Book\n",
1965          "    def return_book(self, isbn, name):\n",
1966          "        if name not in self.members:\n",
1967          "            print(\"Error: Member not found.\")\n",
1968          "            return\n",
1969          "\n",
1970          "        member_rent_list = self.members[name]['rented_books']\n",
1971          "\n",
1972          "        # Check if the member actually rented this specific book\n",
1973          "        if isbn in member_rent_list:\n",
1974          "            member_rent_list.remove(isbn)\n",
1975          "            book_title = self.books[isbn]['title']\n",
1976          "            print(f\"Member '{name}' has returned '{book_title}'.\")\n",
1977          "        else:\n",
1978          "            print(f\"Error: Member has not rented book with ISBN {isbn}.\")\n",
1979          "\n",
1980          "    # 5. Print Books\n",
1981          "    def print_books(self):\n",
1982          "        print(\"\\n[Book List]\")\n",
1983          "        for info in self.books.values():\n",
1984          "            print(f\"- {info['title']} (Author: {info['author']})\")\n",
1985          "\n",
1986          "    # 6. Print Members\n",
1987          "    def print_members(self):\n",
1988          "        print(\"\\n[Member List]\")\n",
1989          "        for name, info in self.members.items():\n",
1990          "            # Convert the list of ISBNs into a list of book titles for display\n",
1991          "            rented_titles = []\n",
1992          "            for isbn in info['rented_books']:\n",
1993          "                rented_titles.append(self.books[isbn]['title'])\n",
1994          "\n",
1995          "            # Format the output string\n",
1996          "            status = \", \".join(rented_titles) if rented_titles else \"None\"\n",
1997          "            print(f\"- {name} (Rented: {status})\")\n",
1998          "\n",
1999          "# --- Execution Test ---\n",
2000          "library = LibraryManagement()\n",
2001          "\n",
2002          "# Add books\n",
2003          "library.add_book(\"1984\", \"George Orwell\", 1949, \"978-001\")\n",
2004          "library.add_book(\"Little Prince\", \"Saint-Exupery\", 1943, \"978-002\")\n",
2005          "\n",
2006          "# Add member\n",
2007          "library.add_member(\"Jae-Moon\")\n",
2008          "\n",
2009          "# Rent book\n",
2010          "library.rent_book(\"978-001\", \"Jae-Moon\")\n",
2011          "\n",
2012          "# Print status\n",
2013          "library.print_members()\n",
2014          "\n",
2015          "# Return book\n",
2016          "library.return_book(\"978-001\", \"Jae-Moon\")\n",
2017          "\n",
2018          "# Print status again\n",
2019          "library.print_members()"
2020        ],
2021        "metadata": {
2022          "colab": {
2023            "base_uri": "https://localhost:8080/"
2024          },
2025          "id": "dN30u7cSuVdk",
2026          "outputId": "08d7e5ab-0143-44e6-9311-be24e4a68318"
2027        },
2028        "execution_count": 301,
2029        "outputs": [
2030          {
2031            "output_type": "stream",
2032            "name": "stdout",
2033            "text": [
2034              "Book '1984' has been added.\n",
2035              "Book 'Little Prince' has been added.\n",
2036              "Member 'Jae-Moon' has been registered.\n",
2037              "Member 'Jae-Moon' has rented '1984'.\n",
2038              "\n",
2039              "[Member List]\n",
2040              "- Jae-Moon (Rented: 1984)\n",
2041              "Member 'Jae-Moon' has returned '1984'.\n",
2042              "\n",
2043              "[Member List]\n",
2044              "- Jae-Moon (Rented: None)\n"
2045            ]
2046          }
2047        ]
2048      },
2049      {
2050        "cell_type": "code",
2051        "source": [
2052          "    library_system = LibraryManagement()\n",
2053          "    library_system.add_book(\"1984\", \"George Orwell\", 1949, \"978-0451524935\")\n",
2054          "    library_system.add_book(\"To Kill a Mockingbird\", \"Harper Lee\", 1960, \"978-0446310789\")\n",
2055          "    library_system.add_member(\"홍길동\")\n",
2056          "\n",
2057          "    library_system.print_books()\n",
2058          "    library_system.print_members()"
2059        ],
2060        "metadata": {
2061          "colab": {
2062            "base_uri": "https://localhost:8080/"
2063          },
2064          "id": "hBqTcGXPzv-8",
2065          "outputId": "e6bdeae9-e05c-4581-f182-5ff6bc872272"
2066        },
2067        "execution_count": 302,
2068        "outputs": [
2069          {
2070            "output_type": "stream",
2071            "name": "stdout",
2072            "text": [
2073              "Book '1984' has been added.\n",
2074              "Book 'To Kill a Mockingbird' has been added.\n",
2075              "Member '홍길동' has been registered.\n",
2076              "\n",
2077              "[Book List]\n",
2078              "- 1984 (Author: George Orwell)\n",
2079              "- To Kill a Mockingbird (Author: Harper Lee)\n",
2080              "\n",
2081              "[Member List]\n",
2082              "- 홍길동 (Rented: None)\n"
2083            ]
2084          }
2085        ]
2086      },
2087      {
2088        "cell_type": "code",
2089        "source": [],
2090        "metadata": {
2091          "id": "k6D7JE5lzw0D"
2092        },
2093        "execution_count": null,
2094        "outputs": []
2095      }
2096    ]
2097  }