{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "id": "6aba1b14", "metadata": { "id": "6aba1b14" }, "source": [ "# Estructura condicional: ```if```" ] }, { "cell_type": "markdown", "id": "17914d6e", "metadata": { "id": "17914d6e" }, "source": [ "\"ordinograma\"" ] }, { "cell_type": "code", "execution_count": 1, "id": "a7095f77", "metadata": { "id": "a7095f77", "outputId": "8b264356-bc16-407c-cbf6-9811fab81814", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Los dos valores son iguales\n" ] } ], "source": [ "a = 5\n", "b = 5\n", "if a == b:\n", " print(\"Los dos valores son iguales\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "b7795ae6", "metadata": { "id": "b7795ae6", "outputId": "e0f8ee14-3231-4321-ec7c-53513377e016", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "El valor de c es 25\n" ] } ], "source": [ "a = 5\n", "b = 5\n", "c = 0\n", "if a == b:\n", " c = a * b\n", "print(\"El valor de c es\", c) # c es 25" ] }, { "cell_type": "code", "execution_count": 3, "id": "9493e674", "metadata": { "id": "9493e674", "outputId": "c537dbaa-f781-496a-e09b-c9b714c9c4f5", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "El valor de c es 0\n" ] } ], "source": [ "a = 5\n", "b = 5\n", "c = 0\n", "if a != b: # La condición se evalúa como False\n", " c = a * b # Si la condición es falsa no se ejecuta el código del cuerpo\n", "print(\"El valor de c es\", c) # c es 0" ] } ], "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.8.8" }, "colab": { "name": "0290_condicional_if.ipynb", "provenance": [], "include_colab_link": true } }, "nbformat": 4, "nbformat_minor": 5 }