{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.EXT.2 \u2014 Building on Basics\n",
    "\n",
    "Second half of the fast pass: loops, functions, lists/strings, and debugging. Same format as 1.EXT.1 \u2014 one reminder, one example, one quick check each."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Quick Recall: Loops\n",
    "\n",
    "`for i in range(n):` repeats a fixed number of times; `while condition:` repeats until the condition goes `False`. `break` exits a loop early."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example\n",
    "for room_number in range(3):\n",
    "    print(f\"Exploring room {room_number + 1}...\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Quick check:** write a `while` loop that reduces a monster's health by a fixed amount each pass, printing the health each time, until it's at or below 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your quick check here\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Quick Recall: Functions\n",
    "\n",
    "`def name(params):` defines a function; `return` sends a value back (no `return` gives `None`). A variable created inside a function stays inside it (scope)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example\n",
    "def calculate_total(gold, bonus):\n",
    "    return gold + bonus\n",
    "\n",
    "print(calculate_total(40, 15))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Quick check:** write a function `can_afford(gold, price)` that returns a `bool`, and call it twice with different values."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your quick check here\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Quick Recall: Lists &amp; Strings\n",
    "\n",
    "Lists (`[\"sword\", \"shield\"]`) are ordered, indexed from `0`, mutable \u2014 `.append()` adds, `len()` counts. Strings support the same indexing/slicing but are immutable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example\n",
    "inventory = [\"sword\", \"shield\"]\n",
    "inventory.append(\"potion\")\n",
    "print(len(inventory), inventory[0])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Quick check:** given `party = [\"Zara\", \"Old Finn\"]`, add a third member and print the full list reversed (`[::-1]`)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your quick check here\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Quick Recall: Debugging\n",
    "\n",
    "Read tracebacks bottom-up \u2014 the last line names the error and usually describes it clearly. `NameError`, `TypeError`, and `IndexError` each point to a different category of problem. When nothing crashes but the output's still wrong, add a `print()` to see what a variable actually holds."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example \u2014 a fixed bug, for reference\n",
    "inventory = [\"sword\", \"shield\", \"potion\"]\n",
    "print(inventory[len(inventory) - 1])   # last item, without hardcoding the index\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Quick check:** the cell below has one bug \u2014 find and fix it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Find and fix the one bug\n",
    "\n",
    "party = [\"Zara\", \"Old Finn\"]\n",
    "print(f\"Party leader: {pary[0]}\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
