{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.11"
  },
  "colab": {
   "provenance": []
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cell-0000",
   "metadata": {},
   "source": [
    "# Getting Started with Python & Notebooks\n",
    "\n",
    "Meet Python and the notebook workflow — run your first code, write comments, and use Python as a powerful calculator.\n",
    "\n",
    "*Part of the free [Python for Data Science](https://ramadnsyh.dev/courses/python-for-data-science) course by [Muhammad Ramadiansyah](https://ramadnsyh.dev). This notebook is generated from the interactive lesson — [read it online](https://ramadnsyh.dev/courses/python-for-data-science/getting-started).*"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0001",
   "metadata": {},
   "source": [
    "Every data scientist's toolbox starts in the same place: Python and a\n",
    "notebook. In this lesson you'll learn why Python became the language of data\n",
    "science, how notebooks organize your work into runnable cells, and how to\n",
    "write your very first lines of code — printing messages, doing arithmetic,\n",
    "and storing results in variables.\n",
    "\n",
    "You can run every code block **right here in the browser**, or download this\n",
    "lesson as a Jupyter notebook and open it in Google Colab. Either way, the\n",
    "code is identical."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0002",
   "metadata": {},
   "source": [
    "## Why Python?\n",
    "\n",
    "Python is a general-purpose programming language, but it has utterly\n",
    "dominated data science for a decade. A few reasons why:\n",
    "\n",
    "- **Readable syntax** — Python code often looks like plain English, so you\n",
    "  spend your energy on the *problem*, not the language.\n",
    "- **The ecosystem** — pandas for tables, NumPy for math, matplotlib for\n",
    "  charts, scikit-learn for machine learning, PyTorch for deep learning. Almost\n",
    "  every data tool speaks Python first.\n",
    "- **Interactive by design** — you can type one line, run it, see the result,\n",
    "  and adjust. That tight feedback loop is exactly how data exploration works.\n",
    "\n",
    "You don't need to be a software engineer to use Python well. This module\n",
    "teaches just the core you'll use every day as a data practitioner."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0003",
   "metadata": {},
   "source": [
    "## Notebooks: code in cells\n",
    "\n",
    "A **notebook** (Jupyter locally, or Google Colab in the cloud) is a document\n",
    "made of **cells**. There are two kinds:\n",
    "\n",
    "- **Markdown cells** hold formatted text — headings, bullet points, notes to\n",
    "  yourself. A `#` makes a big heading, `##` a smaller one.\n",
    "- **Code cells** hold Python. You run a cell and its output appears directly\n",
    "  below it.\n",
    "\n",
    "This mix of prose and runnable code is why notebooks rule data science: your\n",
    "analysis and its explanation live in one document.\n",
    "\n",
    "A few keyboard shortcuts worth memorizing (press `Esc` first, then the key):\n",
    "\n",
    "| Shortcut | What it does |\n",
    "|---|---|\n",
    "| `Shift + Enter` | run the cell, move to the next one |\n",
    "| `Ctrl + Enter` | run the cell, stay on it |\n",
    "| `a` / `b` | insert a new cell above / below |\n",
    "| `m` / `y` | turn the cell into markdown / code |\n",
    "| `dd` | delete the cell |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0004",
   "metadata": {},
   "source": [
    "> **Execution order matters**\n",
    "> \n",
    "> Cells run in the order YOU run them, not the order they appear on the page.\n",
    "> If a cell uses a variable defined in another cell, that other cell must have\n",
    "> been run first. When a notebook gets confusing, use \"Restart & Run All\" to\n",
    "> re-run everything top to bottom."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0005",
   "metadata": {},
   "source": [
    "## Your first code: print()\n",
    "\n",
    "The `print()` function displays whatever you put between the parentheses.\n",
    "Text (a **string**) goes in quotes. Try running this — then edit the message\n",
    "and run it again:"
   ]
  },
  {
   "cell_type": "code",
   "id": "cell-0006",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(\"Hello, data science!\")\n",
    "print(\"Python is going to be my superpower.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0007",
   "metadata": {},
   "source": [
    "Notice each `print()` produces one line of output. In a notebook, the last\n",
    "expression in a cell is also displayed automatically, but `print()` works\n",
    "everywhere and shows exactly what you ask for — we'll use it constantly."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0008",
   "metadata": {},
   "source": [
    "## Comments: notes the computer ignores\n",
    "\n",
    "Anything after a `#` on a line is a **comment**. Python skips it entirely;\n",
    "it exists purely for humans reading the code. Good comments explain *why*,\n",
    "not just *what*:"
   ]
  },
  {
   "cell_type": "code",
   "id": "cell-0009",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "# This whole line is a comment - Python ignores it\n",
    "print(\"Comments make code understandable\")  # comments can share a line too\n",
    "\n",
    "# print(\"This line never runs because it is commented out\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0010",
   "metadata": {},
   "source": [
    "Commenting out a line (adding `#` in front) is also a handy way to\n",
    "temporarily disable code while debugging."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0011",
   "metadata": {},
   "source": [
    "## Python as a calculator\n",
    "\n",
    "Before variables, functions, or data frames, Python is a very good\n",
    "calculator. The arithmetic operators:\n",
    "\n",
    "| Operator | Meaning | Example |\n",
    "|---|---|---|\n",
    "| `+` | addition | `10 + 3` → 13 |\n",
    "| `-` | subtraction | `10 - 3` → 7 |\n",
    "| `*` | multiplication | `10 * 3` → 30 |\n",
    "| `/` | division (always gives a decimal) | `10 / 3` → 3.333… |\n",
    "| `//` | floor division (drops the remainder) | `10 // 3` → 3 |\n",
    "| `%` | modulo (the remainder itself) | `10 % 3` → 1 |\n",
    "| `**` | exponent | `10 ** 3` → 1000 |"
   ]
  },
  {
   "cell_type": "code",
   "id": "cell-0012",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(10 + 3)\n",
    "print(10 - 3)\n",
    "print(10 * 3)\n",
    "print(10 / 3)    # true division: always a float\n",
    "print(10 // 3)   # floor division: whole part only\n",
    "print(10 % 3)    # modulo: the remainder\n",
    "print(10 ** 3)   # exponent: 10 to the power of 3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0013",
   "metadata": {},
   "source": [
    "Two of these deserve a closer look because they show up constantly in data\n",
    "work. The **modulo** operator `%` tells you the remainder after division —\n",
    "which makes it the classic even/odd test. And `**` with a fractional power\n",
    "gives you roots:"
   ]
  },
  {
   "cell_type": "code",
   "id": "cell-0014",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(10 % 2)     # 0 -> 10 is even\n",
    "print(11 % 2)     # 1 -> 11 is odd\n",
    "\n",
    "print(9 ** 0.5)   # square root of 9\n",
    "print(2 ** 10)    # how many values fit in 10 bits"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0015",
   "metadata": {},
   "source": [
    "Python also respects the usual math precedence: `**` before `*` and `/`,\n",
    "which come before `+` and `-`. Use parentheses whenever there's any doubt —\n",
    "`(2 + 3) * 4` is clearer than trusting the reader to remember the rules."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0016",
   "metadata": {},
   "source": [
    "## Your first variables\n",
    "\n",
    "Retyping numbers gets old fast. A **variable** is a name that stores a value\n",
    "so you can reuse it. You create one with `=`, the **assignment** operator:"
   ]
  },
  {
   "cell_type": "code",
   "id": "cell-0017",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "price = 12000        # assignment: store 12000 under the name \"price\"\n",
    "quantity = 3\n",
    "\n",
    "total = price * quantity\n",
    "print(total)\n",
    "\n",
    "# Reassigning replaces the old value\n",
    "quantity = 5\n",
    "total = price * quantity\n",
    "print(total)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0018",
   "metadata": {},
   "source": [
    "Read `=` as \"gets\", not \"equals\": `total = price * quantity` means \"compute\n",
    "the right side, then store it under the name `total`\". If you assign to the\n",
    "same name again, the old value is simply replaced — variables always hold\n",
    "their **most recent** assignment."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0019",
   "metadata": {},
   "source": [
    "> **Run it here or in Colab**\n",
    "> \n",
    "> Every lesson in this course has a \"Download notebook\" option. The generated\n",
    "> .ipynb opens directly in Jupyter or Google Colab, so you can practice with\n",
    "> real notebook shortcuts. For quick experiments, the in-browser runners on\n",
    "> this page are all you need."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0020",
   "metadata": {},
   "source": [
    "### 🏋️ Exercise — A tip calculator in three variables\n",
    "\n",
    "A dinner bill is 480000 rupiah, you want to leave a 10% tip, and 3 people are\n",
    "splitting the total evenly. Using variables (no hard-coded intermediate\n",
    "numbers), compute and print: the tip amount, the grand total, and each\n",
    "person's share. **Bonus:** use `//` and `%` to figure out how many full\n",
    "groups of 8 fit into 100, and what's left over."
   ]
  },
  {
   "cell_type": "code",
   "id": "cell-0021",
   "metadata": {},
   "execution_count": null,
   "outputs": [],
   "source": [
    "# Your solution here"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0022",
   "metadata": {},
   "source": [
    "<details><summary>✅ Show solution</summary>\n",
    "\n",
    "```python\n",
    "bill = 480000\n",
    "tip_rate = 0.10\n",
    "people = 3\n",
    "\n",
    "tip = bill * tip_rate\n",
    "total = bill + tip\n",
    "per_person = total / people\n",
    "\n",
    "print(tip)\n",
    "print(total)\n",
    "print(per_person)\n",
    "\n",
    "# Bonus: split 100 into groups of 8\n",
    "print(100 // 8)  # 12 full groups\n",
    "print(100 % 8)   # 4 left over\n",
    "```\n",
    "\n",
    "</details>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cell-0023",
   "metadata": {},
   "source": [
    "Next up: variables get much more interesting once you know Python's data\n",
    "types — numbers, text, lists, and dictionaries."
   ]
  }
 ]
}