Created
July 21, 2023 03:14
-
-
Save JenniferNorthrup/7d3f25cab8b590ba1f5d611f21c7fd3a to your computer and use it in GitHub Desktop.
Practice+Exercise+-+Intro_to_variables.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/JenniferNorthrup/7d3f25cab8b590ba1f5d611f21c7fd3a/practice-exercise-intro_to_variables.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "N8fwKxeCa4jI" | |
| }, | |
| "source": [ | |
| "# **INTRO TO VARIABLE EXERCISE**" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "uWCna0wEa4kR" | |
| }, | |
| "source": [ | |
| "### 1. What will be the type of the *add* variable?\n", | |
| "a = 10\n", | |
| "\n", | |
| "b = 5.1\n", | |
| "\n", | |
| "add = a + b" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "zrDiygl7a4kR", | |
| "outputId": "9d3d6019-42db-47d1-8930-ffa23e363ff0" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "float" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 1 | |
| } | |
| ], | |
| "source": [ | |
| "a = 10\n", | |
| "b = 5.1\n", | |
| "add = a + b\n", | |
| "type(add)\n", | |
| "#float" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "072oofmea4kS" | |
| }, | |
| "source": [ | |
| "### 2. Is 5 == (3+2)?" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "pe7CvTxKa4kS", | |
| "outputId": "d34342d5-c8da-4843-8a4c-5c9c9e3c88b0" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "execute_result", | |
| "data": { | |
| "text/plain": [ | |
| "True" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "execution_count": 4 | |
| } | |
| ], | |
| "source": [ | |
| "5 == (3+2)\n", | |
| "#True" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "mCG_iAPta4kS" | |
| }, | |
| "source": [ | |
| "### 3. Add 33 in variable *a* and print the result\n", | |
| "\n", | |
| "a = 3" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "6sDZFOjqa4kS", | |
| "outputId": "a6ea2592-be35-4622-f4dc-add77525234a" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "36\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "a = 3\n", | |
| "a = a + 33\n", | |
| "print(a)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "X3vKts6Ua4kS" | |
| }, | |
| "source": [ | |
| "### 4. Convert integer variable *a* to float and check its type\n", | |
| "\n", | |
| "a = 3" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "dMHJmZqYa4kT", | |
| "outputId": "4cb23960-fda8-4436-f894-fbb3ce2da550" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "<class 'float'>\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "a = 3\n", | |
| "converted = float(a)\n", | |
| "print(type(converted))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "eBolmTPEa4kT" | |
| }, | |
| "source": [ | |
| "### 5. What will be 5 times *a* if the value of a is 10?" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "4clXAHDra4kT", | |
| "outputId": "54d4302c-72c5-4954-8990-5eef0d67d0e1" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "50\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "a = 10\n", | |
| "print(a * 5)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "iyD84-dka4kT" | |
| }, | |
| "source": [ | |
| "### 6. Write a program to calculate the area of a triangle with base = 10 and height = 5\n", | |
| "\n", | |
| "Hint : area of triangle = 1/2 * base * height" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 10, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "Yd1Qa6Xia4kT", | |
| "outputId": "834eca44-883c-43ce-e696-53c344115ecc" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "25.0\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "base = 10\n", | |
| "height = 5\n", | |
| "area = 1/2 * base * height\n", | |
| "print(area)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "VObzo9pza4kU" | |
| }, | |
| "source": [ | |
| "### 7. What will be the value of *z* in the following expression:\n", | |
| "\n", | |
| "z = (v + w) * (x / y)\n", | |
| "\n", | |
| "If\n", | |
| "\n", | |
| "v = 10\n", | |
| "\n", | |
| "w = 25\n", | |
| "\n", | |
| "x = 70\n", | |
| "\n", | |
| "y = 2" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "-1c5mW7Ja4kU", | |
| "outputId": "c3a7c711-41af-4b66-f2c7-860f6658d90b" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "1225.0\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "v = 10\n", | |
| "w = 25\n", | |
| "x = 70\n", | |
| "y = 2\n", | |
| "z = (v + w) * (x / y)\n", | |
| "print(z)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "xdM9HSPia4kU" | |
| }, | |
| "source": [ | |
| "### 8. Swap values of *a* and *b*\n", | |
| "If before swapping a = 10 and b = 5\n", | |
| "\n", | |
| "Then after swapping a = 5 and b = 10\n", | |
| "##### Values can not be hardcoded" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 12, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "wGTl-2hca4kU", | |
| "outputId": "3c8bed88-0d17-4e26-95c7-7963d2c2b69e" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "5\n", | |
| "10\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "a = 10\n", | |
| "b = 5\n", | |
| "temp = a\n", | |
| "a = b\n", | |
| "b = temp\n", | |
| "print(a)\n", | |
| "print(b)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "sMLzl7kQa4kU" | |
| }, | |
| "source": [ | |
| "### 9. Convert 35 degree Celsius temperature to Fahrenheit" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 13, | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "miG6NMqUa4kU", | |
| "outputId": "b9378989-f9fc-40dd-8cbc-7c1169490a4d" | |
| }, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "95.0\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "celsius = 35\n", | |
| "fahrenheit = (celsius * 9/5) + 32\n", | |
| "print(fahrenheit)" | |
| ] | |
| } | |
| ], | |
| "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.9.7" | |
| }, | |
| "colab": { | |
| "provenance": [], | |
| "include_colab_link": true | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment