{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Welcome to Pyodios!\n",
    "\n",
    "This example notebook shows you the basics of running Python on your iPhone or iPad.\n",
    "Tap a code cell and press **Run** to execute it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Basic arithmetic\n",
    "x = 10\n",
    "y = 3\n",
    "print(f\"{x} + {y} = {x + y}\")\n",
    "print(f\"{x} * {y} = {x * y}\")\n",
    "print(f\"{x} ** {y} = {x ** y}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Strings and f-strings\n",
    "name = \"Pyodios\"\n",
    "version = 1\n",
    "greeting = f\"Hello from {name} v{version}!\"\n",
    "print(greeting)\n",
    "print(greeting.upper())\n",
    "print(f\"Length: {len(greeting)} characters\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Lists and comprehensions\n",
    "squares = [n ** 2 for n in range(1, 11)]\n",
    "print(f\"Squares: {squares}\")\n",
    "\n",
    "evens = [n for n in squares if n % 2 == 0]\n",
    "print(f\"Even squares: {evens}\")\n",
    "print(f\"Sum: {sum(squares)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Functions\n",
    "def fibonacci(n):\n",
    "    \"\"\"Return the first n Fibonacci numbers.\"\"\"\n",
    "    fibs = []\n",
    "    a, b = 0, 1\n",
    "    for _ in range(n):\n",
    "        fibs.append(a)\n",
    "        a, b = b, a + b\n",
    "    return fibs\n",
    "\n",
    "result = fibonacci(10)\n",
    "print(f\"Fibonacci(10): {result}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Your First Plot\n",
    "\n",
    "matplotlib is bundled with Pyodios, so plotting works without any setup. The cell below uses the `fibonacci` function from above and draws the sequence."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# matplotlib is already installed, just import and plot\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "fibs = fibonacci(15)\n",
    "\n",
    "plt.figure(figsize=(8, 4))\n",
    "plt.plot(fibs, marker='o', linewidth=2)\n",
    "plt.title('Fibonacci sequence (first 15 terms)')\n",
    "plt.xlabel('Index')\n",
    "plt.ylabel('Value')\n",
    "plt.grid(True, alpha=0.3)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# numpy is also bundled, useful for numeric work\n",
    "import numpy as np\n",
    "\n",
    "data = np.random.normal(loc=0, scale=1, size=500)\n",
    "print(f'Mean: {data.mean():.3f}')\n",
    "print(f'Std:  {data.std():.3f}')\n",
    "\n",
    "plt.figure(figsize=(8, 3))\n",
    "plt.hist(data, bins=30, edgecolor='white')\n",
    "plt.title('Histogram of 500 normal samples')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Next Steps\n",
    "\n",
    "Now that you have run a few cells, here are some things to try:\n",
    "\n",
    "- **Edit and re-run**: tap any code cell, change a value, and run it again to see the output update.\n",
    "- **Add a new cell**: use the + button in the toolbar to add a code or markdown cell of your own.\n",
    "- **Install more packages**: open the Packages tab and try one of these.\n",
    "  - `pandas` for data tables and CSV work\n",
    "  - `scipy` for scientific computing (stats, optimization, signal)\n",
    "  - `sympy` for symbolic math (algebra, calculus)\n",
    "  - `requests` for HTTP calls (Pyodide patches it for the browser)\n",
    "  - `seaborn` for prettier statistical plots on top of matplotlib\n",
    "- **Get help**: type `help(plt.plot)` in a cell, or open the Help tab to browse Python documentation.\n",
    "- **Save your work**: use the notebook actions menu to rename and save the file. It lives in the Files app on your device.\n",
    "- **Switch to the editor**: the Editor tab is better for longer Python scripts and supports find and replace."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (Pyodide)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12"
  },
  "nbformat": 4,
  "nbformat_minor": 5
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
