├── README.md ├── bonus.ipynb ├── challange.ipynb ├── excercise1.ipynb ├── excercise2.ipynb └── main.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # session-3-python -------------------------------------------------------------------------------- /bonus.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Calculator Simulator" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Create three numeric variables" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": { 21 | "vscode": { 22 | "languageId": "plaintext" 23 | } 24 | }, 25 | "outputs": [], 26 | "source": [] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "### Take as input from the user the following sequence: variable 1, operator, variable 2, =." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": { 39 | "vscode": { 40 | "languageId": "plaintext" 41 | } 42 | }, 43 | "outputs": [], 44 | "source": [] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "### This would simulate using a real calculator. Accumulate the result in variable 3." 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": { 57 | "vscode": { 58 | "languageId": "plaintext" 59 | } 60 | }, 61 | "outputs": [], 62 | "source": [] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "### Accumulative calculations can be added to the existing value in variable 3" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": { 75 | "vscode": { 76 | "languageId": "plaintext" 77 | } 78 | }, 79 | "outputs": [], 80 | "source": [] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "### Calculated value can be reset by clicking on ^C to reset variable 3 to zero" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": { 93 | "vscode": { 94 | "languageId": "plaintext" 95 | } 96 | }, 97 | "outputs": [], 98 | "source": [] 99 | } 100 | ], 101 | "metadata": { 102 | "language_info": { 103 | "name": "python" 104 | } 105 | }, 106 | "nbformat": 4, 107 | "nbformat_minor": 2 108 | } 109 | -------------------------------------------------------------------------------- /challange.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Challange" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [] 14 | } 15 | ], 16 | "metadata": { 17 | "language_info": { 18 | "name": "python" 19 | } 20 | }, 21 | "nbformat": 4, 22 | "nbformat_minor": 2 23 | } 24 | -------------------------------------------------------------------------------- /excercise1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Excercise 1" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Write a program that takes an input number and checks whether it's a multiple of 3, 5, or both.\n", 15 | "If it's a multiple of both, print \"Divisible by both 3 and 5\", if it's only a multiple of 3, print\n", 16 | "\"Divisible by 3\", if it's only a multiple of 5, print \"Divisible by 5\".\n", 17 | "If it's not a multiple of either, print \"Not divisible by 3 or 5\"." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": null, 23 | "metadata": { 24 | "vscode": { 25 | "languageId": "plaintext" 26 | } 27 | }, 28 | "outputs": [], 29 | "source": [] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "Create a program that prompts the user to enter a character and checks if it's a vowel (a, e, i, o, u), a consonant, or neither." 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": { 42 | "vscode": { 43 | "languageId": "plaintext" 44 | } 45 | }, 46 | "outputs": [], 47 | "source": [] 48 | } 49 | ], 50 | "metadata": { 51 | "language_info": { 52 | "name": "python" 53 | } 54 | }, 55 | "nbformat": 4, 56 | "nbformat_minor": 2 57 | } 58 | -------------------------------------------------------------------------------- /excercise2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Excercise 2" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Create a list of 12 random integers" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": { 21 | "vscode": { 22 | "languageId": "plaintext" 23 | } 24 | }, 25 | "outputs": [], 26 | "source": [] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "### Loop over numbers and check if each number is either even or odd" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": { 39 | "vscode": { 40 | "languageId": "plaintext" 41 | } 42 | }, 43 | "outputs": [], 44 | "source": [] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "### Check if the number is positive or negative" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": { 57 | "vscode": { 58 | "languageId": "plaintext" 59 | } 60 | }, 61 | "outputs": [], 62 | "source": [] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "### Check if the number is a specific number in mind" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": { 75 | "vscode": { 76 | "languageId": "plaintext" 77 | } 78 | }, 79 | "outputs": [], 80 | "source": [] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | "### Print different outputs for each exercise depending on the if condition" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": { 93 | "vscode": { 94 | "languageId": "plaintext" 95 | } 96 | }, 97 | "outputs": [], 98 | "source": [] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "### run arithmetic operations on numbers for certain conditions and print them" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": { 111 | "vscode": { 112 | "languageId": "plaintext" 113 | } 114 | }, 115 | "outputs": [], 116 | "source": [] 117 | } 118 | ], 119 | "metadata": { 120 | "language_info": { 121 | "name": "python" 122 | } 123 | }, 124 | "nbformat": 4, 125 | "nbformat_minor": 2 126 | } 127 | -------------------------------------------------------------------------------- /main.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# module\n", 8 | "the module operator % is used to get the remainder of a division" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "# 1, 5 is divided by 2 and the remainder is 1\n", 18 | "# 5 = 2 * 2 + 1\n", 19 | "print(5 % 2) # the remainder is one because it's an odd number" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": 1, 25 | "metadata": {}, 26 | "outputs": [ 27 | { 28 | "name": "stdout", 29 | "output_type": "stream", 30 | "text": [ 31 | "0\n" 32 | ] 33 | } 34 | ], 35 | "source": [ 36 | "# 2, 6 is divided by 2 and the remainder is 0\n", 37 | "# 6 = 2 * 3\n", 38 | "print(6 % 2) # the remainder is zero because it's an even number" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "so we can use the modulo operator to check if a number is even or odd" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "name": "stdout", 55 | "output_type": "stream", 56 | "text": [ 57 | "False\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "is_even = 5 % 2 == 0\n", 63 | "print(is_even)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "True\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "is_odd = 5 % 2 != 0\n", 81 | "print(is_odd)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "## Prime Numbers\n", 89 | "\n", 90 | "a prime number is a number that is divisible by 1 and itself" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 4, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "True\n", 103 | "True\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "# 2 is a prime number because it is divisible by 1 and 2 only\n", 109 | "# remember that when a number1 is divisable by another number2\n", 110 | "# then number1 = number2 * something\n", 111 | "# and number1 % number2 = 0\n", 112 | "print(2 % 1 == 0)\n", 113 | "print(2 % 2 == 0)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 5, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "True\n", 126 | "False\n", 127 | "True\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "# 3 is a prime number because it is divisible by 1, and 3 only\n", 133 | "print(3 % 1 == 0)\n", 134 | "print(3 % 2 == 0)\n", 135 | "print(3 % 3 == 0)" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 6, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "name": "stdout", 145 | "output_type": "stream", 146 | "text": [ 147 | "2\n", 148 | "4\n", 149 | "6\n", 150 | "8\n", 151 | "10\n" 152 | ] 153 | } 154 | ], 155 | "source": [ 156 | "# what's the expected output?\n", 157 | "for i in range(2, 11, 2):\n", 158 | " print(i)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 7, 164 | "metadata": {}, 165 | "outputs": [ 166 | { 167 | "name": "stdout", 168 | "output_type": "stream", 169 | "text": [ 170 | "1 is odd.\n", 171 | "2 is even.\n", 172 | "3 is odd.\n", 173 | "4 is even.\n", 174 | "5 is odd.\n", 175 | "6 is even.\n", 176 | "7 is odd.\n", 177 | "8 is even.\n", 178 | "9 is odd.\n", 179 | "10 is even.\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "# Write a piece of code that stars from a certain point to the\n", 185 | "# end of it, and identify in a print statement if a number is even or odd\n", 186 | "start = 1\n", 187 | "end = 10\n", 188 | "for num in range(start, end + 1):\n", 189 | " if num % 2 == 0:\n", 190 | " print(f\"{num} is even.\")\n", 191 | " else:\n", 192 | " print(f\"{num} is odd.\")" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [] 201 | } 202 | ], 203 | "metadata": { 204 | "kernelspec": { 205 | "display_name": "Python 3", 206 | "language": "python", 207 | "name": "python3" 208 | }, 209 | "language_info": { 210 | "codemirror_mode": { 211 | "name": "ipython", 212 | "version": 3 213 | }, 214 | "file_extension": ".py", 215 | "mimetype": "text/x-python", 216 | "name": "python", 217 | "nbconvert_exporter": "python", 218 | "pygments_lexer": "ipython3", 219 | "version": "3.12.1" 220 | } 221 | }, 222 | "nbformat": 4, 223 | "nbformat_minor": 2 224 | } 225 | --------------------------------------------------------------------------------