Skip to content

Instantly share code, notes, and snippets.

@DianSano
Created February 22, 2022 11:08
Show Gist options
  • Select an option

  • Save DianSano/91fd6cbd8d34ce2d9f1c480406e61547 to your computer and use it in GitHub Desktop.

Select an option

Save DianSano/91fd6cbd8d34ce2d9f1c480406e61547 to your computer and use it in GitHub Desktop.
LAB_SC01_2022.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "LAB_SC01_2022.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyPXtCUrO42XE3FSZ2d1xLzi",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/DianSano/91fd6cbd8d34ce2d9f1c480406e61547/lab_sc01_2022.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# **Intro to python notebook**"
],
"metadata": {
"id": "Yjsy5_g-CZW0"
}
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Q-mNCmmg9UjF",
"outputId": "6c4ba051-6305-42b8-d47c-1a6c59d21d00"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Tue Feb 22 10:41:08 2022\n"
]
}
],
"source": [
"import time\n",
"print(time.ctime())"
]
},
{
"cell_type": "code",
"source": [
"x = 1\n",
"x"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "x3ykMwmQ_iWY",
"outputId": "3bf7d75f-e5df-4cff-eec0-d81e1d9f20db"
},
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"1"
]
},
"metadata": {},
"execution_count": 2
}
]
},
{
"cell_type": "code",
"source": [
"x = x + 1\n",
"x"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "azv3bn-i_4cl",
"outputId": "fdfaf845-3aa7-4e66-ca60-a6ab7458cc95"
},
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"2"
]
},
"metadata": {},
"execution_count": 3
}
]
},
{
"cell_type": "code",
"source": [
"x = 1\n",
"y = x + 1\n",
"x = 2\n",
"y"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "vXbEg5LpADR7",
"outputId": "76be9e20-f851-4e9d-c1e7-56a6deea3f41"
},
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"2"
]
},
"metadata": {},
"execution_count": 4
}
]
},
{
"cell_type": "markdown",
"source": [
"# **Intro to numpy**\n"
],
"metadata": {
"id": "_x4KMxdkCkgo"
}
},
{
"cell_type": "code",
"source": [
"import numpy as np"
],
"metadata": {
"id": "GZ6GOR82BJoZ"
},
"execution_count": 9,
"outputs": []
},
{
"cell_type": "code",
"source": [
"x = np.array([1,4,3])\n",
"x"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "8H1okY0EBwQH",
"outputId": "874e1c9b-9ff9-4c4b-d570-c029c3bcd7af"
},
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([1, 4, 3])"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "code",
"source": [
"y = np.array([[1,4,3], [9,2,7]])\n",
"y"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "VV6keY_5B6eT",
"outputId": "92bf3524-aadf-4ccc-95b2-35f647b460e4"
},
"execution_count": 12,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([[1, 4, 3],\n",
" [9, 2, 7]])"
]
},
"metadata": {},
"execution_count": 12
}
]
},
{
"cell_type": "markdown",
"source": [
"# **Intro to functions**"
],
"metadata": {
"id": "kFiA35ecCqq3"
}
},
{
"cell_type": "code",
"source": [
"def my_adder(a,b,c):\n",
" \"\"\"\n",
" function to sum the 3 numbers\n",
" Input: 3 numbers a,b,c\n",
" Output: the sum of a,b,c\n",
" author: 1060003624\n",
" date: today\n",
" \"\"\"\n",
"\n",
" #this is the summation\n",
" out = a + b + c\n",
"\n",
" return out"
],
"metadata": {
"id": "5V72Hqv5Cseh"
},
"execution_count": 17,
"outputs": []
},
{
"cell_type": "code",
"source": [
"my_adder(2,3,4)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "oW6XoVOyDz6B",
"outputId": "f87e0d61-b097-472e-8fae-9256a864f59b"
},
"execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"9"
]
},
"metadata": {},
"execution_count": 18
}
]
},
{
"cell_type": "markdown",
"source": [
"# IF Else **Statements**"
],
"metadata": {
"id": "SZtYe3KWE_mb"
}
},
{
"cell_type": "markdown",
"source": [
"Example of If-else Statement"
],
"metadata": {
"id": "zvT8qD_AFTRc"
}
},
{
"cell_type": "code",
"source": [
"def my_thermo_stat(temp, desired_temp):\n",
" if temp < desired_temp - 5:\n",
" status = 'Heat'\n",
" elif temp > desired_temp + 5:\n",
" status = \"AC\"\n",
" else:\n",
" status = 'off'\n",
"\n",
" return status"
],
"metadata": {
"id": "dcmJLZVzFCLt"
},
"execution_count": 19,
"outputs": []
},
{
"cell_type": "code",
"source": [
"status = my_thermo_stat(65,60)\n",
"status"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"id": "WTfvjnRiF3R1",
"outputId": "43e0d260-100c-47b4-a6e6-47ef7fef9a1a"
},
"execution_count": 22,
"outputs": [
{
"output_type": "execute_result",
"data": {
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "string"
},
"text/plain": [
"'off'"
]
},
"metadata": {},
"execution_count": 22
}
]
},
{
"cell_type": "markdown",
"source": [
"(What will be the value of y after the following script is executed?)"
],
"metadata": {
"id": "xYEY0_aAGc7f"
}
},
{
"cell_type": "code",
"source": [
"x = 3\n",
"if x > 1 and x < 2:\n",
" y = 2\n",
"elif x > 2 and x < 4:\n",
" y = 4\n",
"else:\n",
" y = 0\n",
"print(y)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "B2qxn9woGaFr",
"outputId": "4429e3a5-5c4d-4f28-bec3-6e8f4554473d"
},
"execution_count": 23,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"4\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"x = 3\n",
"if 1 < x < 2:\n",
" y = 2\n",
"elif 2 < x < 4:\n",
" y = 4\n",
"else:\n",
" y = 0\n",
"print(y)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "UyzUmYIiGruF",
"outputId": "0e9b30af-d1d6-4a48-8cfd-b6dc9a0aef73"
},
"execution_count": 24,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"4\n"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment