{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "36f77851-0200-473f-b8c3-b10e4bcfdc03", "metadata": {}, "outputs": [], "source": [ "import cmath, math, random, statistics\n", "from fractions import Fraction" ] }, { "cell_type": "markdown", "id": "6ecb3ce5-8a2d-48ce-83ce-50bcc0aa486b", "metadata": {}, "source": [ "# Números: \n", "### Enteros en distintas bases" ] }, { "cell_type": "code", "execution_count": 2, "id": "47cee901-7ff3-43a5-addd-57a7ed69ee1b", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "(100, 255)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "entero = 100\n", "hexa = 0xFF\n", "entero, hexa" ] }, { "cell_type": "code", "execution_count": 3, "id": "7fa14b03-00de-419c-9faf-726bdee1774d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('0x64', '0b11111111', '0o144')" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hex(entero), bin(hexa), oct(entero)" ] }, { "cell_type": "markdown", "id": "5fab96c6-a576-4b7d-8721-10e99c88518a", "metadata": {}, "source": [ "### Flotantes y decimales de precisión fija" ] }, { "cell_type": "code", "execution_count": 4, "id": "64ccef46-f704-4048-9c29-56b35b40e70a", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "(10.45, 0.001, -inf, nan)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "flotante = 10.45\n", "mantisas = float('1e-003')\n", "infinitos = float('-Infinity')\n", "no_definido = float(\"nan\")\n", "\n", "flotante, mantisas, infinitos, no_definido" ] }, { "cell_type": "markdown", "id": "3f517951-1417-445e-92e0-230a2d61210a", "metadata": {}, "source": [ "### Fracciones" ] }, { "cell_type": "code", "execution_count": 5, "id": "4cae4a5c-a1e9-4732-a16f-d1dc445e98d2", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "(Fraction(4, 5), Fraction(8, 15), 0.0008, nan)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "frac = Fraction(\"4/5\")\n", "frac, frac * Fraction(\"2/3\"), frac * mantisas, frac * no_definido" ] }, { "cell_type": "markdown", "id": "b0ae4120-4b19-435f-8a22-5f550e5e55d6", "metadata": {}, "source": [ "### Imaginarios" ] }, { "cell_type": "code", "execution_count": 6, "id": "cc89847f-a488-41d2-b5ed-c8fe351798c0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((8+10j), (4+5j), (9+14j))" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "imag = 4 + 5j\n", "imag * 2, imag, imag + 5 + 9j" ] }, { "cell_type": "code", "execution_count": 7, "id": "f2a4527e-9f17-476a-97ef-cd28a2754444", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(nan+5j)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "imag + no_definido" ] }, { "cell_type": "markdown", "id": "ff5dc309-dc40-44fc-b0a5-9c487ccdc98e", "metadata": {}, "source": [ "# Operaciones \n", "## Sumar, restar, potencias, dividir, resto, división entera" ] }, { "cell_type": "code", "execution_count": 8, "id": "7b4b646d-e817-4efa-95f0-789ee28d54dc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(355, 25500, 16581375)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hexa + entero, hexa * entero, hexa ** 3" ] }, { "cell_type": "code", "execution_count": 9, "id": "6ede147f-2f16-4520-9439-1de613fca158", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2.55, 55, 2)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hexa / entero, hexa % entero, hexa // entero" ] }, { "cell_type": "markdown", "id": "86308f5a-4ba3-49bb-a390-a30b267f72a5", "metadata": {}, "source": [ "## Funciones matemáticas" ] }, { "cell_type": "code", "execution_count": 10, "id": "f30dea6c-21aa-424f-a5ac-53dbc5ddbe81", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(15.968719422671311, 5.541263545158426)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.sqrt(hexa), math.log(hexa)" ] }, { "cell_type": "code", "execution_count": 11, "id": "2e51d40f-e4f5-4187-89b3-95365ba8d512", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(-0.3048106211022167, -0.9524129804151563, 0.320040389379563)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.sin(60), math.cos(60), math.tan(60)" ] }, { "cell_type": "code", "execution_count": 12, "id": "a3319ef3-7ced-471e-85bc-0bc10d59fa84", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "((-56.16227422023235-48.50245524177091j),\n", " (-48.506859457844584+56.15717492513018j))" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cmath.sin(imag), cmath.cos(imag)" ] }, { "cell_type": "code", "execution_count": 13, "id": "07f96d2c-593a-448b-8d4c-9ccfb630fee3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(6.4031242374328485, 0.8960553845713439)" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cmath.polar(imag)" ] }, { "cell_type": "markdown", "id": "27617df7-b8a4-4554-91d9-10a0b23a2217", "metadata": {}, "source": [ "## Números aleatorios" ] }, { "cell_type": "code", "execution_count": 14, "id": "07e8f4b1-a4da-4f0e-ad76-86cc215cce4e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "99" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.randint(1, 100)" ] }, { "cell_type": "code", "execution_count": 15, "id": "8c1c0855-17a0-4fcc-aa9c-d77dbef7a2d5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-16.346364909850635" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.gauss(mu=0, sigma=10.5)" ] }, { "cell_type": "markdown", "id": "f7e293c1-5aba-47a4-ae4f-4aa84bfa4bb6", "metadata": {}, "source": [ "# Listas" ] }, { "cell_type": "code", "execution_count": 16, "id": "9756dfae-c7f5-4fd8-bc2b-12c59267ddd4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[4, 13, 0, -2, 100]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mi_lista = [4, 13, 0, -2, 100]\n", "mi_lista" ] }, { "cell_type": "code", "execution_count": 17, "id": "baddc427-0273-490e-91aa-3bd9e5615aef", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mi_lista[0]" ] }, { "cell_type": "code", "execution_count": 18, "id": "e0418d3e-69fb-4250-ae25-2fefe1bf4cad", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "100" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mi_lista[-1]" ] }, { "cell_type": "code", "execution_count": 19, "id": "ba6307af-a365-4d05-a8a4-5d69718f89e3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[13, 0]" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mi_lista[1:3]" ] }, { "cell_type": "markdown", "id": "45d911cb-5ad1-4228-a7a3-f58398b39e57", "metadata": {}, "source": [ "## Procesado de listas por comprensión" ] }, { "cell_type": "code", "execution_count": 20, "id": "d2181924-409f-431b-a6f3-03b5fe1f145e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0.013098860821720073,\n", " -0.41711290195712114,\n", " 1.4030250544750604,\n", " -1.2315113097308397,\n", " 0.4038148211318986,\n", " -0.6465557302067724,\n", " 1.1809481370294428,\n", " -0.5030861212443873,\n", " -0.10340319416242585,\n", " 0.6538796995454971,\n", " -0.03411292075196376,\n", " 0.0025312568699263414]" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lista = [random.gauss(0, 0.6) for x in range(12)]\n", "lista" ] }, { "cell_type": "code", "execution_count": 21, "id": "39d49390-1769-49bb-9d16-045842ee763e", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[13, -417, 1403, -1231, 403, -646, 1180, -503, -103, 653, -34, 2]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lista = [int(x * 1000) for x in lista]\n", "lista" ] }, { "cell_type": "code", "execution_count": 22, "id": "49ba1fa5-531a-4287-8029-f3f97ddc38cc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-1231, -646, -503, -417, -103, -34, 2, 13, 403, 653, 1180, 1403]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lista.sort()\n", "lista" ] }, { "cell_type": "code", "execution_count": 23, "id": "47d6f55a-9ad0-43ef-be48-d2f08ea1b039", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1180, 13, 653, 2, -646, 403, -417, 1403, -34, -503, -103, -1231]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.shuffle(lista)\n", "lista" ] }, { "cell_type": "markdown", "id": "458a3666-f835-479f-a969-3f305d89ad89", "metadata": {}, "source": [ "# Estadísticas" ] }, { "cell_type": "code", "execution_count": 24, "id": "b278ce8e-d648-4e62-b969-3c2b8a9518e1", "metadata": {}, "outputs": [], "source": [ "# help(statistics)" ] }, { "cell_type": "code", "execution_count": 25, "id": "3f983e5f-5bd8-46f0-807d-689e03cd941a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "755.4613280518191" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "statistics.stdev(lista)" ] }, { "cell_type": "code", "execution_count": 26, "id": "4b6506c5-a8cb-4636-87b0-f21d50ac58c4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(60, -16.0)" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "statistics.mean(lista), statistics.median(lista)" ] }, { "cell_type": "code", "execution_count": 27, "id": "86ffd04f-9eba-4ea3-b8ca-da294d44bc86", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-560.2, -89.2, 10.8, 863.8]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lista.sort()\n", "statistics.quantiles(lista, n=5)" ] }, { "cell_type": "code", "execution_count": 28, "id": "60e98316-cd25-4a2d-b507-979ed5555393", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[-560.2, -89.2, 10.8, 863.8]" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.shuffle(lista)\n", "statistics.quantiles(lista, n=5)" ] }, { "cell_type": "markdown", "id": "6752a450-17cf-48fc-a419-dc2ca0228b90", "metadata": {}, "source": [ "# Caracteres" ] }, { "cell_type": "code", "execution_count": 29, "id": "c80784a7-84a8-4f33-8543-24b814018dce", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Perez, Ana: alumna de la UNNE'" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nombre = \"Ana\"\n", "apellido = \"Perez\"\n", "apellido + \", \" + nombre + \": alumna de la UNNE\"" ] }, { "cell_type": "code", "execution_count": 30, "id": "414368ab-3d77-47b4-a44a-675bc4165159", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Alfonso', 'Marta', 'María', 'Pedro']" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lista_año_22 = [\"María\", \"Pedro\", \"Marta\", \"Alfonso\"]\n", "sorted(lista_año_22)" ] }, { "cell_type": "code", "execution_count": 31, "id": "be72f370-d36c-4932-b37f-c065838bf58f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['María', 'Pedro', 'Marta', 'Alfonso', 'Inés', 'Alfredo', 'Martín']" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "todos = lista_año_22 + [\"Inés\", \"Alfredo\", \"Martín\"]\n", "todos" ] }, { "cell_type": "code", "execution_count": 32, "id": "6e32b223-a913-4ddf-97ef-30f014eb42d2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['María',\n", " 'Pedro',\n", " 'Marta',\n", " 'Alfonso',\n", " 'Inés',\n", " 'Alfredo',\n", " 'Martín',\n", " 'Zulma',\n", " 'Ulises']" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "todos += [\"Zulma\", \"Ulises\"]\n", "todos" ] }, { "cell_type": "code", "execution_count": 33, "id": "dbbedb58-69f7-4a6f-b9c9-46e40624be87", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(['María', 'Pedro', 'Marta', 'Alfonso', 'Inés', 'Alfredo', 'Martín'],\n", " ['Ulises', 'Zulma'])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "afuera = [todos.pop(), todos.pop()]\n", "todos, afuera" ] }, { "cell_type": "markdown", "id": "c9e1fde3-4690-486b-8680-5cb5360c3140", "metadata": {}, "source": [ "# Diccionarios" ] }, { "cell_type": "code", "execution_count": 34, "id": "ea19405b-d44c-437e-955b-f2782a108b14", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = {\"Ana\": 10, \"Oscar\": 50}\n", "a[\"Ana\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "39491f52-823b-4413-a992-151166d7de35", "metadata": {}, "outputs": [], "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.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }