{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d9724920",
   "metadata": {},
   "source": [
    "# Preface"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b76f38c6",
   "metadata": {},
   "source": [
    "This site contains a set of lecture notes (the \"book\") for the Python components of IST-5551, offered by the Jaggi Business School at Missouri S&T in Rolla, Missouri. It was inspired in part by Dr. Allen Downey's [Think Python](https://allendowney.github.io/ThinkPython/)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6516d914",
   "metadata": {},
   "source": [
    "## At a Glance\n",
    "\n",
    "Each chapter in this book builds on the previous ones, so you should read them in order and take time to work on the exercises before you move on.\n",
    "\n",
    "- **Part I: Fundamentals**: Core Python concepts such as statements, expressions, operators, built-in data types, conditionals, loops, functions, files, modules, and packaging.\n",
    "\n",
    "- **Part II: Data Structures**: Python's main data structures -- lists, tuples, dictionaries, and sets -- along with strings, regular expressions, and text analysis.\n",
    "\n",
    "- **Part III: Advanced Topics**: Algorithms, searching and sorting, exceptions, unit testing, and object-oriented programming.\n",
    "\n",
    "- **Appendices**: Practical setup topics such as tooling, Python installation, virtual environments, Jupyter notebooks, and related workflow tips."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "323d2954",
   "metadata": {},
   "source": [
    "## How to Use This Book\n",
    "\n",
    "Each chapter section is an interactive Jupyter Notebook. You can:\n",
    "- Read through the rendered content\n",
    "- Interact with the code directly by downloading the notebooks locally or using Binder\n",
    "- Use the Live Code cells for practice"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64a8925c-5f7b-466e-83f5-02ee5fd70e1a",
   "metadata": {},
   "source": [
    "## Live Coding \n",
    "\n",
    "Some sections include exercises that support live coding. To enable them, click the Live Code button. It may take some time to launch a new session; wait until you see a \"ready\" message. The live coding cells let you practice the concepts and skills introduced in each section.\n",
    "\n",
    "```{image} ../images/thebe-loading.png\n",
    ":alt: thebe-loading\n",
    ":width: 50%\n",
    ":align: center\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30b551ae",
   "metadata": {},
   "source": [
    "(download-function)=\n",
    "## Custom Code \n",
    "If you download the notebook files and place them in a folder in your project directory, or if you write your own notebooks and want to use features such as `jupyturtle`, you may need additional helper files. The cell below downloads the files used specifically for this book. You don't need to understand this code yet, but you can see that it downloads several `*.py` files from Dr. Allen Downey's GitHub repository to enable the required functionality.\n",
    "\n",
    "You then create a folder in your project directory called `shared`, place the downloaded files in it, and add an empty file called `__init__.py`, which makes the `shared` folder a package. Later, in any project notebook, you can import modules from that package and use their functions:\n",
    "\n",
    "```python\n",
    "from shared import [module]\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e31cebe",
   "metadata": {},
   "source": [
    "**The download function**:\n",
    "\n",
    "```python\n",
    "from os.path import basename, exists\n",
    "\n",
    "def download(url):\n",
    "    filename = basename(url)\n",
    "    if not exists(filename):\n",
    "        from urllib.request import urlretrieve\n",
    "\n",
    "        local, _ = urlretrieve(url, filename)\n",
    "        print(\"Downloaded \" + str(local))\n",
    "    return filename\n",
    "```\n",
    "\n",
    "- thinkpython: 'https://github.com/AllenDowney/ThinkPython/raw/v3/thinkpython.py'\n",
    "- diagram: 'https://github.com/AllenDowney/ThinkPython/raw/v3/diagram.py'\n",
    "- jupyturtle: 'https://github.com/ramalho/jupyturtle/releases/download/2024-03/jupyturtle.py'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64d7b8ce",
   "metadata": {},
   "source": [
    "To use the downloaded files as modules, create a directory named `shared` in the project root and place the files in it. In each notebook that needs these modules, put the code snippet below at the beginning of the notebook.\n",
    "\n",
    "```python\n",
    "import sys\n",
    "from pathlib import Path\n",
    "\n",
    "current = Path.cwd()\n",
    "for parent in [current, *current.parents]:\n",
    "    if (parent / '_config.yml').exists():\n",
    "        project_root = parent  # ← Add project root, not chapters\n",
    "        break\n",
    "else:\n",
    "    project_root = Path.cwd().parent.parent\n",
    "\n",
    "sys.path.insert(0, str(project_root))\n",
    "\n",
    "from shared import thinkpython, diagram, jupyturtle\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b5c02f3-911b-4127-afe5-c8e1f5724eba",
   "metadata": {},
   "source": [
    "## Credits\n",
    "\n",
    "Parts of these notes are adapted from [Think Python](https://allendowney.github.io/ThinkPython/) by Dr. Allen Downey.\n",
    "\n",
    "This work is licensed under the [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3954f83c",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
