{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a46231b7",
   "metadata": {},
   "source": [
    "# Variables, tipos y control de flujo\n",
    "\n",
    "Objetivos: practicar los tipos primitivos, las conversiones, las f-strings y los bucles `while` y `for` con ejemplos ejecutables. Refuerza el quiz de variables y tipos."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fcd27390",
   "metadata": {},
   "source": [
    "## Tipos primitivos\n",
    "\n",
    "Cada valor tiene un tipo. `type()` te lo dice en cualquier momento."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "71bcb0b4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:09.976078Z",
     "iopub.status.busy": "2026-09-29T03:43:09.975864Z",
     "iopub.status.idle": "2026-09-29T03:43:09.982445Z",
     "shell.execute_reply": "2026-09-29T03:43:09.981929Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30 -> int\n",
      "1.75 -> float\n",
      "Ada -> str\n",
      "True -> bool\n",
      "None -> NoneType\n"
     ]
    }
   ],
   "source": [
    "edad = 30\n",
    "altura = 1.75\n",
    "nombre = \"Ada\"\n",
    "activo = True\n",
    "sin_valor = None\n",
    "for v in (edad, altura, nombre, activo, sin_valor):\n",
    "    print(v, \"->\", type(v).__name__)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05e08040",
   "metadata": {},
   "source": [
    "## Conversiones entre tipos\n",
    "\n",
    "Lo que parece un número puede ser texto. Se convierte con `int()`, `float()` o `str()`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "004136d8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:09.987455Z",
     "iopub.status.busy": "2026-09-29T03:43:09.987267Z",
     "iopub.status.idle": "2026-09-29T03:43:09.991453Z",
     "shell.execute_reply": "2026-09-29T03:43:09.990999Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30\n",
      "19.99 | 19\n"
     ]
    }
   ],
   "source": [
    "texto = \"25\"\n",
    "numero = int(texto)\n",
    "print(numero + 5)\n",
    "print(str(19.99), \"|\", int(19.99))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f44a1777",
   "metadata": {},
   "source": [
    "## input() siempre devuelve str\n",
    "\n",
    "Aquí simulamos la entrada con una variable para que el notebook corra solo, sin pedir datos por teclado."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e7560871",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:10.005289Z",
     "iopub.status.busy": "2026-09-29T03:43:10.004942Z",
     "iopub.status.idle": "2026-09-29T03:43:10.010952Z",
     "shell.execute_reply": "2026-09-29T03:43:10.010180Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tipo: str\n",
      "como número: 50\n"
     ]
    }
   ],
   "source": [
    "entrada = \"42\"  # así llegaría desde input()\n",
    "print(\"tipo:\", type(entrada).__name__)\n",
    "print(\"como número:\", int(entrada) + 8)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c4fa575",
   "metadata": {},
   "source": [
    "## f-strings\n",
    "\n",
    "La forma clara de combinar texto y valores."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c7c52638",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:10.015645Z",
     "iopub.status.busy": "2026-09-29T03:43:10.015481Z",
     "iopub.status.idle": "2026-09-29T03:43:10.019954Z",
     "shell.execute_reply": "2026-09-29T03:43:10.019437Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ada tiene 30 años\n",
      "Con IVA: 23.19\n"
     ]
    }
   ],
   "source": [
    "nombre = \"Ada\"\n",
    "edad = 30\n",
    "precio = 19.99\n",
    "print(f\"{nombre} tiene {edad} años\")\n",
    "print(f\"Con IVA: {precio * 1.16:.2f}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "995a1ecd",
   "metadata": {},
   "source": [
    "## Bucles while y for\n",
    "\n",
    "`while` repite mientras una condición sea verdadera; `for` recorre una secuencia."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "befca0b0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:10.024899Z",
     "iopub.status.busy": "2026-09-29T03:43:10.024732Z",
     "iopub.status.idle": "2026-09-29T03:43:10.029013Z",
     "shell.execute_reply": "2026-09-29T03:43:10.028597Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "while 0\n",
      "while 1\n",
      "while 2\n",
      "for rojo\n",
      "for verde\n",
      "for azul\n",
      "range 1\n",
      "range 3\n",
      "range 5\n"
     ]
    }
   ],
   "source": [
    "contador = 0\n",
    "while contador < 3:\n",
    "    print(\"while\", contador)\n",
    "    contador += 1\n",
    "\n",
    "for color in [\"rojo\", \"verde\", \"azul\"]:\n",
    "    print(\"for\", color)\n",
    "\n",
    "for i in range(1, 6, 2):\n",
    "    print(\"range\", i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b47adb0c",
   "metadata": {},
   "source": [
    "## break, continue y acumular"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "acaf7a96",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:10.031433Z",
     "iopub.status.busy": "2026-09-29T03:43:10.031287Z",
     "iopub.status.idle": "2026-09-29T03:43:10.035103Z",
     "shell.execute_reply": "2026-09-29T03:43:10.034772Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "impar 1\n",
      "impar 3\n",
      "suma 66\n"
     ]
    }
   ],
   "source": [
    "for n in range(10):\n",
    "    if n == 5:\n",
    "        break\n",
    "    if n % 2 == 0:\n",
    "        continue\n",
    "    print(\"impar\", n)\n",
    "\n",
    "total = 0\n",
    "for n in [4, 8, 15, 16, 23]:\n",
    "    total += n\n",
    "print(\"suma\", total)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
