├── Classes.ipynb ├── Conditions and Loops.ipynb ├── Data Types.ipynb ├── Files and Error Handling.ipynb ├── Functions.ipynb ├── Math Operations.ipynb ├── Modules and Packages.ipynb ├── Python Basics.ipynb ├── Variables.ipynb └── helpers.py /Classes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 5. Classes" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 11, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "# Classes as boilerplates for objects\n", 17 | "class Person():\n", 18 | " # The method that runs as soon as you create a class - initialise\n", 19 | " def __init__(self, name, age, color):\n", 20 | " # Create some attributes for our person class\n", 21 | " self.name = name \n", 22 | " self.age = age\n", 23 | " self.color = color\n", 24 | " \n", 25 | " # Date of birth method\n", 26 | " def year_of_birth(self):\n", 27 | " return 2021-self.age\n", 28 | " \n", 29 | " # Projected age \n", 30 | " def project_age(self, years=5):\n", 31 | " return self.age+years" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 12, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "new_person = Person('Elon Musk', 38, 'blue')" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 19, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "data": { 50 | "text/plain": [ 51 | "38" 52 | ] 53 | }, 54 | "execution_count": 19, 55 | "metadata": {}, 56 | "output_type": "execute_result" 57 | } 58 | ], 59 | "source": [ 60 | "# Accessing a class attribute\n", 61 | "new_person.age" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 14, 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "data": { 71 | "text/plain": [ 72 | "1983" 73 | ] 74 | }, 75 | "execution_count": 14, 76 | "metadata": {}, 77 | "output_type": "execute_result" 78 | } 79 | ], 80 | "source": [ 81 | "# Run a method\n", 82 | "new_person.year_of_birth()" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 17, 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "data": { 92 | "text/plain": [ 93 | "48" 94 | ] 95 | }, 96 | "execution_count": 17, 97 | "metadata": {}, 98 | "output_type": "execute_result" 99 | } 100 | ], 101 | "source": [ 102 | "# Run a method with a keyword argument\n", 103 | "new_person.project_age(years=10)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "# 6. Inheritance\n", 111 | "- PARENT is the class passing down attributes and methods = PERSON\n", 112 | "- CHILD is the class inheriting the methods and attributes = ASTRONAUT" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 34, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "# Create a child class\n", 122 | "class Astronaut(Person):\n", 123 | " \n", 124 | " # Define initialization function\n", 125 | " def __init__(self, name, age, color, mission_length_in_months):\n", 126 | " \n", 127 | " # This is what gives us inheritance - SUPER METHOD\n", 128 | " super().__init__(name, age, color)\n", 129 | " self.mission_length_months = mission_length_in_months\n", 130 | " \n", 131 | " # Method for calculating age on return\n", 132 | " def age_on_return(self):\n", 133 | " return self.project_age(years=int(self.mission_length_months/12))" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 35, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "new_astronaut = Astronaut('Nick', 99, 'purple', 48)" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 36, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "data": { 152 | "text/plain": [ 153 | "'purple'" 154 | ] 155 | }, 156 | "execution_count": 36, 157 | "metadata": {}, 158 | "output_type": "execute_result" 159 | } 160 | ], 161 | "source": [ 162 | "# Access parent like attribute \n", 163 | "new_astronaut.color" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 39, 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "data": { 173 | "text/plain": [ 174 | "1922" 175 | ] 176 | }, 177 | "execution_count": 39, 178 | "metadata": {}, 179 | "output_type": "execute_result" 180 | } 181 | ], 182 | "source": [ 183 | "# Access the methods\n", 184 | "new_astronaut.year_of_birth()" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 38, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "data": { 194 | "text/plain": [ 195 | "103" 196 | ] 197 | }, 198 | "execution_count": 38, 199 | "metadata": {}, 200 | "output_type": "execute_result" 201 | } 202 | ], 203 | "source": [ 204 | "# Run a method\n", 205 | "new_astronaut.age_on_return()" 206 | ] 207 | } 208 | ], 209 | "metadata": { 210 | "kernelspec": { 211 | "display_name": "Python 3", 212 | "language": "python", 213 | "name": "python3" 214 | }, 215 | "language_info": { 216 | "codemirror_mode": { 217 | "name": "ipython", 218 | "version": 3 219 | }, 220 | "file_extension": ".py", 221 | "mimetype": "text/x-python", 222 | "name": "python", 223 | "nbconvert_exporter": "python", 224 | "pygments_lexer": "ipython3", 225 | "version": "3.7.4" 226 | } 227 | }, 228 | "nbformat": 4, 229 | "nbformat_minor": 5 230 | } 231 | -------------------------------------------------------------------------------- /Conditions and Loops.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 4. Conditions and Logic" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 4, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "Sup not Neil\n" 20 | ] 21 | } 22 | ], 23 | "source": [ 24 | "# Applying logic using the IF statement\n", 25 | "name = 'Nick'\n", 26 | "if name == 'Neil Armstrong':\n", 27 | " print('Sup not Neil')" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 15, 33 | "metadata": {}, 34 | "outputs": [ 35 | { 36 | "name": "stdout", 37 | "output_type": "stream", 38 | "text": [ 39 | "False\n" 40 | ] 41 | } 42 | ], 43 | "source": [ 44 | "probability = 0.1\n", 45 | "# Probability is greater than 0.5\n", 46 | "if probability >= 0.5:\n", 47 | " print(True)\n", 48 | " \n", 49 | "# Print out a statement is probability is below\n", 50 | "elif probability < 0: \n", 51 | " print('Check yo probabilities')\n", 52 | " \n", 53 | "# Anything else\n", 54 | "else: \n", 55 | " print(False)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 23, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "Elon's here\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "# Create a list of names\n", 73 | "names = ['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk'] \n", 74 | "if 'elon musk' in names:\n", 75 | " # Using Python escapes\n", 76 | " print(\"Elon\\'s here\")" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "# 5. Loops" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 34, 89 | "metadata": {}, 90 | "outputs": [ 91 | { 92 | "name": "stdout", 93 | "output_type": "stream", 94 | "text": [ 95 | "neil armstrong\n", 96 | "Pleased to have you here!\n", 97 | "\n", 98 | "buzz aldrin\n", 99 | "Sup buzz \n", 100 | "\n", 101 | "sally ride\n", 102 | "Pleased to have you here!\n", 103 | "\n", 104 | "yuri gagarin\n", 105 | "Hey yuri!\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "# This is an example of a For loop\n", 111 | "for name in names:\n", 112 | " print(name)\n", 113 | " \n", 114 | " # Condition statement block\n", 115 | " if name == 'buzz aldrin':\n", 116 | " print('Sup buzz \\n')\n", 117 | " # Next value in the loop\n", 118 | " continue\n", 119 | " \n", 120 | " elif name == 'yuri gagarin':\n", 121 | " print('Hey yuri!')\n", 122 | " # Break statement stops the loop\n", 123 | " break\n", 124 | " \n", 125 | " # Catch all \n", 126 | " else:\n", 127 | " # Placeholder to do nothing\n", 128 | " pass\n", 129 | " \n", 130 | " # Outside of if statement block\n", 131 | " print('Pleased to have you here!\\n')" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 37, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "1\n", 144 | "2\n", 145 | "3\n", 146 | "4\n", 147 | "5\n", 148 | "6\n", 149 | "7\n", 150 | "8\n", 151 | "9\n", 152 | "10\n" 153 | ] 154 | } 155 | ], 156 | "source": [ 157 | "# Loop x number of times\n", 158 | "for idx in range(1,11):\n", 159 | " print(idx)" 160 | ] 161 | }, 162 | { 163 | "cell_type": "code", 164 | "execution_count": 41, 165 | "metadata": {}, 166 | "outputs": [ 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "Shuttle 1 launched\n", 172 | "Shuttle 2 launched\n", 173 | "Shuttle 3 launched\n", 174 | "Shuttle 4 launched\n", 175 | "Shuttle 5 launched\n", 176 | "Shuttle 6 launched\n", 177 | "Shuttle 7 launched\n", 178 | "Shuttle 8 launched\n", 179 | "Shuttle 9 launched\n", 180 | "Shuttle 10 launched\n", 181 | "All shuttles launched\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "# Create launch variables\n", 187 | "launched_shuttles = 0 \n", 188 | "total_shuttles = 10 \n", 189 | "\n", 190 | "# Create a while loop\n", 191 | "while True:\n", 192 | " # STRING FORMATTING\n", 193 | " print('Shuttle {} launched'.format(launched_shuttles+1))\n", 194 | " launched_shuttles += 1\n", 195 | "\n", 196 | " if launched_shuttles == total_shuttles:\n", 197 | " print('All shuttles launched')\n", 198 | " break " 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 42, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "astronaut = {\n", 208 | " \"name\":\"Elon Musk\", \n", 209 | " \"suit_size\": \"Medium\", \n", 210 | " \"allergies\":\"peanuts\"\n", 211 | "}" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 44, 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "data": { 221 | "text/plain": [ 222 | "dict_keys(['name', 'suit_size', 'allergies'])" 223 | ] 224 | }, 225 | "execution_count": 44, 226 | "metadata": {}, 227 | "output_type": "execute_result" 228 | } 229 | ], 230 | "source": [ 231 | "# Accessing dictionary keys\n", 232 | "astronaut.keys()" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 55, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "name\n", 245 | "suit_size\n", 246 | "allergies\n" 247 | ] 248 | } 249 | ], 250 | "source": [ 251 | "# Loop through keys in a dictionary\n", 252 | "for key in astronaut.keys(): \n", 253 | " print(key)" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": 46, 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "data": { 263 | "text/plain": [ 264 | "dict_values(['Elon Musk', 'Medium', 'peanuts'])" 265 | ] 266 | }, 267 | "execution_count": 46, 268 | "metadata": {}, 269 | "output_type": "execute_result" 270 | } 271 | ], 272 | "source": [ 273 | "# Accessing dictionary values\n", 274 | "astronaut.values()" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 49, 280 | "metadata": {}, 281 | "outputs": [ 282 | { 283 | "name": "stdout", 284 | "output_type": "stream", 285 | "text": [ 286 | "Elon Musk\n", 287 | "Medium\n", 288 | "peanuts\n" 289 | ] 290 | } 291 | ], 292 | "source": [ 293 | "# Loop through values in a dictionary\n", 294 | "for value in astronaut.values():\n", 295 | " print(value)" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": 50, 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "data": { 305 | "text/plain": [ 306 | "dict_items([('name', 'Elon Musk'), ('suit_size', 'Medium'), ('allergies', 'peanuts')])" 307 | ] 308 | }, 309 | "execution_count": 50, 310 | "metadata": {}, 311 | "output_type": "execute_result" 312 | } 313 | ], 314 | "source": [ 315 | "astronaut.items()" 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 53, 321 | "metadata": {}, 322 | "outputs": [ 323 | { 324 | "name": "stdout", 325 | "output_type": "stream", 326 | "text": [ 327 | "name\n", 328 | "Elon Musk \n", 329 | "\n", 330 | "suit_size\n", 331 | "Medium \n", 332 | "\n", 333 | "allergies\n", 334 | "peanuts \n", 335 | "\n" 336 | ] 337 | } 338 | ], 339 | "source": [ 340 | "# Loop through keys and values at the same time \n", 341 | "for key, value in astronaut.items():\n", 342 | " print(key)\n", 343 | " print(value, '\\n')" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 56, 349 | "metadata": {}, 350 | "outputs": [], 351 | "source": [ 352 | "# List comprehension\n", 353 | "new_list = [name.title() for name in names]" 354 | ] 355 | }, 356 | { 357 | "cell_type": "code", 358 | "execution_count": 57, 359 | "metadata": {}, 360 | "outputs": [ 361 | { 362 | "data": { 363 | "text/plain": [ 364 | "['Neil Armstrong', 'Buzz Aldrin', 'Sally Ride', 'Yuri Gagarin', 'Elon Musk']" 365 | ] 366 | }, 367 | "execution_count": 57, 368 | "metadata": {}, 369 | "output_type": "execute_result" 370 | } 371 | ], 372 | "source": [ 373 | "new_list" 374 | ] 375 | }, 376 | { 377 | "cell_type": "code", 378 | "execution_count": 58, 379 | "metadata": {}, 380 | "outputs": [ 381 | { 382 | "data": { 383 | "text/plain": [ 384 | "['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 385 | ] 386 | }, 387 | "execution_count": 58, 388 | "metadata": {}, 389 | "output_type": "execute_result" 390 | } 391 | ], 392 | "source": [ 393 | "names" 394 | ] 395 | } 396 | ], 397 | "metadata": { 398 | "kernelspec": { 399 | "display_name": "Python 3", 400 | "language": "python", 401 | "name": "python3" 402 | }, 403 | "language_info": { 404 | "codemirror_mode": { 405 | "name": "ipython", 406 | "version": 3 407 | }, 408 | "file_extension": ".py", 409 | "mimetype": "text/x-python", 410 | "name": "python", 411 | "nbconvert_exporter": "python", 412 | "pygments_lexer": "ipython3", 413 | "version": "3.7.4" 414 | } 415 | }, 416 | "nbformat": 4, 417 | "nbformat_minor": 5 418 | } 419 | -------------------------------------------------------------------------------- /Data Types.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 1. Data Types" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 16, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "pluto\n" 20 | ] 21 | } 22 | ], 23 | "source": [ 24 | "# This is declaring a variable as a STRING \n", 25 | "string_variable = 'pluto'\n", 26 | "print(string_variable)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 17, 32 | "metadata": {}, 33 | "outputs": [ 34 | { 35 | "data": { 36 | "text/plain": [ 37 | "str" 38 | ] 39 | }, 40 | "execution_count": 17, 41 | "metadata": {}, 42 | "output_type": "execute_result" 43 | } 44 | ], 45 | "source": [ 46 | "type(string_variable)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 19, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "data": { 56 | "text/plain": [ 57 | "int" 58 | ] 59 | }, 60 | "execution_count": 19, 61 | "metadata": {}, 62 | "output_type": "execute_result" 63 | } 64 | ], 65 | "source": [ 66 | "# This is declaring a variable as an Integer\n", 67 | "integer_variable = 123852\n", 68 | "type(integer_variable)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 21, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "data": { 78 | "text/plain": [ 79 | "123862" 80 | ] 81 | }, 82 | "execution_count": 21, 83 | "metadata": {}, 84 | "output_type": "execute_result" 85 | } 86 | ], 87 | "source": [ 88 | "integer_variable + 10" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": 23, 94 | "metadata": {}, 95 | "outputs": [ 96 | { 97 | "data": { 98 | "text/plain": [ 99 | "float" 100 | ] 101 | }, 102 | "execution_count": 23, 103 | "metadata": {}, 104 | "output_type": "execute_result" 105 | } 106 | ], 107 | "source": [ 108 | "# This is declaring a variable as a Float\n", 109 | "float_variable = 128.126\n", 110 | "type(float_variable)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 28, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "data": { 120 | "text/plain": [ 121 | "bool" 122 | ] 123 | }, 124 | "execution_count": 28, 125 | "metadata": {}, 126 | "output_type": "execute_result" 127 | } 128 | ], 129 | "source": [ 130 | "# This is assigning a Boolean value to a variable\n", 131 | "bool_variable = bool(0)\n", 132 | "type(bool_variable)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 29, 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "data": { 142 | "text/plain": [ 143 | "False" 144 | ] 145 | }, 146 | "execution_count": 29, 147 | "metadata": {}, 148 | "output_type": "execute_result" 149 | } 150 | ], 151 | "source": [ 152 | "bool_variable" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 57, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "data": { 162 | "text/plain": [ 163 | "list" 164 | ] 165 | }, 166 | "execution_count": 57, 167 | "metadata": {}, 168 | "output_type": "execute_result" 169 | } 170 | ], 171 | "source": [ 172 | "# This is creating a list variable\n", 173 | "list_variable = [1, 2, 3, 123.44, 85.4, 22.1, 1,2,3,1,2,3]\n", 174 | "type(list_variable)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": 44, 180 | "metadata": {}, 181 | "outputs": [], 182 | "source": [ 183 | "list_variable[5] = 123" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 58, 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "data": { 193 | "text/plain": [ 194 | "[1, 2, 3, 123.44, 85.4, 22.1, 1, 2, 3, 1, 2, 3]" 195 | ] 196 | }, 197 | "execution_count": 58, 198 | "metadata": {}, 199 | "output_type": "execute_result" 200 | } 201 | ], 202 | "source": [ 203 | "list_variable" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 54, 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "data": { 213 | "text/plain": [ 214 | "tuple" 215 | ] 216 | }, 217 | "execution_count": 54, 218 | "metadata": {}, 219 | "output_type": "execute_result" 220 | } 221 | ], 222 | "source": [ 223 | "# Create a TUPLE variable, IMMUTABLE = you can't change the values\n", 224 | "tuple_variable = (1, 2, 3, 123.44, 85.4, 22.1, 3)\n", 225 | "type(tuple_variable)" 226 | ] 227 | }, 228 | { 229 | "cell_type": "code", 230 | "execution_count": 56, 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "data": { 235 | "text/plain": [ 236 | "(1, 2, 3, 123.44, 85.4, 22.1, 3)" 237 | ] 238 | }, 239 | "execution_count": 56, 240 | "metadata": {}, 241 | "output_type": "execute_result" 242 | } 243 | ], 244 | "source": [ 245 | "tuple_variable" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 52, 251 | "metadata": {}, 252 | "outputs": [ 253 | { 254 | "data": { 255 | "text/plain": [ 256 | "set" 257 | ] 258 | }, 259 | "execution_count": 52, 260 | "metadata": {}, 261 | "output_type": "execute_result" 262 | } 263 | ], 264 | "source": [ 265 | "# This is creating a SET variable, IMMUTABLE = you can't change the values, No DUPLICATES!\n", 266 | "set_variable = {1, 2, 3, 123.44, 85.4, 22.1, 3}\n", 267 | "type(set_variable)" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 63, 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "data": { 277 | "text/plain": [ 278 | "list" 279 | ] 280 | }, 281 | "execution_count": 63, 282 | "metadata": {}, 283 | "output_type": "execute_result" 284 | } 285 | ], 286 | "source": [ 287 | "# Type casting list to set back to list to get rid of duplicates\n", 288 | "type(list(set(list_variable)))" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 67, 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/plain": [ 299 | "dict" 300 | ] 301 | }, 302 | "execution_count": 67, 303 | "metadata": {}, 304 | "output_type": "execute_result" 305 | } 306 | ], 307 | "source": [ 308 | "# Defining a dictionary variable\n", 309 | "person_variable = {'name':\"Nicholas\", 'favourite_color':'red', 'favourite_number':20}\n", 310 | "type(dict_variable)" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": 71, 316 | "metadata": {}, 317 | "outputs": [ 318 | { 319 | "data": { 320 | "text/plain": [ 321 | "20" 322 | ] 323 | }, 324 | "execution_count": 71, 325 | "metadata": {}, 326 | "output_type": "execute_result" 327 | } 328 | ], 329 | "source": [ 330 | "person_variable['favourite_number']" 331 | ] 332 | }, 333 | { 334 | "cell_type": "code", 335 | "execution_count": 72, 336 | "metadata": {}, 337 | "outputs": [], 338 | "source": [ 339 | "fit_models = {}" 340 | ] 341 | }, 342 | { 343 | "cell_type": "code", 344 | "execution_count": 73, 345 | "metadata": {}, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "(1, 2, 3, 123.44, 85.4, 22.1, 1, 2, 3, 1, 2, 3)" 351 | ] 352 | }, 353 | "execution_count": 73, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "tuple(list_variable)" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "metadata": {}, 365 | "source": [ 366 | "# 2. Lists" 367 | ] 368 | }, 369 | { 370 | "cell_type": "code", 371 | "execution_count": 74, 372 | "metadata": {}, 373 | "outputs": [], 374 | "source": [ 375 | "# Create\n", 376 | "names = ['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": 75, 382 | "metadata": {}, 383 | "outputs": [ 384 | { 385 | "data": { 386 | "text/plain": [ 387 | "['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 388 | ] 389 | }, 390 | "execution_count": 75, 391 | "metadata": {}, 392 | "output_type": "execute_result" 393 | } 394 | ], 395 | "source": [ 396 | "# Read \n", 397 | "names" 398 | ] 399 | }, 400 | { 401 | "cell_type": "code", 402 | "execution_count": 77, 403 | "metadata": {}, 404 | "outputs": [ 405 | { 406 | "data": { 407 | "text/plain": [ 408 | "'neil armstrong'" 409 | ] 410 | }, 411 | "execution_count": 77, 412 | "metadata": {}, 413 | "output_type": "execute_result" 414 | } 415 | ], 416 | "source": [ 417 | "# Reading using Indexing\n", 418 | "names[0]" 419 | ] 420 | }, 421 | { 422 | "cell_type": "code", 423 | "execution_count": 78, 424 | "metadata": {}, 425 | "outputs": [ 426 | { 427 | "data": { 428 | "text/plain": [ 429 | "'elon musk'" 430 | ] 431 | }, 432 | "execution_count": 78, 433 | "metadata": {}, 434 | "output_type": "execute_result" 435 | } 436 | ], 437 | "source": [ 438 | "names[-1]" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 79, 444 | "metadata": {}, 445 | "outputs": [ 446 | { 447 | "data": { 448 | "text/plain": [ 449 | "5" 450 | ] 451 | }, 452 | "execution_count": 79, 453 | "metadata": {}, 454 | "output_type": "execute_result" 455 | } 456 | ], 457 | "source": [ 458 | "len(names)" 459 | ] 460 | }, 461 | { 462 | "cell_type": "code", 463 | "execution_count": null, 464 | "metadata": {}, 465 | "outputs": [], 466 | "source": [ 467 | "# Update" 468 | ] 469 | }, 470 | { 471 | "cell_type": "code", 472 | "execution_count": 80, 473 | "metadata": {}, 474 | "outputs": [ 475 | { 476 | "data": { 477 | "text/plain": [ 478 | "['neil armstrong',\n", 479 | " 'buzz aldrin',\n", 480 | " 'sally ride',\n", 481 | " 'yuri gagarin',\n", 482 | " 'nicholas renotte']" 483 | ] 484 | }, 485 | "execution_count": 80, 486 | "metadata": {}, 487 | "output_type": "execute_result" 488 | } 489 | ], 490 | "source": [ 491 | "names[-1] = 'nicholas renotte'\n", 492 | "names" 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": 81, 498 | "metadata": {}, 499 | "outputs": [], 500 | "source": [ 501 | "names.append('elon musk')" 502 | ] 503 | }, 504 | { 505 | "cell_type": "code", 506 | "execution_count": 82, 507 | "metadata": {}, 508 | "outputs": [ 509 | { 510 | "data": { 511 | "text/plain": [ 512 | "['neil armstrong',\n", 513 | " 'buzz aldrin',\n", 514 | " 'sally ride',\n", 515 | " 'yuri gagarin',\n", 516 | " 'nicholas renotte',\n", 517 | " 'elon musk']" 518 | ] 519 | }, 520 | "execution_count": 82, 521 | "metadata": {}, 522 | "output_type": "execute_result" 523 | } 524 | ], 525 | "source": [ 526 | "names" 527 | ] 528 | }, 529 | { 530 | "cell_type": "code", 531 | "execution_count": 84, 532 | "metadata": {}, 533 | "outputs": [], 534 | "source": [ 535 | "names.insert(0, 'richard branson')" 536 | ] 537 | }, 538 | { 539 | "cell_type": "code", 540 | "execution_count": 85, 541 | "metadata": {}, 542 | "outputs": [ 543 | { 544 | "data": { 545 | "text/plain": [ 546 | "['richard branson',\n", 547 | " 'neil armstrong',\n", 548 | " 'buzz aldrin',\n", 549 | " 'sally ride',\n", 550 | " 'yuri gagarin',\n", 551 | " 'nicholas renotte',\n", 552 | " 'elon musk']" 553 | ] 554 | }, 555 | "execution_count": 85, 556 | "metadata": {}, 557 | "output_type": "execute_result" 558 | } 559 | ], 560 | "source": [ 561 | "names" 562 | ] 563 | }, 564 | { 565 | "cell_type": "code", 566 | "execution_count": null, 567 | "metadata": {}, 568 | "outputs": [], 569 | "source": [ 570 | "# Delete" 571 | ] 572 | }, 573 | { 574 | "cell_type": "code", 575 | "execution_count": 87, 576 | "metadata": {}, 577 | "outputs": [], 578 | "source": [ 579 | "del names[-2]" 580 | ] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "execution_count": 88, 585 | "metadata": {}, 586 | "outputs": [ 587 | { 588 | "data": { 589 | "text/plain": [ 590 | "['richard branson',\n", 591 | " 'neil armstrong',\n", 592 | " 'buzz aldrin',\n", 593 | " 'sally ride',\n", 594 | " 'yuri gagarin',\n", 595 | " 'elon musk']" 596 | ] 597 | }, 598 | "execution_count": 88, 599 | "metadata": {}, 600 | "output_type": "execute_result" 601 | } 602 | ], 603 | "source": [ 604 | "names" 605 | ] 606 | }, 607 | { 608 | "cell_type": "markdown", 609 | "metadata": {}, 610 | "source": [ 611 | "# 3. Dictionaries" 612 | ] 613 | }, 614 | { 615 | "cell_type": "code", 616 | "execution_count": 91, 617 | "metadata": {}, 618 | "outputs": [], 619 | "source": [ 620 | "# Create\n", 621 | "astronaut = {\n", 622 | " \"name\":\"elon musk\", \n", 623 | " \"suit_size\":\"large\", \n", 624 | " \"allergies\":\"peanuts\"\n", 625 | "}" 626 | ] 627 | }, 628 | { 629 | "cell_type": "code", 630 | "execution_count": null, 631 | "metadata": {}, 632 | "outputs": [], 633 | "source": [ 634 | "# Read" 635 | ] 636 | }, 637 | { 638 | "cell_type": "code", 639 | "execution_count": 92, 640 | "metadata": {}, 641 | "outputs": [ 642 | { 643 | "data": { 644 | "text/plain": [ 645 | "{'name': 'elon musk', 'suit_size': 'large', 'allergies': 'peanuts'}" 646 | ] 647 | }, 648 | "execution_count": 92, 649 | "metadata": {}, 650 | "output_type": "execute_result" 651 | } 652 | ], 653 | "source": [ 654 | "astronaut" 655 | ] 656 | }, 657 | { 658 | "cell_type": "code", 659 | "execution_count": 97, 660 | "metadata": {}, 661 | "outputs": [ 662 | { 663 | "data": { 664 | "text/plain": [ 665 | "'large'" 666 | ] 667 | }, 668 | "execution_count": 97, 669 | "metadata": {}, 670 | "output_type": "execute_result" 671 | } 672 | ], 673 | "source": [ 674 | "astronaut['suit_size']" 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "execution_count": 102, 680 | "metadata": {}, 681 | "outputs": [ 682 | { 683 | "data": { 684 | "text/plain": [ 685 | "dict_keys(['name', 'suit_size', 'allergies'])" 686 | ] 687 | }, 688 | "execution_count": 102, 689 | "metadata": {}, 690 | "output_type": "execute_result" 691 | } 692 | ], 693 | "source": [ 694 | "astronaut.keys()" 695 | ] 696 | }, 697 | { 698 | "cell_type": "code", 699 | "execution_count": 103, 700 | "metadata": {}, 701 | "outputs": [ 702 | { 703 | "data": { 704 | "text/plain": [ 705 | "dict_values(['elon musk', 'large', 'peanuts'])" 706 | ] 707 | }, 708 | "execution_count": 103, 709 | "metadata": {}, 710 | "output_type": "execute_result" 711 | } 712 | ], 713 | "source": [ 714 | "astronaut.values()" 715 | ] 716 | }, 717 | { 718 | "cell_type": "code", 719 | "execution_count": 89, 720 | "metadata": {}, 721 | "outputs": [], 722 | "source": [ 723 | "# Update" 724 | ] 725 | }, 726 | { 727 | "cell_type": "code", 728 | "execution_count": 105, 729 | "metadata": {}, 730 | "outputs": [], 731 | "source": [ 732 | "astronaut['allergies'] = 'mango'" 733 | ] 734 | }, 735 | { 736 | "cell_type": "code", 737 | "execution_count": 106, 738 | "metadata": {}, 739 | "outputs": [ 740 | { 741 | "data": { 742 | "text/plain": [ 743 | "{'name': 'elon musk', 'suit_size': 'large', 'allergies': 'mango'}" 744 | ] 745 | }, 746 | "execution_count": 106, 747 | "metadata": {}, 748 | "output_type": "execute_result" 749 | } 750 | ], 751 | "source": [ 752 | "astronaut" 753 | ] 754 | }, 755 | { 756 | "cell_type": "code", 757 | "execution_count": 107, 758 | "metadata": {}, 759 | "outputs": [], 760 | "source": [ 761 | "astronaut['space_ship'] = 'Galactic 1'" 762 | ] 763 | }, 764 | { 765 | "cell_type": "code", 766 | "execution_count": 108, 767 | "metadata": {}, 768 | "outputs": [ 769 | { 770 | "data": { 771 | "text/plain": [ 772 | "{'name': 'elon musk',\n", 773 | " 'suit_size': 'large',\n", 774 | " 'allergies': 'mango',\n", 775 | " 'space_ship': 'Galactic 1'}" 776 | ] 777 | }, 778 | "execution_count": 108, 779 | "metadata": {}, 780 | "output_type": "execute_result" 781 | } 782 | ], 783 | "source": [ 784 | "astronaut" 785 | ] 786 | }, 787 | { 788 | "cell_type": "code", 789 | "execution_count": null, 790 | "metadata": {}, 791 | "outputs": [], 792 | "source": [ 793 | "# Delete" 794 | ] 795 | }, 796 | { 797 | "cell_type": "code", 798 | "execution_count": 109, 799 | "metadata": {}, 800 | "outputs": [], 801 | "source": [ 802 | "del astronaut['space_ship']" 803 | ] 804 | }, 805 | { 806 | "cell_type": "code", 807 | "execution_count": 110, 808 | "metadata": {}, 809 | "outputs": [ 810 | { 811 | "data": { 812 | "text/plain": [ 813 | "{'name': 'elon musk', 'suit_size': 'large', 'allergies': 'mango'}" 814 | ] 815 | }, 816 | "execution_count": 110, 817 | "metadata": {}, 818 | "output_type": "execute_result" 819 | } 820 | ], 821 | "source": [ 822 | "astronaut" 823 | ] 824 | } 825 | ], 826 | "metadata": { 827 | "kernelspec": { 828 | "display_name": "Python 3", 829 | "language": "python", 830 | "name": "python3" 831 | }, 832 | "language_info": { 833 | "codemirror_mode": { 834 | "name": "ipython", 835 | "version": 3 836 | }, 837 | "file_extension": ".py", 838 | "mimetype": "text/x-python", 839 | "name": "python", 840 | "nbconvert_exporter": "python", 841 | "pygments_lexer": "ipython3", 842 | "version": "3.7.4" 843 | } 844 | }, 845 | "nbformat": 4, 846 | "nbformat_minor": 5 847 | } 848 | -------------------------------------------------------------------------------- /Files and Error Handling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Working with Files" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 3, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "# Write out our mission journal \n", 17 | "with open('mission_jounal.txt', 'w') as f:\n", 18 | " f.write(\"It's my first on the space mission. It is verry nice.\")" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 5, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "# Read from journal\n", 28 | "with open('mission_jounal.txt', 'r') as f:\n", 29 | " file = f.read()" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 6, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "It's my first on the space mission. It is verry nice.\n" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "print(file)" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "# Error Handling" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 9, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "# Create a set\n", 63 | "new_set = {1,2,3,4,5,6}" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 16, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "ename": "TypeError", 73 | "evalue": "'set' object does not support item assignment", 74 | "output_type": "error", 75 | "traceback": [ 76 | "\u001b[1;31m-------------------------------------------------------\u001b[0m", 77 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 78 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnew_set\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m4\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 79 | "\u001b[1;31mTypeError\u001b[0m: 'set' object does not support item assignment" 80 | ] 81 | } 82 | ], 83 | "source": [ 84 | "new_set[0] = 4" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 23, 90 | "metadata": {}, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "'set' object does not support item assignment\n", 97 | "Something went wrong with your request.\n" 98 | ] 99 | } 100 | ], 101 | "source": [ 102 | "# Try something using the try keyword\n", 103 | "try: \n", 104 | " # Run a piece of code which may cause an error\n", 105 | " new_set[0] = 4\n", 106 | "\n", 107 | "# If we have an error, this code below will run\n", 108 | "except Exception as e:\n", 109 | " print(e)\n", 110 | " # Print out something that's a little nicer for the user\n", 111 | " print('Something went wrong with your request.')" 112 | ] 113 | } 114 | ], 115 | "metadata": { 116 | "kernelspec": { 117 | "display_name": "Python 3", 118 | "language": "python", 119 | "name": "python3" 120 | }, 121 | "language_info": { 122 | "codemirror_mode": { 123 | "name": "ipython", 124 | "version": 3 125 | }, 126 | "file_extension": ".py", 127 | "mimetype": "text/x-python", 128 | "name": "python", 129 | "nbconvert_exporter": "python", 130 | "pygments_lexer": "ipython3", 131 | "version": "3.7.4" 132 | } 133 | }, 134 | "nbformat": 4, 135 | "nbformat_minor": 5 136 | } 137 | -------------------------------------------------------------------------------- /Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 6. Functions" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 5, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "# Defining a function in Python - Recipe \n", 17 | "def launchpad_welcome():\n", 18 | " print('hello')\n", 19 | " print(1+2)\n", 20 | " print(3+4)" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 18, 26 | "metadata": {}, 27 | "outputs": [ 28 | { 29 | "name": "stdout", 30 | "output_type": "stream", 31 | "text": [ 32 | "hello\n", 33 | "3\n", 34 | "7\n" 35 | ] 36 | } 37 | ], 38 | "source": [ 39 | "# Running our function\n", 40 | "launchpad_welcome()" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 20, 46 | "metadata": {}, 47 | "outputs": [ 48 | { 49 | "name": "stdout", 50 | "output_type": "stream", 51 | "text": [ 52 | "Welcome Elon Musk\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "# String formatting \n", 58 | "print('Welcome {} {}'.format('Elon', 'Musk'))" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 9, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "names = ['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 21, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "# Positional Arguments\n", 77 | "def custom_welcome(name):\n", 78 | " print('Welcome {}'.format(name))" 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 16, 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "Welcome Nick Renotte\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "custom_welcome('Nick Renotte')" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 17, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "Welcome neil armstrong\n", 108 | "Welcome buzz aldrin\n", 109 | "Welcome sally ride\n", 110 | "Welcome yuri gagarin\n", 111 | "Welcome elon musk\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "for name in names:\n", 117 | " custom_welcome(name)" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 22, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "# Multiple positional Arguments - POSITION IS IMPORTANT\n", 127 | "def custom_welcome_to_ship(name, space_ship):\n", 128 | " print('Welcome {} to the {}'.format(name, space_ship))" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 25, 134 | "metadata": {}, 135 | "outputs": [ 136 | { 137 | "name": "stdout", 138 | "output_type": "stream", 139 | "text": [ 140 | "Welcome Nick Renotte to the Galatic 1\n" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "custom_welcome_to_ship('Nick Renotte', 'Galatic 1')" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 33, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "space_ships = ['Galactic 1', 'Galactic 2', 'USS Voyager', 'Maximum Amazin Wow Space Ship', 'Apple iShip']" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 34, 160 | "metadata": {}, 161 | "outputs": [ 162 | { 163 | "name": "stdout", 164 | "output_type": "stream", 165 | "text": [ 166 | "Welcome neil armstrong to the Galactic 1\n", 167 | "Welcome buzz aldrin to the Galactic 2\n", 168 | "Welcome sally ride to the USS Voyager\n", 169 | "Welcome yuri gagarin to the Maximum Amazin Wow Space Ship\n", 170 | "Welcome elon musk to the Apple iShip\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "# Used the enumerate function to get the positional index AND the name\n", 176 | "for idx, name in enumerate(names):\n", 177 | " ship = space_ships[idx]\n", 178 | " custom_welcome_to_ship(name, ship)" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 38, 184 | "metadata": {}, 185 | "outputs": [], 186 | "source": [ 187 | "# This is using keyword arguments\n", 188 | "def space_suit(color='Blue'):\n", 189 | " print('Your space suit is {}'.format(color))" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 37, 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "name": "stdout", 199 | "output_type": "stream", 200 | "text": [ 201 | "Your space suit is Red\n" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "space_suit(color='Red')" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 52, 212 | "metadata": {}, 213 | "outputs": [], 214 | "source": [ 215 | "# Multiple keyword arguments\n", 216 | "def space_suit_welcome(name, space_ship, color='Blue', allergies='None'):\n", 217 | " print('Welcome {} to the {}, your space suit is {}, you have {} allergies'.format(name, space_ship, color, allergies))" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 47, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "name": "stdout", 227 | "output_type": "stream", 228 | "text": [ 229 | "Welcome Elon Musk to the Apple iShip, your space suit is Orange, you have Peanut allergies\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "space_suit_welcome('Elon Musk', 'Apple iShip', allergies='Peanut', color='Orange')" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 53, 240 | "metadata": {}, 241 | "outputs": [], 242 | "source": [ 243 | "# Setup a return statement\n", 244 | "def space_suit_welcome_with_return(name, space_ship, color='Blue', allergies='None'):\n", 245 | " return 'Welcome {} to the {}, your space suit is {}, you have {} allergies'.format(name, space_ship, color, allergies)" 246 | ] 247 | }, 248 | { 249 | "cell_type": "code", 250 | "execution_count": 54, 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [ 254 | "# Example of storing the results of the function inside a variable\n", 255 | "welcome = space_suit_welcome_with_return('Elon Musk', 'Apple iShip')" 256 | ] 257 | }, 258 | { 259 | "cell_type": "code", 260 | "execution_count": 51, 261 | "metadata": {}, 262 | "outputs": [ 263 | { 264 | "name": "stdout", 265 | "output_type": "stream", 266 | "text": [ 267 | "Welcome Elon Musk to the Apple iShip, your space suit is Blue, you have None allergies\n" 268 | ] 269 | } 270 | ], 271 | "source": [ 272 | "print(welcome)" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 58, 278 | "metadata": {}, 279 | "outputs": [], 280 | "source": [ 281 | "# Lambda function - anonymous function\n", 282 | "pi = lambda x: x*3.14" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 59, 288 | "metadata": {}, 289 | "outputs": [], 290 | "source": [ 291 | "return_value = pi(2)" 292 | ] 293 | }, 294 | { 295 | "cell_type": "code", 296 | "execution_count": 60, 297 | "metadata": {}, 298 | "outputs": [ 299 | { 300 | "name": "stdout", 301 | "output_type": "stream", 302 | "text": [ 303 | "6.28\n" 304 | ] 305 | } 306 | ], 307 | "source": [ 308 | "print(return_value)" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 57, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "6.28" 320 | ] 321 | }, 322 | "execution_count": 57, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "3.14*2" 329 | ] 330 | } 331 | ], 332 | "metadata": { 333 | "kernelspec": { 334 | "display_name": "Python 3", 335 | "language": "python", 336 | "name": "python3" 337 | }, 338 | "language_info": { 339 | "codemirror_mode": { 340 | "name": "ipython", 341 | "version": 3 342 | }, 343 | "file_extension": ".py", 344 | "mimetype": "text/x-python", 345 | "name": "python", 346 | "nbconvert_exporter": "python", 347 | "pygments_lexer": "ipython3", 348 | "version": "3.7.4" 349 | } 350 | }, 351 | "nbformat": 4, 352 | "nbformat_minor": 5 353 | } 354 | -------------------------------------------------------------------------------- /Math Operations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 11. Math" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "# Create two variables\n", 17 | "math_value_1 = 1235456\n", 18 | "math_value_2 = 5678914" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": 4, 24 | "metadata": {}, 25 | "outputs": [ 26 | { 27 | "data": { 28 | "text/plain": [ 29 | "6914370" 30 | ] 31 | }, 32 | "execution_count": 4, 33 | "metadata": {}, 34 | "output_type": "execute_result" 35 | } 36 | ], 37 | "source": [ 38 | "# Addition\n", 39 | "math_value_1 + math_value_2" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 5, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "data": { 49 | "text/plain": [ 50 | "-4443458" 51 | ] 52 | }, 53 | "execution_count": 5, 54 | "metadata": {}, 55 | "output_type": "execute_result" 56 | } 57 | ], 58 | "source": [ 59 | "# Subtraction \n", 60 | "math_value_1 - math_value_2 " 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 11, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "data": { 70 | "text/plain": [ 71 | "4.596613719954414" 72 | ] 73 | }, 74 | "execution_count": 11, 75 | "metadata": {}, 76 | "output_type": "execute_result" 77 | } 78 | ], 79 | "source": [ 80 | "# Division\n", 81 | "math_value_2 / math_value_1" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 10, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "4" 93 | ] 94 | }, 95 | "execution_count": 10, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "# Dividing with the Integral Result\n", 102 | "math_value_2 // math_value_1" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 14, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "data": { 112 | "text/plain": [ 113 | "737090" 114 | ] 115 | }, 116 | "execution_count": 14, 117 | "metadata": {}, 118 | "output_type": "execute_result" 119 | } 120 | ], 121 | "source": [ 122 | "# Modulus / Modulo\n", 123 | "math_value_2 % math_value_1" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 13, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "737090" 135 | ] 136 | }, 137 | "execution_count": 13, 138 | "metadata": {}, 139 | "output_type": "execute_result" 140 | } 141 | ], 142 | "source": [ 143 | "math_value_2 - math_value_1*4" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 15, 149 | "metadata": {}, 150 | "outputs": [ 151 | { 152 | "data": { 153 | "text/plain": [ 154 | "7016048374784" 155 | ] 156 | }, 157 | "execution_count": 15, 158 | "metadata": {}, 159 | "output_type": "execute_result" 160 | } 161 | ], 162 | "source": [ 163 | "# Multiplication\n", 164 | "math_value_1 * math_value_2" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 27, 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "data": { 174 | "text/plain": [ 175 | "1885740153297698816" 176 | ] 177 | }, 178 | "execution_count": 27, 179 | "metadata": {}, 180 | "output_type": "execute_result" 181 | } 182 | ], 183 | "source": [ 184 | "# Power\n", 185 | "math_value_1 ** 3" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 21, 191 | "metadata": {}, 192 | "outputs": [ 193 | { 194 | "data": { 195 | "text/plain": [ 196 | "1212121.79" 197 | ] 198 | }, 199 | "execution_count": 21, 200 | "metadata": {}, 201 | "output_type": "execute_result" 202 | } 203 | ], 204 | "source": [ 205 | "# Round \n", 206 | "round(1212121.789123456, 2)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 24, 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "91123154987978" 218 | ] 219 | }, 220 | "execution_count": 24, 221 | "metadata": {}, 222 | "output_type": "execute_result" 223 | } 224 | ], 225 | "source": [ 226 | "# Absolute Values\n", 227 | "abs(-91123154987978)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 25, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "data": { 237 | "text/plain": [ 238 | "121" 239 | ] 240 | }, 241 | "execution_count": 25, 242 | "metadata": {}, 243 | "output_type": "execute_result" 244 | } 245 | ], 246 | "source": [ 247 | "# Minimum - smallest value \n", 248 | "min(121,8989,1212,5464,8974231,2121)" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 26, 254 | "metadata": {}, 255 | "outputs": [ 256 | { 257 | "data": { 258 | "text/plain": [ 259 | "8974231" 260 | ] 261 | }, 262 | "execution_count": 26, 263 | "metadata": {}, 264 | "output_type": "execute_result" 265 | } 266 | ], 267 | "source": [ 268 | "# Maximum\n", 269 | "max(121,8989,1212,5464,8974231,2121)" 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 28, 275 | "metadata": {}, 276 | "outputs": [], 277 | "source": [ 278 | "# Import the math package\n", 279 | "import math" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 29, 285 | "metadata": {}, 286 | "outputs": [ 287 | { 288 | "data": { 289 | "text/plain": [ 290 | "5.0" 291 | ] 292 | }, 293 | "execution_count": 29, 294 | "metadata": {}, 295 | "output_type": "execute_result" 296 | } 297 | ], 298 | "source": [ 299 | "math.sqrt(25)" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 30, 305 | "metadata": {}, 306 | "outputs": [], 307 | "source": [ 308 | "math.sqrt??" 309 | ] 310 | } 311 | ], 312 | "metadata": { 313 | "kernelspec": { 314 | "display_name": "Python 3", 315 | "language": "python", 316 | "name": "python3" 317 | }, 318 | "language_info": { 319 | "codemirror_mode": { 320 | "name": "ipython", 321 | "version": 3 322 | }, 323 | "file_extension": ".py", 324 | "mimetype": "text/x-python", 325 | "name": "python", 326 | "nbconvert_exporter": "python", 327 | "pygments_lexer": "ipython3", 328 | "version": "3.7.4" 329 | } 330 | }, 331 | "nbformat": 4, 332 | "nbformat_minor": 5 333 | } 334 | -------------------------------------------------------------------------------- /Modules and Packages.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 7. Modules" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "# Import launch codes helper\n", 17 | "from helpers import launch_codes" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 2, 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "data": { 27 | "text/plain": [ 28 | "123456789" 29 | ] 30 | }, 31 | "execution_count": 2, 32 | "metadata": {}, 33 | "output_type": "execute_result" 34 | } 35 | ], 36 | "source": [ 37 | "launch_codes()" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "# 8. Working with Packages" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "!pip install requests" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 5, 59 | "metadata": { 60 | "collapsed": true 61 | }, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "Package Version\n", 68 | "---------------------------------- -------------------\n", 69 | "- rnado\n", 70 | "-ornado 6.1\n", 71 | "-umpy 1.20.1\n", 72 | "absl-py 0.13.0\n", 73 | "alabaster 0.7.12\n", 74 | "anaconda-client 1.7.2\n", 75 | "anaconda-navigator 2.0.3\n", 76 | "anaconda-project 0.9.1\n", 77 | "anyio 2.2.0\n", 78 | "appdirs 1.4.4\n", 79 | "argh 0.26.2\n", 80 | "argon2-cffi 20.1.0\n", 81 | "asn1crypto 1.4.0\n", 82 | "astroid 2.5\n", 83 | "astropy 4.2.1\n", 84 | "astunparse 1.6.3\n", 85 | "async-generator 1.10\n", 86 | "atomicwrites 1.4.0\n", 87 | "attrs 20.3.0\n", 88 | "autopep8 1.5.6\n", 89 | "Babel 2.9.0\n", 90 | "backcall 0.2.0\n", 91 | "backports.functools-lru-cache 1.6.4\n", 92 | "backports.shutil-get-terminal-size 1.0.0\n", 93 | "backports.tempfile 1.0\n", 94 | "backports.weakref 1.0.post1\n", 95 | "bcrypt 3.2.0\n", 96 | "beautifulsoup4 4.9.3\n", 97 | "bitarray 1.9.2\n", 98 | "bkcharts 0.2\n", 99 | "black 19.10b0\n", 100 | "bleach 3.3.0\n", 101 | "bokeh 2.3.2\n", 102 | "boto 2.49.0\n", 103 | "Bottleneck 1.3.2\n", 104 | "brotlipy 0.7.0\n", 105 | "cachetools 4.2.2\n", 106 | "certifi 2020.12.5\n", 107 | "cffi 1.14.5\n", 108 | "chardet 4.0.0\n", 109 | "click 7.1.2\n", 110 | "cloudpickle 1.6.0\n", 111 | "clyent 1.2.2\n", 112 | "colorama 0.4.4\n", 113 | "comtypes 1.1.9\n", 114 | "conda 4.10.3\n", 115 | "conda-build 3.21.4\n", 116 | "conda-content-trust 0+unknown\n", 117 | "conda-package-handling 1.7.3\n", 118 | "conda-repo-cli 1.0.4\n", 119 | "conda-token 0.3.0\n", 120 | "conda-verify 3.4.2\n", 121 | "contextlib2 0.6.0.post1\n", 122 | "cryptography 3.4.7\n", 123 | "cycler 0.10.0\n", 124 | "Cython 0.29.23\n", 125 | "cytoolz 0.11.0\n", 126 | "dask 2021.4.0\n", 127 | "decorator 5.0.6\n", 128 | "defusedxml 0.7.1\n", 129 | "diff-match-patch 20200713\n", 130 | "distributed 2021.4.0\n", 131 | "docutils 0.17\n", 132 | "entrypoints 0.3\n", 133 | "et-xmlfile 1.0.1\n", 134 | "fastcache 1.1.0\n", 135 | "filelock 3.0.12\n", 136 | "flake8 3.9.0\n", 137 | "Flask 1.1.2\n", 138 | "flatbuffers 1.12\n", 139 | "fsspec 0.9.0\n", 140 | "future 0.18.2\n", 141 | "gast 0.4.0\n", 142 | "gevent 21.1.2\n", 143 | "glob2 0.7\n", 144 | "google-auth 1.34.0\n", 145 | "google-auth-oauthlib 0.4.5\n", 146 | "google-pasta 0.2.0\n", 147 | "greenlet 1.0.0\n", 148 | "grpcio 1.34.1\n", 149 | "h5py 3.1.0\n", 150 | "HeapDict 1.0.1\n", 151 | "html5lib 1.1\n", 152 | "idna 2.10\n", 153 | "imagecodecs 2021.3.31\n", 154 | "imageio 2.9.0\n", 155 | "imagesize 1.2.0\n", 156 | "importlib-metadata 3.10.0\n", 157 | "iniconfig 1.1.1\n", 158 | "intervaltree 3.1.0\n", 159 | "ipykernel 5.3.4\n", 160 | "ipython 7.22.0\n", 161 | "ipython-genutils 0.2.0\n", 162 | "ipywidgets 7.6.3\n", 163 | "isort 5.8.0\n", 164 | "itsdangerous 1.1.0\n", 165 | "jdcal 1.4.1\n", 166 | "jedi 0.17.2\n", 167 | "Jinja2 2.11.3\n", 168 | "joblib 1.0.1\n", 169 | "json5 0.9.5\n", 170 | "jsonschema 3.2.0\n", 171 | "jupyter 1.0.0\n", 172 | "jupyter-client 6.1.12\n", 173 | "jupyter-console 6.4.0\n", 174 | "jupyter-core 4.7.1\n", 175 | "jupyter-packaging 0.7.12\n", 176 | "jupyter-server 1.4.1\n", 177 | "jupyterlab 3.0.14\n", 178 | "jupyterlab-pygments 0.1.2\n", 179 | "jupyterlab-server 2.4.0\n", 180 | "jupyterlab-widgets 1.0.0\n", 181 | "keras-nightly 2.5.0.dev2021032900\n", 182 | "Keras-Preprocessing 1.1.2\n", 183 | "keyring 22.3.0\n", 184 | "kiwisolver 1.3.1\n", 185 | "lazy-object-proxy 1.6.0\n", 186 | "libarchive-c 2.9\n", 187 | "llvmlite 0.36.0\n", 188 | "locket 0.2.1\n", 189 | "lxml 4.6.3\n", 190 | "Markdown 3.3.4\n", 191 | "MarkupSafe 1.1.1\n", 192 | "matplotlib 3.3.4\n", 193 | "mccabe 0.6.1\n", 194 | "menuinst 1.4.16\n", 195 | "mistune 0.8.4\n", 196 | "mkl-fft 1.3.0\n", 197 | "mkl-random 1.2.1\n", 198 | "mkl-service 2.3.0\n", 199 | "mock 4.0.3\n", 200 | "more-itertools 8.7.0\n", 201 | "mpmath 1.2.1\n", 202 | "msgpack 1.0.2\n", 203 | "multipledispatch 0.6.0\n", 204 | "mypy-extensions 0.4.3\n", 205 | "navigator-updater 0.2.1\n", 206 | "nbclassic 0.2.6\n", 207 | "nbclient 0.5.3\n", 208 | "nbconvert 6.0.7\n", 209 | "nbformat 5.1.3\n", 210 | "nest-asyncio 1.5.1\n", 211 | "networkx 2.5\n", 212 | "nltk 3.6.1\n", 213 | "nose 1.3.7\n", 214 | "notebook 6.3.0\n", 215 | "numba 0.53.1\n", 216 | "numexpr 2.7.3\n", 217 | "numpy 1.19.5\n", 218 | "numpydoc 1.1.0\n", 219 | "oauthlib 3.1.1\n", 220 | "olefile 0.46\n", 221 | "opencv-python 4.5.3.56\n", 222 | "openpyxl 3.0.7\n", 223 | "opt-einsum 3.3.0\n", 224 | "packaging 20.9\n", 225 | "pandas 1.2.4\n", 226 | "pandocfilters 1.4.3\n", 227 | "paramiko 2.7.2\n", 228 | "parso 0.7.0\n", 229 | "partd 1.2.0\n", 230 | "path 15.1.2\n", 231 | "pathlib2 2.3.5\n", 232 | "pathspec 0.7.0\n", 233 | "patsy 0.5.1\n", 234 | "pep8 1.7.1\n", 235 | "pexpect 4.8.0\n", 236 | "pickleshare 0.7.5\n", 237 | "Pillow 8.2.0\n", 238 | "pip 21.0.1\n", 239 | "pkginfo 1.7.0\n", 240 | "pluggy 0.13.1\n", 241 | "ply 3.11\n", 242 | "prometheus-client 0.10.1\n", 243 | "prompt-toolkit 3.0.17\n", 244 | "protobuf 3.17.3\n", 245 | "psutil 5.8.0\n", 246 | "ptyprocess 0.7.0\n", 247 | "py 1.10.0\n", 248 | "pyasn1 0.4.8\n", 249 | "pyasn1-modules 0.2.8\n", 250 | "pycodestyle 2.6.0\n", 251 | "pycosat 0.6.3\n", 252 | "pycparser 2.20\n", 253 | "pycurl 7.43.0.6\n", 254 | "pydocstyle 6.0.0\n", 255 | "pyerfa 1.7.3\n", 256 | "pyflakes 2.2.0\n", 257 | "Pygments 2.8.1\n", 258 | "pylint 2.7.4\n", 259 | "pyls-black 0.4.6\n", 260 | "pyls-spyder 0.3.2\n", 261 | "PyNaCl 1.4.0\n", 262 | "pyodbc 4.0.0-unsupported\n", 263 | "pyOpenSSL 20.0.1\n", 264 | "pyparsing 2.4.7\n", 265 | "pyreadline 2.1\n", 266 | "pyrsistent 0.17.3\n", 267 | "PySocks 1.7.1\n", 268 | "pytest 6.2.3\n", 269 | "python-dateutil 2.8.1\n", 270 | "python-jsonrpc-server 0.4.0\n", 271 | "python-language-server 0.36.2\n", 272 | "pytz 2021.1\n", 273 | "PyWavelets 1.1.1\n", 274 | "pywin32 227\n", 275 | "pywin32-ctypes 0.2.0\n", 276 | "pywinpty 0.5.7\n", 277 | "PyYAML 5.4.1\n", 278 | "pyzmq 20.0.0\n", 279 | "QDarkStyle 2.8.1\n", 280 | "QtAwesome 1.0.2\n", 281 | "qtconsole 5.0.3\n", 282 | "QtPy 1.9.0\n", 283 | "regex 2021.4.4\n", 284 | "requests 2.25.1\n", 285 | "requests-oauthlib 1.3.0\n", 286 | "rope 0.18.0\n", 287 | "rsa 4.7.2\n", 288 | "Rtree 0.9.7\n", 289 | "ruamel-yaml-conda 0.15.100\n", 290 | "scikit-image 0.18.1\n", 291 | "scikit-learn 0.24.1\n", 292 | "scipy 1.6.2\n", 293 | "seaborn 0.11.1\n", 294 | "Send2Trash 1.5.0\n", 295 | "setuptools 52.0.0.post20210125\n", 296 | "simplegeneric 0.8.1\n", 297 | "singledispatch 0.0.0\n", 298 | "sip 4.19.13\n", 299 | "six 1.15.0\n", 300 | "sniffio 1.2.0\n", 301 | "snowballstemmer 2.1.0\n", 302 | "sortedcollections 2.1.0\n", 303 | "sortedcontainers 2.3.0\n", 304 | "soupsieve 2.2.1\n", 305 | "Sphinx 4.0.1\n", 306 | "sphinxcontrib-applehelp 1.0.2\n", 307 | "sphinxcontrib-devhelp 1.0.2\n", 308 | "sphinxcontrib-htmlhelp 1.0.3\n", 309 | "sphinxcontrib-jsmath 1.0.1\n", 310 | "sphinxcontrib-qthelp 1.0.3\n", 311 | "sphinxcontrib-serializinghtml 1.1.4\n", 312 | "sphinxcontrib-websupport 1.2.4\n", 313 | "spyder 4.2.5\n", 314 | "spyder-kernels 1.10.2\n", 315 | "SQLAlchemy 1.4.7\n", 316 | "statsmodels 0.12.2\n", 317 | "sympy 1.8\n", 318 | "tables 3.6.1\n", 319 | "tblib 1.7.0\n", 320 | "tensorboard 2.5.0\n", 321 | "tensorboard-data-server 0.6.1\n", 322 | "tensorboard-plugin-wit 1.8.0\n", 323 | "tensorflow 2.5.0\n", 324 | "tensorflow-estimator 2.5.0\n", 325 | "termcolor 1.1.0\n", 326 | "terminado 0.9.4\n", 327 | "testpath 0.4.4\n", 328 | "textdistance 4.2.1\n", 329 | "threadpoolctl 2.1.0\n", 330 | "three-merge 0.1.1\n", 331 | "tifffile 2021.4.8\n", 332 | "toml 0.10.2\n", 333 | "toolz 0.11.1\n", 334 | "tornado 6.1\n", 335 | "tqdm 4.59.0\n", 336 | "traitlets 5.0.5\n", 337 | "typed-ast 1.4.2\n", 338 | "typing-extensions 3.7.4.3\n", 339 | "ujson 4.0.2\n", 340 | "unicodecsv 0.14.1\n", 341 | "urllib3 1.26.4\n", 342 | "watchdog 1.0.2\n", 343 | "wcwidth 0.2.5\n", 344 | "webencodings 0.5.1\n", 345 | "Werkzeug 1.0.1\n", 346 | "wheel 0.36.2\n", 347 | "widgetsnbextension 3.5.1\n", 348 | "win-inet-pton 1.1.0\n", 349 | "win-unicode-console 0.5\n", 350 | "wincertstore 0.2\n", 351 | "wrapt 1.12.1\n", 352 | "xlrd 2.0.1\n", 353 | "XlsxWriter 1.3.8\n", 354 | "xlwings 0.23.0\n", 355 | "xlwt 1.3.0\n", 356 | "xmltodict 0.12.0\n", 357 | "yapf 0.31.0\n", 358 | "youtube-dl 2021.6.6\n", 359 | "zict 2.0.0\n", 360 | "zipp 3.4.1\n", 361 | "zope.event 4.5.0\n", 362 | "zope.interface 5.3.0\n" 363 | ] 364 | } 365 | ], 366 | "source": [ 367 | "!pip list" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 7, 373 | "metadata": {}, 374 | "outputs": [], 375 | "source": [ 376 | "# Import requests into notebook\n", 377 | "import requests" 378 | ] 379 | }, 380 | { 381 | "cell_type": "code", 382 | "execution_count": 9, 383 | "metadata": {}, 384 | "outputs": [], 385 | "source": [ 386 | "# I can haz dad joke api endpoint\n", 387 | "joke_url = 'https://icanhazdadjoke.com'\n", 388 | "\n", 389 | "# Iss API Endpoint\n", 390 | "iss_url = 'https://api.wheretheiss.at/v1/satellites/25544'" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 28, 396 | "metadata": {}, 397 | "outputs": [], 398 | "source": [ 399 | "# This is setting up a header - metadata for your api request \n", 400 | "my_header = {'Accept':'application/json'}\n", 401 | "\n", 402 | "# API call\n", 403 | "results = requests.get(joke_url, headers=my_header)" 404 | ] 405 | }, 406 | { 407 | "cell_type": "code", 408 | "execution_count": 35, 409 | "metadata": {}, 410 | "outputs": [ 411 | { 412 | "data": { 413 | "text/plain": [ 414 | "" 415 | ] 416 | }, 417 | "execution_count": 35, 418 | "metadata": {}, 419 | "output_type": "execute_result" 420 | } 421 | ], 422 | "source": [ 423 | "# Status of api request\n", 424 | "results" 425 | ] 426 | }, 427 | { 428 | "cell_type": "code", 429 | "execution_count": 36, 430 | "metadata": {}, 431 | "outputs": [], 432 | "source": [ 433 | "# Extract JSON results from API\n", 434 | "json_result = results.json()" 435 | ] 436 | }, 437 | { 438 | "cell_type": "code", 439 | "execution_count": 30, 440 | "metadata": {}, 441 | "outputs": [ 442 | { 443 | "data": { 444 | "text/plain": [ 445 | "dict" 446 | ] 447 | }, 448 | "execution_count": 30, 449 | "metadata": {}, 450 | "output_type": "execute_result" 451 | } 452 | ], 453 | "source": [ 454 | "type(json_result)" 455 | ] 456 | }, 457 | { 458 | "cell_type": "code", 459 | "execution_count": 31, 460 | "metadata": {}, 461 | "outputs": [ 462 | { 463 | "data": { 464 | "text/plain": [ 465 | "'At the boxing match, the dad got into the popcorn line and the line for hot dogs, but he wanted to stay out of the punchline.'" 466 | ] 467 | }, 468 | "execution_count": 31, 469 | "metadata": {}, 470 | "output_type": "execute_result" 471 | } 472 | ], 473 | "source": [ 474 | "json_result['joke']" 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": 37, 480 | "metadata": {}, 481 | "outputs": [], 482 | "source": [ 483 | "# Making an ISS API CALL\n", 484 | "iss_results = requests.get(iss_url, headers=my_header)" 485 | ] 486 | }, 487 | { 488 | "cell_type": "code", 489 | "execution_count": 34, 490 | "metadata": {}, 491 | "outputs": [ 492 | { 493 | "data": { 494 | "text/plain": [ 495 | "{'name': 'iss',\n", 496 | " 'id': 25544,\n", 497 | " 'latitude': -7.5807259730229,\n", 498 | " 'longitude': 26.575010685914,\n", 499 | " 'altitude': 422.11580115155,\n", 500 | " 'velocity': 27571.587350287,\n", 501 | " 'visibility': 'daylight',\n", 502 | " 'footprint': 4518.2120811976,\n", 503 | " 'timestamp': 1628148748,\n", 504 | " 'daynum': 2459431.814213,\n", 505 | " 'solar_lat': 16.877074603974,\n", 506 | " 'solar_lon': 68.391792982596,\n", 507 | " 'units': 'kilometers'}" 508 | ] 509 | }, 510 | "execution_count": 34, 511 | "metadata": {}, 512 | "output_type": "execute_result" 513 | } 514 | ], 515 | "source": [ 516 | "iss_results.json()" 517 | ] 518 | } 519 | ], 520 | "metadata": { 521 | "kernelspec": { 522 | "display_name": "Python 3", 523 | "language": "python", 524 | "name": "python3" 525 | }, 526 | "language_info": { 527 | "codemirror_mode": { 528 | "name": "ipython", 529 | "version": 3 530 | }, 531 | "file_extension": ".py", 532 | "mimetype": "text/x-python", 533 | "name": "python", 534 | "nbconvert_exporter": "python", 535 | "pygments_lexer": "ipython3", 536 | "version": "3.7.4" 537 | } 538 | }, 539 | "nbformat": 4, 540 | "nbformat_minor": 5 541 | } 542 | -------------------------------------------------------------------------------- /Python Basics.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 0. Variables" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 9, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "space_name = 123456.012" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 10, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "123456.012\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "print(space_name)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 11, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "float" 45 | ] 46 | }, 47 | "execution_count": 11, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "type(space_name)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "# 1. Data Types" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 16, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "pluto\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "# This is declaring a variable as a STRING \n", 78 | "string_variable = 'pluto'\n", 79 | "print(string_variable)" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 17, 85 | "metadata": {}, 86 | "outputs": [ 87 | { 88 | "data": { 89 | "text/plain": [ 90 | "str" 91 | ] 92 | }, 93 | "execution_count": 17, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "type(string_variable)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 19, 105 | "metadata": {}, 106 | "outputs": [ 107 | { 108 | "data": { 109 | "text/plain": [ 110 | "int" 111 | ] 112 | }, 113 | "execution_count": 19, 114 | "metadata": {}, 115 | "output_type": "execute_result" 116 | } 117 | ], 118 | "source": [ 119 | "# This is declaring a variable as an Integer\n", 120 | "integer_variable = 123852\n", 121 | "type(integer_variable)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 21, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "data": { 131 | "text/plain": [ 132 | "123862" 133 | ] 134 | }, 135 | "execution_count": 21, 136 | "metadata": {}, 137 | "output_type": "execute_result" 138 | } 139 | ], 140 | "source": [ 141 | "integer_variable + 10" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 23, 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "data": { 151 | "text/plain": [ 152 | "float" 153 | ] 154 | }, 155 | "execution_count": 23, 156 | "metadata": {}, 157 | "output_type": "execute_result" 158 | } 159 | ], 160 | "source": [ 161 | "# This is declaring a variable as a Float\n", 162 | "float_variable = 128.126\n", 163 | "type(float_variable)" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 28, 169 | "metadata": {}, 170 | "outputs": [ 171 | { 172 | "data": { 173 | "text/plain": [ 174 | "bool" 175 | ] 176 | }, 177 | "execution_count": 28, 178 | "metadata": {}, 179 | "output_type": "execute_result" 180 | } 181 | ], 182 | "source": [ 183 | "# This is assigning a Boolean value to a variable\n", 184 | "bool_variable = bool(0)\n", 185 | "type(bool_variable)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 29, 191 | "metadata": {}, 192 | "outputs": [ 193 | { 194 | "data": { 195 | "text/plain": [ 196 | "False" 197 | ] 198 | }, 199 | "execution_count": 29, 200 | "metadata": {}, 201 | "output_type": "execute_result" 202 | } 203 | ], 204 | "source": [ 205 | "bool_variable" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 57, 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "data": { 215 | "text/plain": [ 216 | "list" 217 | ] 218 | }, 219 | "execution_count": 57, 220 | "metadata": {}, 221 | "output_type": "execute_result" 222 | } 223 | ], 224 | "source": [ 225 | "# This is creating a list variable\n", 226 | "list_variable = [1, 2, 3, 123.44, 85.4, 22.1, 1,2,3,1,2,3]\n", 227 | "type(list_variable)" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 44, 233 | "metadata": {}, 234 | "outputs": [], 235 | "source": [ 236 | "list_variable[5] = 123" 237 | ] 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 58, 242 | "metadata": {}, 243 | "outputs": [ 244 | { 245 | "data": { 246 | "text/plain": [ 247 | "[1, 2, 3, 123.44, 85.4, 22.1, 1, 2, 3, 1, 2, 3]" 248 | ] 249 | }, 250 | "execution_count": 58, 251 | "metadata": {}, 252 | "output_type": "execute_result" 253 | } 254 | ], 255 | "source": [ 256 | "list_variable" 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "execution_count": 54, 262 | "metadata": {}, 263 | "outputs": [ 264 | { 265 | "data": { 266 | "text/plain": [ 267 | "tuple" 268 | ] 269 | }, 270 | "execution_count": 54, 271 | "metadata": {}, 272 | "output_type": "execute_result" 273 | } 274 | ], 275 | "source": [ 276 | "# Create a TUPLE variable, IMMUTABLE = you can't change the values\n", 277 | "tuple_variable = (1, 2, 3, 123.44, 85.4, 22.1, 3)\n", 278 | "type(tuple_variable)" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 56, 284 | "metadata": {}, 285 | "outputs": [ 286 | { 287 | "data": { 288 | "text/plain": [ 289 | "(1, 2, 3, 123.44, 85.4, 22.1, 3)" 290 | ] 291 | }, 292 | "execution_count": 56, 293 | "metadata": {}, 294 | "output_type": "execute_result" 295 | } 296 | ], 297 | "source": [ 298 | "tuple_variable" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 52, 304 | "metadata": {}, 305 | "outputs": [ 306 | { 307 | "data": { 308 | "text/plain": [ 309 | "set" 310 | ] 311 | }, 312 | "execution_count": 52, 313 | "metadata": {}, 314 | "output_type": "execute_result" 315 | } 316 | ], 317 | "source": [ 318 | "# This is creating a SET variable, IMMUTABLE = you can't change the values, No DUPLICATES!\n", 319 | "set_variable = {1, 2, 3, 123.44, 85.4, 22.1, 3}\n", 320 | "type(set_variable)" 321 | ] 322 | }, 323 | { 324 | "cell_type": "code", 325 | "execution_count": 63, 326 | "metadata": {}, 327 | "outputs": [ 328 | { 329 | "data": { 330 | "text/plain": [ 331 | "list" 332 | ] 333 | }, 334 | "execution_count": 63, 335 | "metadata": {}, 336 | "output_type": "execute_result" 337 | } 338 | ], 339 | "source": [ 340 | "# Type casting list to set back to list to get rid of duplicates\n", 341 | "type(list(set(list_variable)))" 342 | ] 343 | }, 344 | { 345 | "cell_type": "code", 346 | "execution_count": 67, 347 | "metadata": {}, 348 | "outputs": [ 349 | { 350 | "data": { 351 | "text/plain": [ 352 | "dict" 353 | ] 354 | }, 355 | "execution_count": 67, 356 | "metadata": {}, 357 | "output_type": "execute_result" 358 | } 359 | ], 360 | "source": [ 361 | "# Defining a dictionary variable\n", 362 | "person_variable = {'name':\"Nicholas\", 'favourite_color':'red', 'favourite_number':20}\n", 363 | "type(dict_variable)" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "execution_count": 71, 369 | "metadata": {}, 370 | "outputs": [ 371 | { 372 | "data": { 373 | "text/plain": [ 374 | "20" 375 | ] 376 | }, 377 | "execution_count": 71, 378 | "metadata": {}, 379 | "output_type": "execute_result" 380 | } 381 | ], 382 | "source": [ 383 | "person_variable['favourite_number']" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": 72, 389 | "metadata": {}, 390 | "outputs": [], 391 | "source": [ 392 | "fit_models = {}" 393 | ] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": 73, 398 | "metadata": {}, 399 | "outputs": [ 400 | { 401 | "data": { 402 | "text/plain": [ 403 | "(1, 2, 3, 123.44, 85.4, 22.1, 1, 2, 3, 1, 2, 3)" 404 | ] 405 | }, 406 | "execution_count": 73, 407 | "metadata": {}, 408 | "output_type": "execute_result" 409 | } 410 | ], 411 | "source": [ 412 | "tuple(list_variable)" 413 | ] 414 | }, 415 | { 416 | "cell_type": "markdown", 417 | "metadata": {}, 418 | "source": [ 419 | "# 2. Lists" 420 | ] 421 | }, 422 | { 423 | "cell_type": "code", 424 | "execution_count": 74, 425 | "metadata": {}, 426 | "outputs": [], 427 | "source": [ 428 | "# Create\n", 429 | "names = ['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 75, 435 | "metadata": {}, 436 | "outputs": [ 437 | { 438 | "data": { 439 | "text/plain": [ 440 | "['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 441 | ] 442 | }, 443 | "execution_count": 75, 444 | "metadata": {}, 445 | "output_type": "execute_result" 446 | } 447 | ], 448 | "source": [ 449 | "# Read \n", 450 | "names" 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "execution_count": 77, 456 | "metadata": {}, 457 | "outputs": [ 458 | { 459 | "data": { 460 | "text/plain": [ 461 | "'neil armstrong'" 462 | ] 463 | }, 464 | "execution_count": 77, 465 | "metadata": {}, 466 | "output_type": "execute_result" 467 | } 468 | ], 469 | "source": [ 470 | "# Reading using Indexing\n", 471 | "names[0]" 472 | ] 473 | }, 474 | { 475 | "cell_type": "code", 476 | "execution_count": 78, 477 | "metadata": {}, 478 | "outputs": [ 479 | { 480 | "data": { 481 | "text/plain": [ 482 | "'elon musk'" 483 | ] 484 | }, 485 | "execution_count": 78, 486 | "metadata": {}, 487 | "output_type": "execute_result" 488 | } 489 | ], 490 | "source": [ 491 | "names[-1]" 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": 79, 497 | "metadata": {}, 498 | "outputs": [ 499 | { 500 | "data": { 501 | "text/plain": [ 502 | "5" 503 | ] 504 | }, 505 | "execution_count": 79, 506 | "metadata": {}, 507 | "output_type": "execute_result" 508 | } 509 | ], 510 | "source": [ 511 | "len(names)" 512 | ] 513 | }, 514 | { 515 | "cell_type": "code", 516 | "execution_count": null, 517 | "metadata": {}, 518 | "outputs": [], 519 | "source": [ 520 | "# Update" 521 | ] 522 | }, 523 | { 524 | "cell_type": "code", 525 | "execution_count": 80, 526 | "metadata": {}, 527 | "outputs": [ 528 | { 529 | "data": { 530 | "text/plain": [ 531 | "['neil armstrong',\n", 532 | " 'buzz aldrin',\n", 533 | " 'sally ride',\n", 534 | " 'yuri gagarin',\n", 535 | " 'nicholas renotte']" 536 | ] 537 | }, 538 | "execution_count": 80, 539 | "metadata": {}, 540 | "output_type": "execute_result" 541 | } 542 | ], 543 | "source": [ 544 | "names[-1] = 'nicholas renotte'\n", 545 | "names" 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": 81, 551 | "metadata": {}, 552 | "outputs": [], 553 | "source": [ 554 | "names.append('elon musk')" 555 | ] 556 | }, 557 | { 558 | "cell_type": "code", 559 | "execution_count": 82, 560 | "metadata": {}, 561 | "outputs": [ 562 | { 563 | "data": { 564 | "text/plain": [ 565 | "['neil armstrong',\n", 566 | " 'buzz aldrin',\n", 567 | " 'sally ride',\n", 568 | " 'yuri gagarin',\n", 569 | " 'nicholas renotte',\n", 570 | " 'elon musk']" 571 | ] 572 | }, 573 | "execution_count": 82, 574 | "metadata": {}, 575 | "output_type": "execute_result" 576 | } 577 | ], 578 | "source": [ 579 | "names" 580 | ] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "execution_count": 84, 585 | "metadata": {}, 586 | "outputs": [], 587 | "source": [ 588 | "names.insert(0, 'richard branson')" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": 85, 594 | "metadata": {}, 595 | "outputs": [ 596 | { 597 | "data": { 598 | "text/plain": [ 599 | "['richard branson',\n", 600 | " 'neil armstrong',\n", 601 | " 'buzz aldrin',\n", 602 | " 'sally ride',\n", 603 | " 'yuri gagarin',\n", 604 | " 'nicholas renotte',\n", 605 | " 'elon musk']" 606 | ] 607 | }, 608 | "execution_count": 85, 609 | "metadata": {}, 610 | "output_type": "execute_result" 611 | } 612 | ], 613 | "source": [ 614 | "names" 615 | ] 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": null, 620 | "metadata": {}, 621 | "outputs": [], 622 | "source": [ 623 | "# Delete" 624 | ] 625 | }, 626 | { 627 | "cell_type": "code", 628 | "execution_count": 87, 629 | "metadata": {}, 630 | "outputs": [], 631 | "source": [ 632 | "del names[-2]" 633 | ] 634 | }, 635 | { 636 | "cell_type": "code", 637 | "execution_count": 88, 638 | "metadata": {}, 639 | "outputs": [ 640 | { 641 | "data": { 642 | "text/plain": [ 643 | "['richard branson',\n", 644 | " 'neil armstrong',\n", 645 | " 'buzz aldrin',\n", 646 | " 'sally ride',\n", 647 | " 'yuri gagarin',\n", 648 | " 'elon musk']" 649 | ] 650 | }, 651 | "execution_count": 88, 652 | "metadata": {}, 653 | "output_type": "execute_result" 654 | } 655 | ], 656 | "source": [ 657 | "names" 658 | ] 659 | }, 660 | { 661 | "cell_type": "markdown", 662 | "metadata": {}, 663 | "source": [ 664 | "# 3. Dictionaries" 665 | ] 666 | }, 667 | { 668 | "cell_type": "code", 669 | "execution_count": 91, 670 | "metadata": {}, 671 | "outputs": [], 672 | "source": [ 673 | "# Create\n", 674 | "astronaut = {\n", 675 | " \"name\":\"elon musk\", \n", 676 | " \"suit_size\":\"large\", \n", 677 | " \"allergies\":\"peanuts\"\n", 678 | "}" 679 | ] 680 | }, 681 | { 682 | "cell_type": "code", 683 | "execution_count": null, 684 | "metadata": {}, 685 | "outputs": [], 686 | "source": [ 687 | "# Read" 688 | ] 689 | }, 690 | { 691 | "cell_type": "code", 692 | "execution_count": 92, 693 | "metadata": {}, 694 | "outputs": [ 695 | { 696 | "data": { 697 | "text/plain": [ 698 | "{'name': 'elon musk', 'suit_size': 'large', 'allergies': 'peanuts'}" 699 | ] 700 | }, 701 | "execution_count": 92, 702 | "metadata": {}, 703 | "output_type": "execute_result" 704 | } 705 | ], 706 | "source": [ 707 | "astronaut" 708 | ] 709 | }, 710 | { 711 | "cell_type": "code", 712 | "execution_count": 97, 713 | "metadata": {}, 714 | "outputs": [ 715 | { 716 | "data": { 717 | "text/plain": [ 718 | "'large'" 719 | ] 720 | }, 721 | "execution_count": 97, 722 | "metadata": {}, 723 | "output_type": "execute_result" 724 | } 725 | ], 726 | "source": [ 727 | "astronaut['suit_size']" 728 | ] 729 | }, 730 | { 731 | "cell_type": "code", 732 | "execution_count": 102, 733 | "metadata": {}, 734 | "outputs": [ 735 | { 736 | "data": { 737 | "text/plain": [ 738 | "dict_keys(['name', 'suit_size', 'allergies'])" 739 | ] 740 | }, 741 | "execution_count": 102, 742 | "metadata": {}, 743 | "output_type": "execute_result" 744 | } 745 | ], 746 | "source": [ 747 | "astronaut.keys()" 748 | ] 749 | }, 750 | { 751 | "cell_type": "code", 752 | "execution_count": 103, 753 | "metadata": {}, 754 | "outputs": [ 755 | { 756 | "data": { 757 | "text/plain": [ 758 | "dict_values(['elon musk', 'large', 'peanuts'])" 759 | ] 760 | }, 761 | "execution_count": 103, 762 | "metadata": {}, 763 | "output_type": "execute_result" 764 | } 765 | ], 766 | "source": [ 767 | "astronaut.values()" 768 | ] 769 | }, 770 | { 771 | "cell_type": "code", 772 | "execution_count": 89, 773 | "metadata": {}, 774 | "outputs": [], 775 | "source": [ 776 | "# Update" 777 | ] 778 | }, 779 | { 780 | "cell_type": "code", 781 | "execution_count": 105, 782 | "metadata": {}, 783 | "outputs": [], 784 | "source": [ 785 | "astronaut['allergies'] = 'mango'" 786 | ] 787 | }, 788 | { 789 | "cell_type": "code", 790 | "execution_count": 106, 791 | "metadata": {}, 792 | "outputs": [ 793 | { 794 | "data": { 795 | "text/plain": [ 796 | "{'name': 'elon musk', 'suit_size': 'large', 'allergies': 'mango'}" 797 | ] 798 | }, 799 | "execution_count": 106, 800 | "metadata": {}, 801 | "output_type": "execute_result" 802 | } 803 | ], 804 | "source": [ 805 | "astronaut" 806 | ] 807 | }, 808 | { 809 | "cell_type": "code", 810 | "execution_count": 107, 811 | "metadata": {}, 812 | "outputs": [], 813 | "source": [ 814 | "astronaut['space_ship'] = 'Galactic 1'" 815 | ] 816 | }, 817 | { 818 | "cell_type": "code", 819 | "execution_count": 108, 820 | "metadata": {}, 821 | "outputs": [ 822 | { 823 | "data": { 824 | "text/plain": [ 825 | "{'name': 'elon musk',\n", 826 | " 'suit_size': 'large',\n", 827 | " 'allergies': 'mango',\n", 828 | " 'space_ship': 'Galactic 1'}" 829 | ] 830 | }, 831 | "execution_count": 108, 832 | "metadata": {}, 833 | "output_type": "execute_result" 834 | } 835 | ], 836 | "source": [ 837 | "astronaut" 838 | ] 839 | }, 840 | { 841 | "cell_type": "code", 842 | "execution_count": null, 843 | "metadata": {}, 844 | "outputs": [], 845 | "source": [ 846 | "# Delete" 847 | ] 848 | }, 849 | { 850 | "cell_type": "code", 851 | "execution_count": 109, 852 | "metadata": {}, 853 | "outputs": [], 854 | "source": [ 855 | "del astronaut['space_ship']" 856 | ] 857 | }, 858 | { 859 | "cell_type": "code", 860 | "execution_count": 110, 861 | "metadata": {}, 862 | "outputs": [ 863 | { 864 | "data": { 865 | "text/plain": [ 866 | "{'name': 'elon musk', 'suit_size': 'large', 'allergies': 'mango'}" 867 | ] 868 | }, 869 | "execution_count": 110, 870 | "metadata": {}, 871 | "output_type": "execute_result" 872 | } 873 | ], 874 | "source": [ 875 | "astronaut" 876 | ] 877 | }, 878 | { 879 | "cell_type": "markdown", 880 | "metadata": {}, 881 | "source": [ 882 | "# 4. Conditions and Logic" 883 | ] 884 | }, 885 | { 886 | "cell_type": "code", 887 | "execution_count": 4, 888 | "metadata": {}, 889 | "outputs": [ 890 | { 891 | "name": "stdout", 892 | "output_type": "stream", 893 | "text": [ 894 | "Sup not Neil\n" 895 | ] 896 | } 897 | ], 898 | "source": [ 899 | "# Applying logic using the IF statement\n", 900 | "name = 'Nick'\n", 901 | "if name == 'Neil Armstrong':\n", 902 | " print('Sup not Neil')" 903 | ] 904 | }, 905 | { 906 | "cell_type": "code", 907 | "execution_count": 15, 908 | "metadata": {}, 909 | "outputs": [ 910 | { 911 | "name": "stdout", 912 | "output_type": "stream", 913 | "text": [ 914 | "False\n" 915 | ] 916 | } 917 | ], 918 | "source": [ 919 | "probability = 0.1\n", 920 | "# Probability is greater than 0.5\n", 921 | "if probability >= 0.5:\n", 922 | " print(True)\n", 923 | " \n", 924 | "# Print out a statement is probability is below\n", 925 | "elif probability < 0: \n", 926 | " print('Check yo probabilities')\n", 927 | " \n", 928 | "# Anything else\n", 929 | "else: \n", 930 | " print(False)" 931 | ] 932 | }, 933 | { 934 | "cell_type": "code", 935 | "execution_count": 23, 936 | "metadata": {}, 937 | "outputs": [ 938 | { 939 | "name": "stdout", 940 | "output_type": "stream", 941 | "text": [ 942 | "Elon's here\n" 943 | ] 944 | } 945 | ], 946 | "source": [ 947 | "# Create a list of names\n", 948 | "names = ['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk'] \n", 949 | "if 'elon musk' in names:\n", 950 | " # Using Python escapes\n", 951 | " print(\"Elon\\'s here\")" 952 | ] 953 | }, 954 | { 955 | "cell_type": "markdown", 956 | "metadata": {}, 957 | "source": [ 958 | "# 5. Loops" 959 | ] 960 | }, 961 | { 962 | "cell_type": "code", 963 | "execution_count": 34, 964 | "metadata": {}, 965 | "outputs": [ 966 | { 967 | "name": "stdout", 968 | "output_type": "stream", 969 | "text": [ 970 | "neil armstrong\n", 971 | "Pleased to have you here!\n", 972 | "\n", 973 | "buzz aldrin\n", 974 | "Sup buzz \n", 975 | "\n", 976 | "sally ride\n", 977 | "Pleased to have you here!\n", 978 | "\n", 979 | "yuri gagarin\n", 980 | "Hey yuri!\n" 981 | ] 982 | } 983 | ], 984 | "source": [ 985 | "# This is an example of a For loop\n", 986 | "for name in names:\n", 987 | " print(name)\n", 988 | " \n", 989 | " # Condition statement block\n", 990 | " if name == 'buzz aldrin':\n", 991 | " print('Sup buzz \\n')\n", 992 | " # Next value in the loop\n", 993 | " continue\n", 994 | " \n", 995 | " elif name == 'yuri gagarin':\n", 996 | " print('Hey yuri!')\n", 997 | " # Break statement stops the loop\n", 998 | " break\n", 999 | " \n", 1000 | " # Catch all \n", 1001 | " else:\n", 1002 | " # Placeholder to do nothing\n", 1003 | " pass\n", 1004 | " \n", 1005 | " # Outside of if statement block\n", 1006 | " print('Pleased to have you here!\\n')" 1007 | ] 1008 | }, 1009 | { 1010 | "cell_type": "code", 1011 | "execution_count": 37, 1012 | "metadata": {}, 1013 | "outputs": [ 1014 | { 1015 | "name": "stdout", 1016 | "output_type": "stream", 1017 | "text": [ 1018 | "1\n", 1019 | "2\n", 1020 | "3\n", 1021 | "4\n", 1022 | "5\n", 1023 | "6\n", 1024 | "7\n", 1025 | "8\n", 1026 | "9\n", 1027 | "10\n" 1028 | ] 1029 | } 1030 | ], 1031 | "source": [ 1032 | "# Loop x number of times\n", 1033 | "for idx in range(1,11):\n", 1034 | " print(idx)" 1035 | ] 1036 | }, 1037 | { 1038 | "cell_type": "code", 1039 | "execution_count": 41, 1040 | "metadata": {}, 1041 | "outputs": [ 1042 | { 1043 | "name": "stdout", 1044 | "output_type": "stream", 1045 | "text": [ 1046 | "Shuttle 1 launched\n", 1047 | "Shuttle 2 launched\n", 1048 | "Shuttle 3 launched\n", 1049 | "Shuttle 4 launched\n", 1050 | "Shuttle 5 launched\n", 1051 | "Shuttle 6 launched\n", 1052 | "Shuttle 7 launched\n", 1053 | "Shuttle 8 launched\n", 1054 | "Shuttle 9 launched\n", 1055 | "Shuttle 10 launched\n", 1056 | "All shuttles launched\n" 1057 | ] 1058 | } 1059 | ], 1060 | "source": [ 1061 | "# Create launch variables\n", 1062 | "launched_shuttles = 0 \n", 1063 | "total_shuttles = 10 \n", 1064 | "\n", 1065 | "# Create a while loop\n", 1066 | "while True:\n", 1067 | " # STRING FORMATTING\n", 1068 | " print('Shuttle {} launched'.format(launched_shuttles+1))\n", 1069 | " launched_shuttles += 1\n", 1070 | "\n", 1071 | " if launched_shuttles == total_shuttles:\n", 1072 | " print('All shuttles launched')\n", 1073 | " break " 1074 | ] 1075 | }, 1076 | { 1077 | "cell_type": "code", 1078 | "execution_count": 42, 1079 | "metadata": {}, 1080 | "outputs": [], 1081 | "source": [ 1082 | "astronaut = {\n", 1083 | " \"name\":\"Elon Musk\", \n", 1084 | " \"suit_size\": \"Medium\", \n", 1085 | " \"allergies\":\"peanuts\"\n", 1086 | "}" 1087 | ] 1088 | }, 1089 | { 1090 | "cell_type": "code", 1091 | "execution_count": 44, 1092 | "metadata": {}, 1093 | "outputs": [ 1094 | { 1095 | "data": { 1096 | "text/plain": [ 1097 | "dict_keys(['name', 'suit_size', 'allergies'])" 1098 | ] 1099 | }, 1100 | "execution_count": 44, 1101 | "metadata": {}, 1102 | "output_type": "execute_result" 1103 | } 1104 | ], 1105 | "source": [ 1106 | "# Accessing dictionary keys\n", 1107 | "astronaut.keys()" 1108 | ] 1109 | }, 1110 | { 1111 | "cell_type": "code", 1112 | "execution_count": 55, 1113 | "metadata": {}, 1114 | "outputs": [ 1115 | { 1116 | "name": "stdout", 1117 | "output_type": "stream", 1118 | "text": [ 1119 | "name\n", 1120 | "suit_size\n", 1121 | "allergies\n" 1122 | ] 1123 | } 1124 | ], 1125 | "source": [ 1126 | "# Loop through keys in a dictionary\n", 1127 | "for key in astronaut.keys(): \n", 1128 | " print(key)" 1129 | ] 1130 | }, 1131 | { 1132 | "cell_type": "code", 1133 | "execution_count": 46, 1134 | "metadata": {}, 1135 | "outputs": [ 1136 | { 1137 | "data": { 1138 | "text/plain": [ 1139 | "dict_values(['Elon Musk', 'Medium', 'peanuts'])" 1140 | ] 1141 | }, 1142 | "execution_count": 46, 1143 | "metadata": {}, 1144 | "output_type": "execute_result" 1145 | } 1146 | ], 1147 | "source": [ 1148 | "# Accessing dictionary values\n", 1149 | "astronaut.values()" 1150 | ] 1151 | }, 1152 | { 1153 | "cell_type": "code", 1154 | "execution_count": 49, 1155 | "metadata": {}, 1156 | "outputs": [ 1157 | { 1158 | "name": "stdout", 1159 | "output_type": "stream", 1160 | "text": [ 1161 | "Elon Musk\n", 1162 | "Medium\n", 1163 | "peanuts\n" 1164 | ] 1165 | } 1166 | ], 1167 | "source": [ 1168 | "# Loop through values in a dictionary\n", 1169 | "for value in astronaut.values():\n", 1170 | " print(value)" 1171 | ] 1172 | }, 1173 | { 1174 | "cell_type": "code", 1175 | "execution_count": 50, 1176 | "metadata": {}, 1177 | "outputs": [ 1178 | { 1179 | "data": { 1180 | "text/plain": [ 1181 | "dict_items([('name', 'Elon Musk'), ('suit_size', 'Medium'), ('allergies', 'peanuts')])" 1182 | ] 1183 | }, 1184 | "execution_count": 50, 1185 | "metadata": {}, 1186 | "output_type": "execute_result" 1187 | } 1188 | ], 1189 | "source": [ 1190 | "astronaut.items()" 1191 | ] 1192 | }, 1193 | { 1194 | "cell_type": "code", 1195 | "execution_count": 53, 1196 | "metadata": {}, 1197 | "outputs": [ 1198 | { 1199 | "name": "stdout", 1200 | "output_type": "stream", 1201 | "text": [ 1202 | "name\n", 1203 | "Elon Musk \n", 1204 | "\n", 1205 | "suit_size\n", 1206 | "Medium \n", 1207 | "\n", 1208 | "allergies\n", 1209 | "peanuts \n", 1210 | "\n" 1211 | ] 1212 | } 1213 | ], 1214 | "source": [ 1215 | "# Loop through keys and values at the same time \n", 1216 | "for key, value in astronaut.items():\n", 1217 | " print(key)\n", 1218 | " print(value, '\\n')" 1219 | ] 1220 | }, 1221 | { 1222 | "cell_type": "code", 1223 | "execution_count": 56, 1224 | "metadata": {}, 1225 | "outputs": [], 1226 | "source": [ 1227 | "# List comprehension\n", 1228 | "new_list = [name.title() for name in names]" 1229 | ] 1230 | }, 1231 | { 1232 | "cell_type": "code", 1233 | "execution_count": 57, 1234 | "metadata": {}, 1235 | "outputs": [ 1236 | { 1237 | "data": { 1238 | "text/plain": [ 1239 | "['Neil Armstrong', 'Buzz Aldrin', 'Sally Ride', 'Yuri Gagarin', 'Elon Musk']" 1240 | ] 1241 | }, 1242 | "execution_count": 57, 1243 | "metadata": {}, 1244 | "output_type": "execute_result" 1245 | } 1246 | ], 1247 | "source": [ 1248 | "new_list" 1249 | ] 1250 | }, 1251 | { 1252 | "cell_type": "code", 1253 | "execution_count": 58, 1254 | "metadata": {}, 1255 | "outputs": [ 1256 | { 1257 | "data": { 1258 | "text/plain": [ 1259 | "['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 1260 | ] 1261 | }, 1262 | "execution_count": 58, 1263 | "metadata": {}, 1264 | "output_type": "execute_result" 1265 | } 1266 | ], 1267 | "source": [ 1268 | "names" 1269 | ] 1270 | }, 1271 | { 1272 | "cell_type": "markdown", 1273 | "metadata": {}, 1274 | "source": [ 1275 | "# 6. Functions" 1276 | ] 1277 | }, 1278 | { 1279 | "cell_type": "code", 1280 | "execution_count": 5, 1281 | "metadata": {}, 1282 | "outputs": [], 1283 | "source": [ 1284 | "# Defining a function in Python - Recipe \n", 1285 | "def launchpad_welcome():\n", 1286 | " print('hello')\n", 1287 | " print(1+2)\n", 1288 | " print(3+4)" 1289 | ] 1290 | }, 1291 | { 1292 | "cell_type": "code", 1293 | "execution_count": 18, 1294 | "metadata": {}, 1295 | "outputs": [ 1296 | { 1297 | "name": "stdout", 1298 | "output_type": "stream", 1299 | "text": [ 1300 | "hello\n", 1301 | "3\n", 1302 | "7\n" 1303 | ] 1304 | } 1305 | ], 1306 | "source": [ 1307 | "# Running our function\n", 1308 | "launchpad_welcome()" 1309 | ] 1310 | }, 1311 | { 1312 | "cell_type": "code", 1313 | "execution_count": 20, 1314 | "metadata": {}, 1315 | "outputs": [ 1316 | { 1317 | "name": "stdout", 1318 | "output_type": "stream", 1319 | "text": [ 1320 | "Welcome Elon Musk\n" 1321 | ] 1322 | } 1323 | ], 1324 | "source": [ 1325 | "# String formatting \n", 1326 | "print('Welcome {} {}'.format('Elon', 'Musk'))" 1327 | ] 1328 | }, 1329 | { 1330 | "cell_type": "code", 1331 | "execution_count": 9, 1332 | "metadata": {}, 1333 | "outputs": [], 1334 | "source": [ 1335 | "names = ['neil armstrong', 'buzz aldrin', 'sally ride', 'yuri gagarin', 'elon musk']" 1336 | ] 1337 | }, 1338 | { 1339 | "cell_type": "code", 1340 | "execution_count": 21, 1341 | "metadata": {}, 1342 | "outputs": [], 1343 | "source": [ 1344 | "# Positional Arguments\n", 1345 | "def custom_welcome(name):\n", 1346 | " print('Welcome {}'.format(name))" 1347 | ] 1348 | }, 1349 | { 1350 | "cell_type": "code", 1351 | "execution_count": 16, 1352 | "metadata": {}, 1353 | "outputs": [ 1354 | { 1355 | "name": "stdout", 1356 | "output_type": "stream", 1357 | "text": [ 1358 | "Welcome Nick Renotte\n" 1359 | ] 1360 | } 1361 | ], 1362 | "source": [ 1363 | "custom_welcome('Nick Renotte')" 1364 | ] 1365 | }, 1366 | { 1367 | "cell_type": "code", 1368 | "execution_count": 17, 1369 | "metadata": {}, 1370 | "outputs": [ 1371 | { 1372 | "name": "stdout", 1373 | "output_type": "stream", 1374 | "text": [ 1375 | "Welcome neil armstrong\n", 1376 | "Welcome buzz aldrin\n", 1377 | "Welcome sally ride\n", 1378 | "Welcome yuri gagarin\n", 1379 | "Welcome elon musk\n" 1380 | ] 1381 | } 1382 | ], 1383 | "source": [ 1384 | "for name in names:\n", 1385 | " custom_welcome(name)" 1386 | ] 1387 | }, 1388 | { 1389 | "cell_type": "code", 1390 | "execution_count": 22, 1391 | "metadata": {}, 1392 | "outputs": [], 1393 | "source": [ 1394 | "# Multiple positional Arguments - POSITION IS IMPORTANT\n", 1395 | "def custom_welcome_to_ship(name, space_ship):\n", 1396 | " print('Welcome {} to the {}'.format(name, space_ship))" 1397 | ] 1398 | }, 1399 | { 1400 | "cell_type": "code", 1401 | "execution_count": 25, 1402 | "metadata": {}, 1403 | "outputs": [ 1404 | { 1405 | "name": "stdout", 1406 | "output_type": "stream", 1407 | "text": [ 1408 | "Welcome Nick Renotte to the Galatic 1\n" 1409 | ] 1410 | } 1411 | ], 1412 | "source": [ 1413 | "custom_welcome_to_ship('Nick Renotte', 'Galatic 1')" 1414 | ] 1415 | }, 1416 | { 1417 | "cell_type": "code", 1418 | "execution_count": 33, 1419 | "metadata": {}, 1420 | "outputs": [], 1421 | "source": [ 1422 | "space_ships = ['Galactic 1', 'Galactic 2', 'USS Voyager', 'Maximum Amazin Wow Space Ship', 'Apple iShip']" 1423 | ] 1424 | }, 1425 | { 1426 | "cell_type": "code", 1427 | "execution_count": 34, 1428 | "metadata": {}, 1429 | "outputs": [ 1430 | { 1431 | "name": "stdout", 1432 | "output_type": "stream", 1433 | "text": [ 1434 | "Welcome neil armstrong to the Galactic 1\n", 1435 | "Welcome buzz aldrin to the Galactic 2\n", 1436 | "Welcome sally ride to the USS Voyager\n", 1437 | "Welcome yuri gagarin to the Maximum Amazin Wow Space Ship\n", 1438 | "Welcome elon musk to the Apple iShip\n" 1439 | ] 1440 | } 1441 | ], 1442 | "source": [ 1443 | "# Used the enumerate function to get the positional index AND the name\n", 1444 | "for idx, name in enumerate(names):\n", 1445 | " ship = space_ships[idx]\n", 1446 | " custom_welcome_to_ship(name, ship)" 1447 | ] 1448 | }, 1449 | { 1450 | "cell_type": "code", 1451 | "execution_count": 38, 1452 | "metadata": {}, 1453 | "outputs": [], 1454 | "source": [ 1455 | "# This is using keyword arguments\n", 1456 | "def space_suit(color='Blue'):\n", 1457 | " print('Your space suit is {}'.format(color))" 1458 | ] 1459 | }, 1460 | { 1461 | "cell_type": "code", 1462 | "execution_count": 37, 1463 | "metadata": {}, 1464 | "outputs": [ 1465 | { 1466 | "name": "stdout", 1467 | "output_type": "stream", 1468 | "text": [ 1469 | "Your space suit is Red\n" 1470 | ] 1471 | } 1472 | ], 1473 | "source": [ 1474 | "space_suit(color='Red')" 1475 | ] 1476 | }, 1477 | { 1478 | "cell_type": "code", 1479 | "execution_count": 52, 1480 | "metadata": {}, 1481 | "outputs": [], 1482 | "source": [ 1483 | "# Multiple keyword arguments\n", 1484 | "def space_suit_welcome(name, space_ship, color='Blue', allergies='None'):\n", 1485 | " print('Welcome {} to the {}, your space suit is {}, you have {} allergies'.format(name, space_ship, color, allergies))" 1486 | ] 1487 | }, 1488 | { 1489 | "cell_type": "code", 1490 | "execution_count": 47, 1491 | "metadata": {}, 1492 | "outputs": [ 1493 | { 1494 | "name": "stdout", 1495 | "output_type": "stream", 1496 | "text": [ 1497 | "Welcome Elon Musk to the Apple iShip, your space suit is Orange, you have Peanut allergies\n" 1498 | ] 1499 | } 1500 | ], 1501 | "source": [ 1502 | "space_suit_welcome('Elon Musk', 'Apple iShip', allergies='Peanut', color='Orange')" 1503 | ] 1504 | }, 1505 | { 1506 | "cell_type": "code", 1507 | "execution_count": 53, 1508 | "metadata": {}, 1509 | "outputs": [], 1510 | "source": [ 1511 | "# Setup a return statement\n", 1512 | "def space_suit_welcome_with_return(name, space_ship, color='Blue', allergies='None'):\n", 1513 | " return 'Welcome {} to the {}, your space suit is {}, you have {} allergies'.format(name, space_ship, color, allergies)" 1514 | ] 1515 | }, 1516 | { 1517 | "cell_type": "code", 1518 | "execution_count": 54, 1519 | "metadata": {}, 1520 | "outputs": [], 1521 | "source": [ 1522 | "# Example of storing the results of the function inside a variable\n", 1523 | "welcome = space_suit_welcome_with_return('Elon Musk', 'Apple iShip')" 1524 | ] 1525 | }, 1526 | { 1527 | "cell_type": "code", 1528 | "execution_count": 51, 1529 | "metadata": {}, 1530 | "outputs": [ 1531 | { 1532 | "name": "stdout", 1533 | "output_type": "stream", 1534 | "text": [ 1535 | "Welcome Elon Musk to the Apple iShip, your space suit is Blue, you have None allergies\n" 1536 | ] 1537 | } 1538 | ], 1539 | "source": [ 1540 | "print(welcome)" 1541 | ] 1542 | }, 1543 | { 1544 | "cell_type": "code", 1545 | "execution_count": 58, 1546 | "metadata": {}, 1547 | "outputs": [], 1548 | "source": [ 1549 | "# Lambda function - anonymous function\n", 1550 | "pi = lambda x: x*3.14" 1551 | ] 1552 | }, 1553 | { 1554 | "cell_type": "code", 1555 | "execution_count": 59, 1556 | "metadata": {}, 1557 | "outputs": [], 1558 | "source": [ 1559 | "return_value = pi(2)" 1560 | ] 1561 | }, 1562 | { 1563 | "cell_type": "code", 1564 | "execution_count": 60, 1565 | "metadata": {}, 1566 | "outputs": [ 1567 | { 1568 | "name": "stdout", 1569 | "output_type": "stream", 1570 | "text": [ 1571 | "6.28\n" 1572 | ] 1573 | } 1574 | ], 1575 | "source": [ 1576 | "print(return_value)" 1577 | ] 1578 | }, 1579 | { 1580 | "cell_type": "code", 1581 | "execution_count": 57, 1582 | "metadata": {}, 1583 | "outputs": [ 1584 | { 1585 | "data": { 1586 | "text/plain": [ 1587 | "6.28" 1588 | ] 1589 | }, 1590 | "execution_count": 57, 1591 | "metadata": {}, 1592 | "output_type": "execute_result" 1593 | } 1594 | ], 1595 | "source": [ 1596 | "3.14*2" 1597 | ] 1598 | }, 1599 | { 1600 | "cell_type": "markdown", 1601 | "metadata": {}, 1602 | "source": [ 1603 | "# 5. Classes" 1604 | ] 1605 | }, 1606 | { 1607 | "cell_type": "code", 1608 | "execution_count": 11, 1609 | "metadata": {}, 1610 | "outputs": [], 1611 | "source": [ 1612 | "# Classes as boilerplates for objects\n", 1613 | "class Person():\n", 1614 | " # The method that runs as soon as you create a class - initialise\n", 1615 | " def __init__(self, name, age, color):\n", 1616 | " # Create some attributes for our person class\n", 1617 | " self.name = name \n", 1618 | " self.age = age\n", 1619 | " self.color = color\n", 1620 | " \n", 1621 | " # Date of birth method\n", 1622 | " def year_of_birth(self):\n", 1623 | " return 2021-self.age\n", 1624 | " \n", 1625 | " # Projected age \n", 1626 | " def project_age(self, years=5):\n", 1627 | " return self.age+years" 1628 | ] 1629 | }, 1630 | { 1631 | "cell_type": "code", 1632 | "execution_count": 12, 1633 | "metadata": {}, 1634 | "outputs": [], 1635 | "source": [ 1636 | "new_person = Person('Elon Musk', 38, 'blue')" 1637 | ] 1638 | }, 1639 | { 1640 | "cell_type": "code", 1641 | "execution_count": 19, 1642 | "metadata": {}, 1643 | "outputs": [ 1644 | { 1645 | "data": { 1646 | "text/plain": [ 1647 | "38" 1648 | ] 1649 | }, 1650 | "execution_count": 19, 1651 | "metadata": {}, 1652 | "output_type": "execute_result" 1653 | } 1654 | ], 1655 | "source": [ 1656 | "# Accessing a class attribute\n", 1657 | "new_person.age" 1658 | ] 1659 | }, 1660 | { 1661 | "cell_type": "code", 1662 | "execution_count": 14, 1663 | "metadata": {}, 1664 | "outputs": [ 1665 | { 1666 | "data": { 1667 | "text/plain": [ 1668 | "1983" 1669 | ] 1670 | }, 1671 | "execution_count": 14, 1672 | "metadata": {}, 1673 | "output_type": "execute_result" 1674 | } 1675 | ], 1676 | "source": [ 1677 | "# Run a method\n", 1678 | "new_person.year_of_birth()" 1679 | ] 1680 | }, 1681 | { 1682 | "cell_type": "code", 1683 | "execution_count": 17, 1684 | "metadata": {}, 1685 | "outputs": [ 1686 | { 1687 | "data": { 1688 | "text/plain": [ 1689 | "48" 1690 | ] 1691 | }, 1692 | "execution_count": 17, 1693 | "metadata": {}, 1694 | "output_type": "execute_result" 1695 | } 1696 | ], 1697 | "source": [ 1698 | "# Run a method with a keyword argument\n", 1699 | "new_person.project_age(years=10)" 1700 | ] 1701 | }, 1702 | { 1703 | "cell_type": "markdown", 1704 | "metadata": {}, 1705 | "source": [ 1706 | "# 6. Inheritance\n", 1707 | "- PARENT is the class passing down attributes and methods = PERSON\n", 1708 | "- CHILD is the class inheriting the methods and attributes = ASTRONAUT" 1709 | ] 1710 | }, 1711 | { 1712 | "cell_type": "code", 1713 | "execution_count": 34, 1714 | "metadata": {}, 1715 | "outputs": [], 1716 | "source": [ 1717 | "# Create a child class\n", 1718 | "class Astronaut(Person):\n", 1719 | " \n", 1720 | " # Define initialization function\n", 1721 | " def __init__(self, name, age, color, mission_length_in_months):\n", 1722 | " \n", 1723 | " # This is what gives us inheritance - SUPER METHOD\n", 1724 | " super().__init__(name, age, color)\n", 1725 | " self.mission_length_months = mission_length_in_months\n", 1726 | " \n", 1727 | " # Method for calculating age on return\n", 1728 | " def age_on_return(self):\n", 1729 | " return self.project_age(years=int(self.mission_length_months/12))" 1730 | ] 1731 | }, 1732 | { 1733 | "cell_type": "code", 1734 | "execution_count": 35, 1735 | "metadata": {}, 1736 | "outputs": [], 1737 | "source": [ 1738 | "new_astronaut = Astronaut('Nick', 99, 'purple', 48)" 1739 | ] 1740 | }, 1741 | { 1742 | "cell_type": "code", 1743 | "execution_count": 36, 1744 | "metadata": {}, 1745 | "outputs": [ 1746 | { 1747 | "data": { 1748 | "text/plain": [ 1749 | "'purple'" 1750 | ] 1751 | }, 1752 | "execution_count": 36, 1753 | "metadata": {}, 1754 | "output_type": "execute_result" 1755 | } 1756 | ], 1757 | "source": [ 1758 | "# Access parent like attribute \n", 1759 | "new_astronaut.color" 1760 | ] 1761 | }, 1762 | { 1763 | "cell_type": "code", 1764 | "execution_count": 39, 1765 | "metadata": {}, 1766 | "outputs": [ 1767 | { 1768 | "data": { 1769 | "text/plain": [ 1770 | "1922" 1771 | ] 1772 | }, 1773 | "execution_count": 39, 1774 | "metadata": {}, 1775 | "output_type": "execute_result" 1776 | } 1777 | ], 1778 | "source": [ 1779 | "# Access the methods\n", 1780 | "new_astronaut.year_of_birth()" 1781 | ] 1782 | }, 1783 | { 1784 | "cell_type": "code", 1785 | "execution_count": 38, 1786 | "metadata": {}, 1787 | "outputs": [ 1788 | { 1789 | "data": { 1790 | "text/plain": [ 1791 | "103" 1792 | ] 1793 | }, 1794 | "execution_count": 38, 1795 | "metadata": {}, 1796 | "output_type": "execute_result" 1797 | } 1798 | ], 1799 | "source": [ 1800 | "# Run a method\n", 1801 | "new_astronaut.age_on_return()" 1802 | ] 1803 | }, 1804 | { 1805 | "cell_type": "markdown", 1806 | "metadata": {}, 1807 | "source": [ 1808 | "# 7. Modules" 1809 | ] 1810 | }, 1811 | { 1812 | "cell_type": "code", 1813 | "execution_count": 1, 1814 | "metadata": {}, 1815 | "outputs": [], 1816 | "source": [ 1817 | "# Import launch codes helper\n", 1818 | "from helpers import launch_codes" 1819 | ] 1820 | }, 1821 | { 1822 | "cell_type": "code", 1823 | "execution_count": 2, 1824 | "metadata": {}, 1825 | "outputs": [ 1826 | { 1827 | "data": { 1828 | "text/plain": [ 1829 | "123456789" 1830 | ] 1831 | }, 1832 | "execution_count": 2, 1833 | "metadata": {}, 1834 | "output_type": "execute_result" 1835 | } 1836 | ], 1837 | "source": [ 1838 | "launch_codes()" 1839 | ] 1840 | }, 1841 | { 1842 | "cell_type": "markdown", 1843 | "metadata": {}, 1844 | "source": [ 1845 | "# 8. Working with Packages" 1846 | ] 1847 | }, 1848 | { 1849 | "cell_type": "code", 1850 | "execution_count": null, 1851 | "metadata": {}, 1852 | "outputs": [], 1853 | "source": [ 1854 | "!pip install requests" 1855 | ] 1856 | }, 1857 | { 1858 | "cell_type": "code", 1859 | "execution_count": 5, 1860 | "metadata": { 1861 | "collapsed": true 1862 | }, 1863 | "outputs": [ 1864 | { 1865 | "name": "stdout", 1866 | "output_type": "stream", 1867 | "text": [ 1868 | "Package Version\n", 1869 | "---------------------------------- -------------------\n", 1870 | "- rnado\n", 1871 | "-ornado 6.1\n", 1872 | "-umpy 1.20.1\n", 1873 | "absl-py 0.13.0\n", 1874 | "alabaster 0.7.12\n", 1875 | "anaconda-client 1.7.2\n", 1876 | "anaconda-navigator 2.0.3\n", 1877 | "anaconda-project 0.9.1\n", 1878 | "anyio 2.2.0\n", 1879 | "appdirs 1.4.4\n", 1880 | "argh 0.26.2\n", 1881 | "argon2-cffi 20.1.0\n", 1882 | "asn1crypto 1.4.0\n", 1883 | "astroid 2.5\n", 1884 | "astropy 4.2.1\n", 1885 | "astunparse 1.6.3\n", 1886 | "async-generator 1.10\n", 1887 | "atomicwrites 1.4.0\n", 1888 | "attrs 20.3.0\n", 1889 | "autopep8 1.5.6\n", 1890 | "Babel 2.9.0\n", 1891 | "backcall 0.2.0\n", 1892 | "backports.functools-lru-cache 1.6.4\n", 1893 | "backports.shutil-get-terminal-size 1.0.0\n", 1894 | "backports.tempfile 1.0\n", 1895 | "backports.weakref 1.0.post1\n", 1896 | "bcrypt 3.2.0\n", 1897 | "beautifulsoup4 4.9.3\n", 1898 | "bitarray 1.9.2\n", 1899 | "bkcharts 0.2\n", 1900 | "black 19.10b0\n", 1901 | "bleach 3.3.0\n", 1902 | "bokeh 2.3.2\n", 1903 | "boto 2.49.0\n", 1904 | "Bottleneck 1.3.2\n", 1905 | "brotlipy 0.7.0\n", 1906 | "cachetools 4.2.2\n", 1907 | "certifi 2020.12.5\n", 1908 | "cffi 1.14.5\n", 1909 | "chardet 4.0.0\n", 1910 | "click 7.1.2\n", 1911 | "cloudpickle 1.6.0\n", 1912 | "clyent 1.2.2\n", 1913 | "colorama 0.4.4\n", 1914 | "comtypes 1.1.9\n", 1915 | "conda 4.10.3\n", 1916 | "conda-build 3.21.4\n", 1917 | "conda-content-trust 0+unknown\n", 1918 | "conda-package-handling 1.7.3\n", 1919 | "conda-repo-cli 1.0.4\n", 1920 | "conda-token 0.3.0\n", 1921 | "conda-verify 3.4.2\n", 1922 | "contextlib2 0.6.0.post1\n", 1923 | "cryptography 3.4.7\n", 1924 | "cycler 0.10.0\n", 1925 | "Cython 0.29.23\n", 1926 | "cytoolz 0.11.0\n", 1927 | "dask 2021.4.0\n", 1928 | "decorator 5.0.6\n", 1929 | "defusedxml 0.7.1\n", 1930 | "diff-match-patch 20200713\n", 1931 | "distributed 2021.4.0\n", 1932 | "docutils 0.17\n", 1933 | "entrypoints 0.3\n", 1934 | "et-xmlfile 1.0.1\n", 1935 | "fastcache 1.1.0\n", 1936 | "filelock 3.0.12\n", 1937 | "flake8 3.9.0\n", 1938 | "Flask 1.1.2\n", 1939 | "flatbuffers 1.12\n", 1940 | "fsspec 0.9.0\n", 1941 | "future 0.18.2\n", 1942 | "gast 0.4.0\n", 1943 | "gevent 21.1.2\n", 1944 | "glob2 0.7\n", 1945 | "google-auth 1.34.0\n", 1946 | "google-auth-oauthlib 0.4.5\n", 1947 | "google-pasta 0.2.0\n", 1948 | "greenlet 1.0.0\n", 1949 | "grpcio 1.34.1\n", 1950 | "h5py 3.1.0\n", 1951 | "HeapDict 1.0.1\n", 1952 | "html5lib 1.1\n", 1953 | "idna 2.10\n", 1954 | "imagecodecs 2021.3.31\n", 1955 | "imageio 2.9.0\n", 1956 | "imagesize 1.2.0\n", 1957 | "importlib-metadata 3.10.0\n", 1958 | "iniconfig 1.1.1\n", 1959 | "intervaltree 3.1.0\n", 1960 | "ipykernel 5.3.4\n", 1961 | "ipython 7.22.0\n", 1962 | "ipython-genutils 0.2.0\n", 1963 | "ipywidgets 7.6.3\n", 1964 | "isort 5.8.0\n", 1965 | "itsdangerous 1.1.0\n", 1966 | "jdcal 1.4.1\n", 1967 | "jedi 0.17.2\n", 1968 | "Jinja2 2.11.3\n", 1969 | "joblib 1.0.1\n", 1970 | "json5 0.9.5\n", 1971 | "jsonschema 3.2.0\n", 1972 | "jupyter 1.0.0\n", 1973 | "jupyter-client 6.1.12\n", 1974 | "jupyter-console 6.4.0\n", 1975 | "jupyter-core 4.7.1\n", 1976 | "jupyter-packaging 0.7.12\n", 1977 | "jupyter-server 1.4.1\n", 1978 | "jupyterlab 3.0.14\n", 1979 | "jupyterlab-pygments 0.1.2\n", 1980 | "jupyterlab-server 2.4.0\n", 1981 | "jupyterlab-widgets 1.0.0\n", 1982 | "keras-nightly 2.5.0.dev2021032900\n", 1983 | "Keras-Preprocessing 1.1.2\n", 1984 | "keyring 22.3.0\n", 1985 | "kiwisolver 1.3.1\n", 1986 | "lazy-object-proxy 1.6.0\n", 1987 | "libarchive-c 2.9\n", 1988 | "llvmlite 0.36.0\n", 1989 | "locket 0.2.1\n", 1990 | "lxml 4.6.3\n", 1991 | "Markdown 3.3.4\n", 1992 | "MarkupSafe 1.1.1\n", 1993 | "matplotlib 3.3.4\n", 1994 | "mccabe 0.6.1\n", 1995 | "menuinst 1.4.16\n", 1996 | "mistune 0.8.4\n", 1997 | "mkl-fft 1.3.0\n", 1998 | "mkl-random 1.2.1\n", 1999 | "mkl-service 2.3.0\n", 2000 | "mock 4.0.3\n", 2001 | "more-itertools 8.7.0\n", 2002 | "mpmath 1.2.1\n", 2003 | "msgpack 1.0.2\n", 2004 | "multipledispatch 0.6.0\n", 2005 | "mypy-extensions 0.4.3\n", 2006 | "navigator-updater 0.2.1\n", 2007 | "nbclassic 0.2.6\n", 2008 | "nbclient 0.5.3\n", 2009 | "nbconvert 6.0.7\n", 2010 | "nbformat 5.1.3\n", 2011 | "nest-asyncio 1.5.1\n", 2012 | "networkx 2.5\n", 2013 | "nltk 3.6.1\n", 2014 | "nose 1.3.7\n", 2015 | "notebook 6.3.0\n", 2016 | "numba 0.53.1\n", 2017 | "numexpr 2.7.3\n", 2018 | "numpy 1.19.5\n", 2019 | "numpydoc 1.1.0\n", 2020 | "oauthlib 3.1.1\n", 2021 | "olefile 0.46\n", 2022 | "opencv-python 4.5.3.56\n", 2023 | "openpyxl 3.0.7\n", 2024 | "opt-einsum 3.3.0\n", 2025 | "packaging 20.9\n", 2026 | "pandas 1.2.4\n", 2027 | "pandocfilters 1.4.3\n", 2028 | "paramiko 2.7.2\n", 2029 | "parso 0.7.0\n", 2030 | "partd 1.2.0\n", 2031 | "path 15.1.2\n", 2032 | "pathlib2 2.3.5\n", 2033 | "pathspec 0.7.0\n", 2034 | "patsy 0.5.1\n", 2035 | "pep8 1.7.1\n", 2036 | "pexpect 4.8.0\n", 2037 | "pickleshare 0.7.5\n", 2038 | "Pillow 8.2.0\n", 2039 | "pip 21.0.1\n", 2040 | "pkginfo 1.7.0\n", 2041 | "pluggy 0.13.1\n", 2042 | "ply 3.11\n", 2043 | "prometheus-client 0.10.1\n", 2044 | "prompt-toolkit 3.0.17\n", 2045 | "protobuf 3.17.3\n", 2046 | "psutil 5.8.0\n", 2047 | "ptyprocess 0.7.0\n", 2048 | "py 1.10.0\n", 2049 | "pyasn1 0.4.8\n", 2050 | "pyasn1-modules 0.2.8\n", 2051 | "pycodestyle 2.6.0\n", 2052 | "pycosat 0.6.3\n", 2053 | "pycparser 2.20\n", 2054 | "pycurl 7.43.0.6\n", 2055 | "pydocstyle 6.0.0\n", 2056 | "pyerfa 1.7.3\n", 2057 | "pyflakes 2.2.0\n", 2058 | "Pygments 2.8.1\n", 2059 | "pylint 2.7.4\n", 2060 | "pyls-black 0.4.6\n", 2061 | "pyls-spyder 0.3.2\n", 2062 | "PyNaCl 1.4.0\n", 2063 | "pyodbc 4.0.0-unsupported\n", 2064 | "pyOpenSSL 20.0.1\n", 2065 | "pyparsing 2.4.7\n", 2066 | "pyreadline 2.1\n", 2067 | "pyrsistent 0.17.3\n", 2068 | "PySocks 1.7.1\n", 2069 | "pytest 6.2.3\n", 2070 | "python-dateutil 2.8.1\n", 2071 | "python-jsonrpc-server 0.4.0\n", 2072 | "python-language-server 0.36.2\n", 2073 | "pytz 2021.1\n", 2074 | "PyWavelets 1.1.1\n", 2075 | "pywin32 227\n", 2076 | "pywin32-ctypes 0.2.0\n", 2077 | "pywinpty 0.5.7\n", 2078 | "PyYAML 5.4.1\n", 2079 | "pyzmq 20.0.0\n", 2080 | "QDarkStyle 2.8.1\n", 2081 | "QtAwesome 1.0.2\n", 2082 | "qtconsole 5.0.3\n", 2083 | "QtPy 1.9.0\n", 2084 | "regex 2021.4.4\n", 2085 | "requests 2.25.1\n", 2086 | "requests-oauthlib 1.3.0\n", 2087 | "rope 0.18.0\n", 2088 | "rsa 4.7.2\n", 2089 | "Rtree 0.9.7\n", 2090 | "ruamel-yaml-conda 0.15.100\n", 2091 | "scikit-image 0.18.1\n", 2092 | "scikit-learn 0.24.1\n", 2093 | "scipy 1.6.2\n", 2094 | "seaborn 0.11.1\n", 2095 | "Send2Trash 1.5.0\n", 2096 | "setuptools 52.0.0.post20210125\n", 2097 | "simplegeneric 0.8.1\n", 2098 | "singledispatch 0.0.0\n", 2099 | "sip 4.19.13\n", 2100 | "six 1.15.0\n", 2101 | "sniffio 1.2.0\n", 2102 | "snowballstemmer 2.1.0\n", 2103 | "sortedcollections 2.1.0\n", 2104 | "sortedcontainers 2.3.0\n", 2105 | "soupsieve 2.2.1\n", 2106 | "Sphinx 4.0.1\n", 2107 | "sphinxcontrib-applehelp 1.0.2\n", 2108 | "sphinxcontrib-devhelp 1.0.2\n", 2109 | "sphinxcontrib-htmlhelp 1.0.3\n", 2110 | "sphinxcontrib-jsmath 1.0.1\n", 2111 | "sphinxcontrib-qthelp 1.0.3\n", 2112 | "sphinxcontrib-serializinghtml 1.1.4\n", 2113 | "sphinxcontrib-websupport 1.2.4\n", 2114 | "spyder 4.2.5\n", 2115 | "spyder-kernels 1.10.2\n", 2116 | "SQLAlchemy 1.4.7\n", 2117 | "statsmodels 0.12.2\n", 2118 | "sympy 1.8\n", 2119 | "tables 3.6.1\n", 2120 | "tblib 1.7.0\n", 2121 | "tensorboard 2.5.0\n", 2122 | "tensorboard-data-server 0.6.1\n", 2123 | "tensorboard-plugin-wit 1.8.0\n", 2124 | "tensorflow 2.5.0\n", 2125 | "tensorflow-estimator 2.5.0\n", 2126 | "termcolor 1.1.0\n", 2127 | "terminado 0.9.4\n", 2128 | "testpath 0.4.4\n", 2129 | "textdistance 4.2.1\n", 2130 | "threadpoolctl 2.1.0\n", 2131 | "three-merge 0.1.1\n", 2132 | "tifffile 2021.4.8\n", 2133 | "toml 0.10.2\n", 2134 | "toolz 0.11.1\n", 2135 | "tornado 6.1\n", 2136 | "tqdm 4.59.0\n", 2137 | "traitlets 5.0.5\n", 2138 | "typed-ast 1.4.2\n", 2139 | "typing-extensions 3.7.4.3\n", 2140 | "ujson 4.0.2\n", 2141 | "unicodecsv 0.14.1\n", 2142 | "urllib3 1.26.4\n", 2143 | "watchdog 1.0.2\n", 2144 | "wcwidth 0.2.5\n", 2145 | "webencodings 0.5.1\n", 2146 | "Werkzeug 1.0.1\n", 2147 | "wheel 0.36.2\n", 2148 | "widgetsnbextension 3.5.1\n", 2149 | "win-inet-pton 1.1.0\n", 2150 | "win-unicode-console 0.5\n", 2151 | "wincertstore 0.2\n", 2152 | "wrapt 1.12.1\n", 2153 | "xlrd 2.0.1\n", 2154 | "XlsxWriter 1.3.8\n", 2155 | "xlwings 0.23.0\n", 2156 | "xlwt 1.3.0\n", 2157 | "xmltodict 0.12.0\n", 2158 | "yapf 0.31.0\n", 2159 | "youtube-dl 2021.6.6\n", 2160 | "zict 2.0.0\n", 2161 | "zipp 3.4.1\n", 2162 | "zope.event 4.5.0\n", 2163 | "zope.interface 5.3.0\n" 2164 | ] 2165 | } 2166 | ], 2167 | "source": [ 2168 | "!pip list" 2169 | ] 2170 | }, 2171 | { 2172 | "cell_type": "code", 2173 | "execution_count": 7, 2174 | "metadata": {}, 2175 | "outputs": [], 2176 | "source": [ 2177 | "# Import requests into notebook\n", 2178 | "import requests" 2179 | ] 2180 | }, 2181 | { 2182 | "cell_type": "code", 2183 | "execution_count": 9, 2184 | "metadata": {}, 2185 | "outputs": [], 2186 | "source": [ 2187 | "# I can haz dad joke api endpoint\n", 2188 | "joke_url = 'https://icanhazdadjoke.com'\n", 2189 | "\n", 2190 | "# Iss API Endpoint\n", 2191 | "iss_url = 'https://api.wheretheiss.at/v1/satellites/25544'" 2192 | ] 2193 | }, 2194 | { 2195 | "cell_type": "code", 2196 | "execution_count": 28, 2197 | "metadata": {}, 2198 | "outputs": [], 2199 | "source": [ 2200 | "# This is setting up a header - metadata for your api request \n", 2201 | "my_header = {'Accept':'application/json'}\n", 2202 | "\n", 2203 | "# API call\n", 2204 | "results = requests.get(joke_url, headers=my_header)" 2205 | ] 2206 | }, 2207 | { 2208 | "cell_type": "code", 2209 | "execution_count": 35, 2210 | "metadata": {}, 2211 | "outputs": [ 2212 | { 2213 | "data": { 2214 | "text/plain": [ 2215 | "" 2216 | ] 2217 | }, 2218 | "execution_count": 35, 2219 | "metadata": {}, 2220 | "output_type": "execute_result" 2221 | } 2222 | ], 2223 | "source": [ 2224 | "# Status of api request\n", 2225 | "results" 2226 | ] 2227 | }, 2228 | { 2229 | "cell_type": "code", 2230 | "execution_count": 36, 2231 | "metadata": {}, 2232 | "outputs": [], 2233 | "source": [ 2234 | "# Extract JSON results from API\n", 2235 | "json_result = results.json()" 2236 | ] 2237 | }, 2238 | { 2239 | "cell_type": "code", 2240 | "execution_count": 30, 2241 | "metadata": {}, 2242 | "outputs": [ 2243 | { 2244 | "data": { 2245 | "text/plain": [ 2246 | "dict" 2247 | ] 2248 | }, 2249 | "execution_count": 30, 2250 | "metadata": {}, 2251 | "output_type": "execute_result" 2252 | } 2253 | ], 2254 | "source": [ 2255 | "type(json_result)" 2256 | ] 2257 | }, 2258 | { 2259 | "cell_type": "code", 2260 | "execution_count": 31, 2261 | "metadata": {}, 2262 | "outputs": [ 2263 | { 2264 | "data": { 2265 | "text/plain": [ 2266 | "'At the boxing match, the dad got into the popcorn line and the line for hot dogs, but he wanted to stay out of the punchline.'" 2267 | ] 2268 | }, 2269 | "execution_count": 31, 2270 | "metadata": {}, 2271 | "output_type": "execute_result" 2272 | } 2273 | ], 2274 | "source": [ 2275 | "json_result['joke']" 2276 | ] 2277 | }, 2278 | { 2279 | "cell_type": "code", 2280 | "execution_count": 37, 2281 | "metadata": {}, 2282 | "outputs": [], 2283 | "source": [ 2284 | "# Making an ISS API CALL\n", 2285 | "iss_results = requests.get(iss_url, headers=my_header)" 2286 | ] 2287 | }, 2288 | { 2289 | "cell_type": "code", 2290 | "execution_count": 34, 2291 | "metadata": {}, 2292 | "outputs": [ 2293 | { 2294 | "data": { 2295 | "text/plain": [ 2296 | "{'name': 'iss',\n", 2297 | " 'id': 25544,\n", 2298 | " 'latitude': -7.5807259730229,\n", 2299 | " 'longitude': 26.575010685914,\n", 2300 | " 'altitude': 422.11580115155,\n", 2301 | " 'velocity': 27571.587350287,\n", 2302 | " 'visibility': 'daylight',\n", 2303 | " 'footprint': 4518.2120811976,\n", 2304 | " 'timestamp': 1628148748,\n", 2305 | " 'daynum': 2459431.814213,\n", 2306 | " 'solar_lat': 16.877074603974,\n", 2307 | " 'solar_lon': 68.391792982596,\n", 2308 | " 'units': 'kilometers'}" 2309 | ] 2310 | }, 2311 | "execution_count": 34, 2312 | "metadata": {}, 2313 | "output_type": "execute_result" 2314 | } 2315 | ], 2316 | "source": [ 2317 | "iss_results.json()" 2318 | ] 2319 | }, 2320 | { 2321 | "cell_type": "markdown", 2322 | "metadata": {}, 2323 | "source": [ 2324 | "# 9. Working with Files" 2325 | ] 2326 | }, 2327 | { 2328 | "cell_type": "code", 2329 | "execution_count": 3, 2330 | "metadata": {}, 2331 | "outputs": [], 2332 | "source": [ 2333 | "# Write out our mission journal \n", 2334 | "with open('mission_jounal.txt', 'w') as f:\n", 2335 | " f.write(\"It's my first on the space mission. It is verry nice.\")" 2336 | ] 2337 | }, 2338 | { 2339 | "cell_type": "code", 2340 | "execution_count": 5, 2341 | "metadata": {}, 2342 | "outputs": [], 2343 | "source": [ 2344 | "# Read from journal\n", 2345 | "with open('mission_jounal.txt', 'r') as f:\n", 2346 | " file = f.read()" 2347 | ] 2348 | }, 2349 | { 2350 | "cell_type": "code", 2351 | "execution_count": 6, 2352 | "metadata": {}, 2353 | "outputs": [ 2354 | { 2355 | "name": "stdout", 2356 | "output_type": "stream", 2357 | "text": [ 2358 | "It's my first on the space mission. It is verry nice.\n" 2359 | ] 2360 | } 2361 | ], 2362 | "source": [ 2363 | "print(file)" 2364 | ] 2365 | }, 2366 | { 2367 | "cell_type": "markdown", 2368 | "metadata": {}, 2369 | "source": [ 2370 | "# 10. Error Handling" 2371 | ] 2372 | }, 2373 | { 2374 | "cell_type": "code", 2375 | "execution_count": 9, 2376 | "metadata": {}, 2377 | "outputs": [], 2378 | "source": [ 2379 | "# Create a set\n", 2380 | "new_set = {1,2,3,4,5,6}" 2381 | ] 2382 | }, 2383 | { 2384 | "cell_type": "code", 2385 | "execution_count": 16, 2386 | "metadata": {}, 2387 | "outputs": [ 2388 | { 2389 | "ename": "TypeError", 2390 | "evalue": "'set' object does not support item assignment", 2391 | "output_type": "error", 2392 | "traceback": [ 2393 | "\u001b[1;31m-------------------------------------------------------\u001b[0m", 2394 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 2395 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mnew_set\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m4\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 2396 | "\u001b[1;31mTypeError\u001b[0m: 'set' object does not support item assignment" 2397 | ] 2398 | } 2399 | ], 2400 | "source": [ 2401 | "new_set[0] = 4" 2402 | ] 2403 | }, 2404 | { 2405 | "cell_type": "code", 2406 | "execution_count": 23, 2407 | "metadata": {}, 2408 | "outputs": [ 2409 | { 2410 | "name": "stdout", 2411 | "output_type": "stream", 2412 | "text": [ 2413 | "'set' object does not support item assignment\n", 2414 | "Something went wrong with your request.\n" 2415 | ] 2416 | } 2417 | ], 2418 | "source": [ 2419 | "# Try something using the try keyword\n", 2420 | "try: \n", 2421 | " # Run a piece of code which may cause an error\n", 2422 | " new_set[0] = 4\n", 2423 | "\n", 2424 | "# If we have an error, this code below will run\n", 2425 | "except Exception as e:\n", 2426 | " print(e)\n", 2427 | " # Print out something that's a little nicer for the user\n", 2428 | " print('Something went wrong with your request.')" 2429 | ] 2430 | }, 2431 | { 2432 | "cell_type": "markdown", 2433 | "metadata": {}, 2434 | "source": [ 2435 | "# 11. Math" 2436 | ] 2437 | }, 2438 | { 2439 | "cell_type": "code", 2440 | "execution_count": 1, 2441 | "metadata": {}, 2442 | "outputs": [], 2443 | "source": [ 2444 | "# Create two variables\n", 2445 | "math_value_1 = 1235456\n", 2446 | "math_value_2 = 5678914" 2447 | ] 2448 | }, 2449 | { 2450 | "cell_type": "code", 2451 | "execution_count": 4, 2452 | "metadata": {}, 2453 | "outputs": [ 2454 | { 2455 | "data": { 2456 | "text/plain": [ 2457 | "6914370" 2458 | ] 2459 | }, 2460 | "execution_count": 4, 2461 | "metadata": {}, 2462 | "output_type": "execute_result" 2463 | } 2464 | ], 2465 | "source": [ 2466 | "# Addition\n", 2467 | "math_value_1 + math_value_2" 2468 | ] 2469 | }, 2470 | { 2471 | "cell_type": "code", 2472 | "execution_count": 5, 2473 | "metadata": {}, 2474 | "outputs": [ 2475 | { 2476 | "data": { 2477 | "text/plain": [ 2478 | "-4443458" 2479 | ] 2480 | }, 2481 | "execution_count": 5, 2482 | "metadata": {}, 2483 | "output_type": "execute_result" 2484 | } 2485 | ], 2486 | "source": [ 2487 | "# Subtraction \n", 2488 | "math_value_1 - math_value_2 " 2489 | ] 2490 | }, 2491 | { 2492 | "cell_type": "code", 2493 | "execution_count": 11, 2494 | "metadata": {}, 2495 | "outputs": [ 2496 | { 2497 | "data": { 2498 | "text/plain": [ 2499 | "4.596613719954414" 2500 | ] 2501 | }, 2502 | "execution_count": 11, 2503 | "metadata": {}, 2504 | "output_type": "execute_result" 2505 | } 2506 | ], 2507 | "source": [ 2508 | "# Division\n", 2509 | "math_value_2 / math_value_1" 2510 | ] 2511 | }, 2512 | { 2513 | "cell_type": "code", 2514 | "execution_count": 10, 2515 | "metadata": {}, 2516 | "outputs": [ 2517 | { 2518 | "data": { 2519 | "text/plain": [ 2520 | "4" 2521 | ] 2522 | }, 2523 | "execution_count": 10, 2524 | "metadata": {}, 2525 | "output_type": "execute_result" 2526 | } 2527 | ], 2528 | "source": [ 2529 | "# Dividing with the Integral Result\n", 2530 | "math_value_2 // math_value_1" 2531 | ] 2532 | }, 2533 | { 2534 | "cell_type": "code", 2535 | "execution_count": 14, 2536 | "metadata": {}, 2537 | "outputs": [ 2538 | { 2539 | "data": { 2540 | "text/plain": [ 2541 | "737090" 2542 | ] 2543 | }, 2544 | "execution_count": 14, 2545 | "metadata": {}, 2546 | "output_type": "execute_result" 2547 | } 2548 | ], 2549 | "source": [ 2550 | "# Modulus / Modulo\n", 2551 | "math_value_2 % math_value_1" 2552 | ] 2553 | }, 2554 | { 2555 | "cell_type": "code", 2556 | "execution_count": 13, 2557 | "metadata": {}, 2558 | "outputs": [ 2559 | { 2560 | "data": { 2561 | "text/plain": [ 2562 | "737090" 2563 | ] 2564 | }, 2565 | "execution_count": 13, 2566 | "metadata": {}, 2567 | "output_type": "execute_result" 2568 | } 2569 | ], 2570 | "source": [ 2571 | "math_value_2 - math_value_1*4" 2572 | ] 2573 | }, 2574 | { 2575 | "cell_type": "code", 2576 | "execution_count": 15, 2577 | "metadata": {}, 2578 | "outputs": [ 2579 | { 2580 | "data": { 2581 | "text/plain": [ 2582 | "7016048374784" 2583 | ] 2584 | }, 2585 | "execution_count": 15, 2586 | "metadata": {}, 2587 | "output_type": "execute_result" 2588 | } 2589 | ], 2590 | "source": [ 2591 | "# Multiplication\n", 2592 | "math_value_1 * math_value_2" 2593 | ] 2594 | }, 2595 | { 2596 | "cell_type": "code", 2597 | "execution_count": 27, 2598 | "metadata": {}, 2599 | "outputs": [ 2600 | { 2601 | "data": { 2602 | "text/plain": [ 2603 | "1885740153297698816" 2604 | ] 2605 | }, 2606 | "execution_count": 27, 2607 | "metadata": {}, 2608 | "output_type": "execute_result" 2609 | } 2610 | ], 2611 | "source": [ 2612 | "# Power\n", 2613 | "math_value_1 ** 3" 2614 | ] 2615 | }, 2616 | { 2617 | "cell_type": "code", 2618 | "execution_count": 21, 2619 | "metadata": {}, 2620 | "outputs": [ 2621 | { 2622 | "data": { 2623 | "text/plain": [ 2624 | "1212121.79" 2625 | ] 2626 | }, 2627 | "execution_count": 21, 2628 | "metadata": {}, 2629 | "output_type": "execute_result" 2630 | } 2631 | ], 2632 | "source": [ 2633 | "# Round \n", 2634 | "round(1212121.789123456, 2)" 2635 | ] 2636 | }, 2637 | { 2638 | "cell_type": "code", 2639 | "execution_count": 24, 2640 | "metadata": {}, 2641 | "outputs": [ 2642 | { 2643 | "data": { 2644 | "text/plain": [ 2645 | "91123154987978" 2646 | ] 2647 | }, 2648 | "execution_count": 24, 2649 | "metadata": {}, 2650 | "output_type": "execute_result" 2651 | } 2652 | ], 2653 | "source": [ 2654 | "# Absolute Values\n", 2655 | "abs(-91123154987978)" 2656 | ] 2657 | }, 2658 | { 2659 | "cell_type": "code", 2660 | "execution_count": 25, 2661 | "metadata": {}, 2662 | "outputs": [ 2663 | { 2664 | "data": { 2665 | "text/plain": [ 2666 | "121" 2667 | ] 2668 | }, 2669 | "execution_count": 25, 2670 | "metadata": {}, 2671 | "output_type": "execute_result" 2672 | } 2673 | ], 2674 | "source": [ 2675 | "# Minimum - smallest value \n", 2676 | "min(121,8989,1212,5464,8974231,2121)" 2677 | ] 2678 | }, 2679 | { 2680 | "cell_type": "code", 2681 | "execution_count": 26, 2682 | "metadata": {}, 2683 | "outputs": [ 2684 | { 2685 | "data": { 2686 | "text/plain": [ 2687 | "8974231" 2688 | ] 2689 | }, 2690 | "execution_count": 26, 2691 | "metadata": {}, 2692 | "output_type": "execute_result" 2693 | } 2694 | ], 2695 | "source": [ 2696 | "# Maximum\n", 2697 | "max(121,8989,1212,5464,8974231,2121)" 2698 | ] 2699 | }, 2700 | { 2701 | "cell_type": "code", 2702 | "execution_count": 28, 2703 | "metadata": {}, 2704 | "outputs": [], 2705 | "source": [ 2706 | "# Import the math package\n", 2707 | "import math" 2708 | ] 2709 | }, 2710 | { 2711 | "cell_type": "code", 2712 | "execution_count": 29, 2713 | "metadata": {}, 2714 | "outputs": [ 2715 | { 2716 | "data": { 2717 | "text/plain": [ 2718 | "5.0" 2719 | ] 2720 | }, 2721 | "execution_count": 29, 2722 | "metadata": {}, 2723 | "output_type": "execute_result" 2724 | } 2725 | ], 2726 | "source": [ 2727 | "math.sqrt(25)" 2728 | ] 2729 | }, 2730 | { 2731 | "cell_type": "code", 2732 | "execution_count": 30, 2733 | "metadata": {}, 2734 | "outputs": [], 2735 | "source": [ 2736 | "math.sqrt??" 2737 | ] 2738 | } 2739 | ], 2740 | "metadata": { 2741 | "kernelspec": { 2742 | "display_name": "Python 3", 2743 | "language": "python", 2744 | "name": "python3" 2745 | }, 2746 | "language_info": { 2747 | "codemirror_mode": { 2748 | "name": "ipython", 2749 | "version": 3 2750 | }, 2751 | "file_extension": ".py", 2752 | "mimetype": "text/x-python", 2753 | "name": "python", 2754 | "nbconvert_exporter": "python", 2755 | "pygments_lexer": "ipython3", 2756 | "version": "3.7.3" 2757 | } 2758 | }, 2759 | "nbformat": 4, 2760 | "nbformat_minor": 5 2761 | } 2762 | -------------------------------------------------------------------------------- /Variables.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 0. Variables" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 9, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "space_name = 123456.012" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 10, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "123456.012\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "print(space_name)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 11, 39 | "metadata": {}, 40 | "outputs": [ 41 | { 42 | "data": { 43 | "text/plain": [ 44 | "float" 45 | ] 46 | }, 47 | "execution_count": 11, 48 | "metadata": {}, 49 | "output_type": "execute_result" 50 | } 51 | ], 52 | "source": [ 53 | "type(space_name)" 54 | ] 55 | } 56 | ], 57 | "metadata": { 58 | "kernelspec": { 59 | "display_name": "Python 3", 60 | "language": "python", 61 | "name": "python3" 62 | }, 63 | "language_info": { 64 | "codemirror_mode": { 65 | "name": "ipython", 66 | "version": 3 67 | }, 68 | "file_extension": ".py", 69 | "mimetype": "text/x-python", 70 | "name": "python", 71 | "nbconvert_exporter": "python", 72 | "pygments_lexer": "ipython3", 73 | "version": "3.7.4" 74 | } 75 | }, 76 | "nbformat": 4, 77 | "nbformat_minor": 5 78 | } 79 | -------------------------------------------------------------------------------- /helpers.py: -------------------------------------------------------------------------------- 1 | # Function to return launch codes 2 | def launch_codes(): 3 | return 123456789 --------------------------------------------------------------------------------