{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8c148a9d",
   "metadata": {},
   "source": [
    "# Proyecto: Calculadora de Datos\n",
    "\n",
    "Construimos paso a paso un programa que recibe una lista de números y devuelve un resumen estadístico. El objetivo es que funcione y que el código quede claro y reutilizable."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "188aeda2",
   "metadata": {},
   "source": [
    "## Paso 1: estadísticas básicas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "64378243",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:08.180204Z",
     "iopub.status.busy": "2026-09-29T03:43:08.179974Z",
     "iopub.status.idle": "2026-09-29T03:43:08.186404Z",
     "shell.execute_reply": "2026-09-29T03:43:08.185924Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'cantidad': 6, 'suma': 61, 'promedio': 10.166666666666666, 'minimo': 3, 'maximo': 22}\n"
     ]
    }
   ],
   "source": [
    "def estadisticas_basicas(numeros):\n",
    "    return {\n",
    "        \"cantidad\": len(numeros),\n",
    "        \"suma\": sum(numeros),\n",
    "        \"promedio\": sum(numeros) / len(numeros),\n",
    "        \"minimo\": min(numeros),\n",
    "        \"maximo\": max(numeros),\n",
    "    }\n",
    "\n",
    "datos = [10, 4, 7, 22, 3, 15]\n",
    "print(estadisticas_basicas(datos))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43a9feb3",
   "metadata": {},
   "source": [
    "## Paso 2: contar valores sobre el promedio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bf7a3308",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:08.189126Z",
     "iopub.status.busy": "2026-09-29T03:43:08.189035Z",
     "iopub.status.idle": "2026-09-29T03:43:08.192695Z",
     "shell.execute_reply": "2026-09-29T03:43:08.192273Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "def sobre_promedio(numeros):\n",
    "    promedio = sum(numeros) / len(numeros)\n",
    "    return len([n for n in numeros if n > promedio])\n",
    "\n",
    "print(sobre_promedio([10, 4, 7, 22, 3, 15]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "764c1414",
   "metadata": {},
   "source": [
    "## Paso 3: manejar la lista vacía"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3c14f717",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:08.196325Z",
     "iopub.status.busy": "2026-09-29T03:43:08.196241Z",
     "iopub.status.idle": "2026-09-29T03:43:08.199941Z",
     "shell.execute_reply": "2026-09-29T03:43:08.199520Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'cantidad': 6, 'suma': 61, 'promedio': 10.166666666666666, 'minimo': 3, 'maximo': 22, 'sobre_promedio': 2}\n",
      "{'error': 'la lista está vacía'}\n"
     ]
    }
   ],
   "source": [
    "def resumen(numeros):\n",
    "    if not numeros:\n",
    "        return {\"error\": \"la lista está vacía\"}\n",
    "    promedio = sum(numeros) / len(numeros)\n",
    "    return {\n",
    "        \"cantidad\": len(numeros),\n",
    "        \"suma\": sum(numeros),\n",
    "        \"promedio\": promedio,\n",
    "        \"minimo\": min(numeros),\n",
    "        \"maximo\": max(numeros),\n",
    "        \"sobre_promedio\": len([n for n in numeros if n > promedio]),\n",
    "    }\n",
    "\n",
    "print(resumen([10, 4, 7, 22, 3, 15]))\n",
    "print(resumen([]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d9ba2b7",
   "metadata": {},
   "source": [
    "## Paso 4: separar cálculo de presentación"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0277dc61",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:08.203867Z",
     "iopub.status.busy": "2026-09-29T03:43:08.203772Z",
     "iopub.status.idle": "2026-09-29T03:43:08.207207Z",
     "shell.execute_reply": "2026-09-29T03:43:08.206813Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cantidad: 6\n",
      "suma: 61\n",
      "promedio: 10.166666666666666\n",
      "minimo: 3\n",
      "maximo: 22\n",
      "sobre_promedio: 2\n"
     ]
    }
   ],
   "source": [
    "def imprimir_resumen(numeros):\n",
    "    datos = resumen(numeros)\n",
    "    if \"error\" in datos:\n",
    "        print(\"No hay datos que resumir.\")\n",
    "        return\n",
    "    for clave, valor in datos.items():\n",
    "        print(f\"{clave}: {valor}\")\n",
    "\n",
    "imprimir_resumen([10, 4, 7, 22, 3, 15])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2e8076ef",
   "metadata": {},
   "source": [
    "## Pruebas rápidas\n",
    "\n",
    "Lista normal, un solo elemento y lista vacía."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bdecaefe",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-29T03:43:08.209722Z",
     "iopub.status.busy": "2026-09-29T03:43:08.209639Z",
     "iopub.status.idle": "2026-09-29T03:43:08.212548Z",
     "shell.execute_reply": "2026-09-29T03:43:08.212115Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cantidad: 4\n",
      "suma: 20\n",
      "promedio: 5.0\n",
      "minimo: 5\n",
      "maximo: 5\n",
      "sobre_promedio: 0\n",
      "cantidad: 1\n",
      "suma: 99\n",
      "promedio: 99.0\n",
      "minimo: 99\n",
      "maximo: 99\n",
      "sobre_promedio: 0\n",
      "No hay datos que resumir.\n"
     ]
    }
   ],
   "source": [
    "imprimir_resumen([5, 5, 5, 5])\n",
    "imprimir_resumen([99])\n",
    "imprimir_resumen([])"
   ]
  }
 ],
 "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
}
