{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "01Variaveis&Strings.ipynb", "version": "0.3.2", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "cells": [ { "metadata": { "id": "xzPWIQ1P9Tg8", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "7f038c8f-0108-4bd7-f431-2b827b6b4ce1" }, "cell_type": "code", "source": [ "# As variaveis são utilizadas para guardar valores. \n", "# Uma string é ums série de caracteres rodeados por aspas (\"\") ou pelicas(''). \n", "# Hello world \n", "print(\"Hello World!\")\n" ], "execution_count": 1, "outputs": [ { "output_type": "stream", "text": [ "Hello World!\n" ], "name": "stdout" } ] }, { "metadata": { "id": "RHEdBthF9ThP", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "bf8b8a5b-42cb-4500-eb9b-f170c6ca1e07" }, "cell_type": "code", "source": [ "# \"Olá Mundo\" com variáveis\n", "\n", "a = \"Hello World!\"\n", "print(a)" ], "execution_count": 4, "outputs": [ { "output_type": "stream", "text": [ "Hello World!\n" ], "name": "stdout" } ] }, { "metadata": { "id": "kam3wKTH9ThY", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "bb603a7c-2e56-4fe2-9d66-733f9a7ecc0a" }, "cell_type": "code", "source": [ "# Concatenação (juntar strings) \n", "\n", "a=\"Hello\"\n", "b=\"World!\"\n", "c=a+\" \"+b\n", "print(c)" ], "execution_count": 7, "outputs": [ { "output_type": "stream", "text": [ "Hello World!\n" ], "name": "stdout" } ] }, { "metadata": { "id": "GoEi4Uxx9Thi", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "fd9f8e60-300e-4084-ff0e-9ff09ee4159d" }, "cell_type": "code", "source": [ "a=\"Hello\"\n", "b=\"World!\"\n", "print(a+\" \"+b)" ], "execution_count": 8, "outputs": [ { "output_type": "stream", "text": [ "Hello World!\n" ], "name": "stdout" } ] }, { "metadata": { "id": "ppqc297xEg3s", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "65398bfa-877b-4a22-fccc-adbd722fafb8" }, "cell_type": "code", "source": [ "#soma\n", "a=1\n", "b=2\n", "c=a + b\n", "print(c)" ], "execution_count": 10, "outputs": [ { "output_type": "stream", "text": [ "3\n" ], "name": "stdout" } ] }, { "metadata": { "id": "-m_xPftOE0lK", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "c0d9d081-00c6-431c-a198-b1931d7414d1" }, "cell_type": "code", "source": [ "#multiplicação\n", "a=4\n", "b=2\n", "c=a * b\n", "print(c)" ], "execution_count": 12, "outputs": [ { "output_type": "stream", "text": [ "8\n" ], "name": "stdout" } ] }, { "metadata": { "id": "LsvdTpkxFBf8", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "eec2c9bf-3ded-4a7b-aa3e-4669155cfbe0" }, "cell_type": "code", "source": [ "#divisão\n", "a=9\n", "b=2\n", "c=a / b\n", "print(c)" ], "execution_count": 24, "outputs": [ { "output_type": "stream", "text": [ "4.5\n" ], "name": "stdout" } ] }, { "metadata": { "id": "DAeuNqTFFLVD", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "f4e448ee-3532-4c30-f2b8-d38b4ced807d" }, "cell_type": "code", "source": [ "a=9\n", "b=2\n", "c=a // b\n", "print(c)" ], "execution_count": 20, "outputs": [ { "output_type": "stream", "text": [ "4\n" ], "name": "stdout" } ] }, { "metadata": { "id": "1C7iPC5-FWuV", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "f0e85ce9-ae23-43c8-93d5-59b44059654a" }, "cell_type": "code", "source": [ "a=9\n", "b=3\n", "c=a ** b\n", "print(c)" ], "execution_count": 25, "outputs": [ { "output_type": "stream", "text": [ "729\n" ], "name": "stdout" } ] }, { "metadata": { "id": "CR4xouYnGglU", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "d915acdf-1b0f-4f3f-dc3e-133799148687" }, "cell_type": "code", "source": [ "a=\"olá\"\n", "b=3\n", "c=a * b\n", "print(c)" ], "execution_count": 27, "outputs": [ { "output_type": "stream", "text": [ "oláoláolá\n" ], "name": "stdout" } ] }, { "metadata": { "id": "ogApuWskGvD2", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "23fbebdc-f988-45fc-e26c-2174a64814ba" }, "cell_type": "code", "source": [ "a=\"4\"\n", "b=2\n", "c=a * b\n", "print(c)" ], "execution_count": 28, "outputs": [ { "output_type": "stream", "text": [ "44\n" ], "name": "stdout" } ] }, { "metadata": { "id": "mJ4zj0qwG-42", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 54 }, "outputId": "6590058f-dd14-48c8-947c-b527983d666d" }, "cell_type": "code", "source": [ "nome = input(\"Como te chamas?\")\n", "resposta = \"Olá \"+nome+\"!\"\n", "print(resposta)" ], "execution_count": 31, "outputs": [ { "output_type": "stream", "text": [ "Como te chamas?Carlos\n", "Olá Carlos!\n" ], "name": "stdout" } ] }, { "metadata": { "id": "CHVqZV2AIPdI", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 54 }, "outputId": "9cb4de12-9e74-4b48-a568-99c881f54046" }, "cell_type": "code", "source": [ "idade = input(\"Que idades têns?\")\n", "resposta = idade+\"?\"\n", "print(resposta)" ], "execution_count": 32, "outputs": [ { "output_type": "stream", "text": [ "Que idades têns?25\n", "25?\n" ], "name": "stdout" } ] }, { "metadata": { "id": "XHjdT8CQIm-H", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 54 }, "outputId": "f3914c9c-9f25-4214-8858-cbd3d0f147b8" }, "cell_type": "code", "source": [ "idade = input(\"Que idades têns?\")\n", "idade1=float(idade)\n", "nascimento = 2019-idade1\n", "print(nascimento)" ], "execution_count": 34, "outputs": [ { "output_type": "stream", "text": [ "Que idades têns?25\n", "1994.0\n" ], "name": "stdout" } ] }, { "metadata": { "id": "sHju69Z3JlkQ", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 54 }, "outputId": "81150083-7941-488a-ac40-c55775366824" }, "cell_type": "code", "source": [ "idade = input(\"Que idades têns?\")\n", "idade1=int(idade)\n", "nascimento = 2019-idade1\n", "print(nascimento)" ], "execution_count": 37, "outputs": [ { "output_type": "stream", "text": [ "Que idades têns?25\n", "1994\n" ], "name": "stdout" } ] }, { "metadata": { "id": "pol9OtF5Kday", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 54 }, "outputId": "9e651bf8-8e61-4225-e372-1067f09579f9" }, "cell_type": "code", "source": [ "idade = input(\"Que idades têns?\")\n", "idade1=int(idade)\n", "if idade1>=18:\n", " print(\"é maior\")" ], "execution_count": 49, "outputs": [ { "output_type": "stream", "text": [ "Que idades têns?22\n", "é maior\n" ], "name": "stdout" } ] }, { "metadata": { "id": "x9XnjKwmNZ9i", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "PaxroiCvK-mH", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "d557f395-8c6e-4ddb-aaf1-2fc17a56b063" }, "cell_type": "code", "source": [ "#operadores logicos (==)\n", "idade1==18" ], "execution_count": 41, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": { "tags": [] }, "execution_count": 41 } ] }, { "metadata": { "id": "k01aUdGdLnAf", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "71526889-bda4-4da5-ff5d-2630e3c61a13" }, "cell_type": "code", "source": [ "#>=\n", "idade1>=18" ], "execution_count": 42, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": { "tags": [] }, "execution_count": 42 } ] }, { "metadata": { "id": "K3KAbCujLxc4", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "752b626d-6946-4a50-d1a6-afd32f1bdfac" }, "cell_type": "code", "source": [ "#>=\n", "idade1<=18" ], "execution_count": 43, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "True" ] }, "metadata": { "tags": [] }, "execution_count": 43 } ] }, { "metadata": { "id": "b09KeLPfL0oa", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "08ebbd42-e642-4e6f-d49b-47d6dc978e25" }, "cell_type": "code", "source": [ "#>=\n", "idade1>18" ], "execution_count": 44, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "False" ] }, "metadata": { "tags": [] }, "execution_count": 44 } ] }, { "metadata": { "id": "dmHgSs3YNbBj", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "Cjsv5gAeL4ax", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "007ee7ec-50ce-4d42-edee-74e475bedda2" }, "cell_type": "code", "source": [ "#>=\n", "idade1<18" ], "execution_count": 45, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "False" ] }, "metadata": { "tags": [] }, "execution_count": 45 } ] }, { "metadata": { "id": "02pYr-7-L6y_", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 35 }, "outputId": "7958b113-1500-45f9-9cff-883b7c441916" }, "cell_type": "code", "source": [ "#!=\n", "idade1!=18" ], "execution_count": 46, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "False" ] }, "metadata": { "tags": [] }, "execution_count": 46 } ] }, { "metadata": { "id": "iRDa1zR0NdhA", "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", "height": 54 }, "outputId": "a47f4466-5005-4803-b3f8-dcd80b2ab5f5" }, "cell_type": "code", "source": [ "idade = input(\"Que idades têns?\")\n", "idade1=int(idade)\n", "if idade1>=18:\n", " print(\"é maior\")\n", "print(\"pois é...\")" ], "execution_count": 52, "outputs": [ { "output_type": "stream", "text": [ "Que idades têns?17\n", "pois é...\n" ], "name": "stdout" } ] } ] }