|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "417c53f3", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + ">>>Cute :3 isn't it ** ?\n", |
| 14 | + "Cute 😚 isn't it 😃 ? \n" |
| 15 | + ] |
| 16 | + } |
| 17 | + ], |
| 18 | + "source": [ |
| 19 | + "#Emoji convertor\n", |
| 20 | + "msg = input(\">>>\")\n", |
| 21 | + "words = msg.split(\" \")\n", |
| 22 | + "emojis={\n", |
| 23 | + " \":)\":\"😊\",\n", |
| 24 | + " \":(\":\"😌\",\n", |
| 25 | + " \";)\":\"😉\",\n", |
| 26 | + " \":o\":\"😮\",\n", |
| 27 | + " \":3\":\"😚\",\n", |
| 28 | + " \"**\":\"😃\"\n", |
| 29 | + "}\n", |
| 30 | + "output = ''\n", |
| 31 | + "for w in words:\n", |
| 32 | + " output += emojis.get(w,w)+\" \"\n", |
| 33 | + "print(output)" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "code", |
| 38 | + "execution_count": 2, |
| 39 | + "id": "6c38c14f", |
| 40 | + "metadata": {}, |
| 41 | + "outputs": [ |
| 42 | + { |
| 43 | + "name": "stdout", |
| 44 | + "output_type": "stream", |
| 45 | + "text": [ |
| 46 | + "Your good name? Sanya\n", |
| 47 | + "Welcome Sanya ! 🙏\n", |
| 48 | + "To quit --> type 'exit'\n", |
| 49 | + "Your good name? exit\n" |
| 50 | + ] |
| 51 | + } |
| 52 | + ], |
| 53 | + "source": [ |
| 54 | + "#Functions --> Reusable lines of code\n", |
| 55 | + "def Greet(name):#name is the Parmeter\n", |
| 56 | + " \n", |
| 57 | + " print(f\"Welcome {name} ! 🙏\")\n", |
| 58 | + " print(\"To quit --> type 'exit'\")\n", |
| 59 | + " \n", |
| 60 | + "while(True):\n", |
| 61 | + " name = input(\"Your good name? \")\n", |
| 62 | + " if name ==\"exit\":\n", |
| 63 | + " break \n", |
| 64 | + " else:\n", |
| 65 | + " Greet(name)# Positional Argument" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "code", |
| 70 | + "execution_count": 7, |
| 71 | + "id": "2edf0ad5", |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "name": "stdout", |
| 76 | + "output_type": "stream", |
| 77 | + "text": [ |
| 78 | + "Welcome Sanya Abhimanu to the company!\n" |
| 79 | + ] |
| 80 | + } |
| 81 | + ], |
| 82 | + "source": [ |
| 83 | + "def Greetings(last_name,fir_name):\n", |
| 84 | + " print(f\"Welcome {fir_name} {last_name} to the company!\")\n", |
| 85 | + " \n", |
| 86 | + " \n", |
| 87 | + "Greetings(fir_name=\"Sanya\",last_name=\"Abhimanu\") #keyword arguments -->Improves readability" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": 12, |
| 93 | + "id": "f1447dc9", |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [ |
| 96 | + { |
| 97 | + "name": "stdout", |
| 98 | + "output_type": "stream", |
| 99 | + "text": [ |
| 100 | + "3\n" |
| 101 | + ] |
| 102 | + } |
| 103 | + ], |
| 104 | + "source": [ |
| 105 | + "def add(a):\n", |
| 106 | + " return a+0\n", |
| 107 | + "\n", |
| 108 | + "print(add(3))" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "code", |
| 113 | + "execution_count": 8, |
| 114 | + "id": "3c8c0b82", |
| 115 | + "metadata": {}, |
| 116 | + "outputs": [ |
| 117 | + { |
| 118 | + "name": "stdout", |
| 119 | + "output_type": "stream", |
| 120 | + "text": [ |
| 121 | + ">>>hey hey ;)\n", |
| 122 | + "hey hey 😉 \n" |
| 123 | + ] |
| 124 | + } |
| 125 | + ], |
| 126 | + "source": [ |
| 127 | + "def emoji_convertor(msg):\n", |
| 128 | + " emojis={\n", |
| 129 | + " \":)\":\"😊\",\n", |
| 130 | + " \":(\":\"😌\",\n", |
| 131 | + " \";)\":\"😉\",\n", |
| 132 | + " \":o\":\"😮\",\n", |
| 133 | + " \":3\":\"😚\",\n", |
| 134 | + " \"**\":\"😃\"\n", |
| 135 | + " }\n", |
| 136 | + " words = msg.split(\" \")\n", |
| 137 | + " output = ''\n", |
| 138 | + " for w in words:\n", |
| 139 | + " output += emojis.get(w,w)+\" \"\n", |
| 140 | + " print(output)\n", |
| 141 | + "\n", |
| 142 | + " \n", |
| 143 | + "msg = input(\">>>\")\n", |
| 144 | + "emoji_convertor(msg)" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 16, |
| 150 | + "id": "24819f30", |
| 151 | + "metadata": {}, |
| 152 | + "outputs": [ |
| 153 | + { |
| 154 | + "name": "stdout", |
| 155 | + "output_type": "stream", |
| 156 | + "text": [ |
| 157 | + "Your age? 0\n", |
| 158 | + "Your age cannot be zero?!\n" |
| 159 | + ] |
| 160 | + } |
| 161 | + ], |
| 162 | + "source": [ |
| 163 | + "#Exception\n", |
| 164 | + "try:\n", |
| 165 | + " age = int(input(\"Your age? \"))\n", |
| 166 | + " risk = 25000/age\n", |
| 167 | + " print(\"You are at risk this month!\")\n", |
| 168 | + "except ValueError:\n", |
| 169 | + " print(\"Invalid input 🙄\")\n", |
| 170 | + "except ZeroDivisionError:\n", |
| 171 | + " print(\"Your age cannot be zero?!\")" |
| 172 | + ] |
| 173 | + }, |
| 174 | + { |
| 175 | + "cell_type": "code", |
| 176 | + "execution_count": 6, |
| 177 | + "id": "b96a397f", |
| 178 | + "metadata": {}, |
| 179 | + "outputs": [ |
| 180 | + { |
| 181 | + "name": "stdout", |
| 182 | + "output_type": "stream", |
| 183 | + "text": [ |
| 184 | + "draw\n", |
| 185 | + "Move\n", |
| 186 | + "10\n" |
| 187 | + ] |
| 188 | + } |
| 189 | + ], |
| 190 | + "source": [ |
| 191 | + "#Classes\n", |
| 192 | + "#Capitalize class name\n", |
| 193 | + "class Point:\n", |
| 194 | + " def move(self):\n", |
| 195 | + " print(\"Move\")\n", |
| 196 | + " def draw(self):\n", |
| 197 | + " print(\"draw\")\n", |
| 198 | + " \n", |
| 199 | + " \n", |
| 200 | + "point1 = Point()\n", |
| 201 | + "#point1 --> object\n", |
| 202 | + "point1.draw()\n", |
| 203 | + "point1.move()\n", |
| 204 | + "point1.x = 10\n", |
| 205 | + "point1.y = 20\n", |
| 206 | + "print(point1.x)" |
| 207 | + ] |
| 208 | + }, |
| 209 | + { |
| 210 | + "cell_type": "code", |
| 211 | + "execution_count": 1, |
| 212 | + "id": "92a0e4d5", |
| 213 | + "metadata": {}, |
| 214 | + "outputs": [ |
| 215 | + { |
| 216 | + "name": "stdout", |
| 217 | + "output_type": "stream", |
| 218 | + "text": [ |
| 219 | + "13\n", |
| 220 | + "20\n" |
| 221 | + ] |
| 222 | + } |
| 223 | + ], |
| 224 | + "source": [ |
| 225 | + "#Constructor\n", |
| 226 | + "class Point:\n", |
| 227 | + " def __init__(self,x,y): #constructor\n", |
| 228 | + " self.x = x\n", |
| 229 | + " self.y = y\n", |
| 230 | + " def move(self):\n", |
| 231 | + " print(\"Move\")\n", |
| 232 | + " def draw(self):\n", |
| 233 | + " print(\"draw\")\n", |
| 234 | + "\n", |
| 235 | + " \n", |
| 236 | + "point = Point(10,20)\n", |
| 237 | + "point.x = 13\n", |
| 238 | + "print(point.x)\n", |
| 239 | + "print(point.y)" |
| 240 | + ] |
| 241 | + }, |
| 242 | + { |
| 243 | + "cell_type": "code", |
| 244 | + "execution_count": 11, |
| 245 | + "id": "2a2ed8c6", |
| 246 | + "metadata": {}, |
| 247 | + "outputs": [ |
| 248 | + { |
| 249 | + "name": "stdout", |
| 250 | + "output_type": "stream", |
| 251 | + "text": [ |
| 252 | + "Hello you, I'm John smith\n", |
| 253 | + "Hello you, I'm Boby smith\n" |
| 254 | + ] |
| 255 | + } |
| 256 | + ], |
| 257 | + "source": [ |
| 258 | + "class Person:\n", |
| 259 | + " def __init__(self,name):\n", |
| 260 | + " self.name=name\n", |
| 261 | + " def talk(self):\n", |
| 262 | + " print(f\"Hello you, I'm {self.name}\")\n", |
| 263 | + "\n", |
| 264 | + "\n", |
| 265 | + "john = Person(\"John smith\")\n", |
| 266 | + "john.talk()\n", |
| 267 | + "\n", |
| 268 | + "bob = Person(\"Boby smith\")\n", |
| 269 | + "bob.talk()" |
| 270 | + ] |
| 271 | + }, |
| 272 | + { |
| 273 | + "cell_type": "code", |
| 274 | + "execution_count": 3, |
| 275 | + "id": "cdaa6fb4", |
| 276 | + "metadata": {}, |
| 277 | + "outputs": [ |
| 278 | + { |
| 279 | + "name": "stdout", |
| 280 | + "output_type": "stream", |
| 281 | + "text": [ |
| 282 | + "Walk\n" |
| 283 | + ] |
| 284 | + } |
| 285 | + ], |
| 286 | + "source": [ |
| 287 | + "#inheritance\n", |
| 288 | + "class Mammal:\n", |
| 289 | + " def walk(self):\n", |
| 290 | + " print(\"Walk\")\n", |
| 291 | + "\n", |
| 292 | + "\n", |
| 293 | + "class Dog(Mammal): #Dog is inheriting Mammal class \n", |
| 294 | + " pass\n", |
| 295 | + "class Cat(Mammal): #Cat is inheriting Mammal class \n", |
| 296 | + " pass\n", |
| 297 | + "\n", |
| 298 | + "cat_1 = Cat()\n", |
| 299 | + "cat_1.walk()" |
| 300 | + ] |
| 301 | + }, |
| 302 | + { |
| 303 | + "cell_type": "code", |
| 304 | + "execution_count": 6, |
| 305 | + "id": "d6f53896", |
| 306 | + "metadata": {}, |
| 307 | + "outputs": [ |
| 308 | + { |
| 309 | + "name": "stdout", |
| 310 | + "output_type": "stream", |
| 311 | + "text": [ |
| 312 | + "{0, 1, 64, 4, 36, 9, 16, 49, 81, 25}\n", |
| 313 | + "False\n", |
| 314 | + "True\n", |
| 315 | + "<class 'set'>\n" |
| 316 | + ] |
| 317 | + } |
| 318 | + ], |
| 319 | + "source": [ |
| 320 | + "#set --> (unordered and unindexed collection of elements)\n", |
| 321 | + "#operations like union, intersection, difference, etc...\n", |
| 322 | + "S = {x**2 for x in range(10)}\n", |
| 323 | + "print(S)\n", |
| 324 | + "\n", |
| 325 | + "print(all(x>0 for x in S))\n", |
| 326 | + "print(any(x>0 for x in S))\n", |
| 327 | + "print(type(S))\n" |
| 328 | + ] |
| 329 | + }, |
| 330 | + { |
| 331 | + "cell_type": "code", |
| 332 | + "execution_count": null, |
| 333 | + "id": "f6e02f3f", |
| 334 | + "metadata": {}, |
| 335 | + "outputs": [], |
| 336 | + "source": [] |
| 337 | + } |
| 338 | + ], |
| 339 | + "metadata": { |
| 340 | + "kernelspec": { |
| 341 | + "display_name": "Python 3 (ipykernel)", |
| 342 | + "language": "python", |
| 343 | + "name": "python3" |
| 344 | + }, |
| 345 | + "language_info": { |
| 346 | + "codemirror_mode": { |
| 347 | + "name": "ipython", |
| 348 | + "version": 3 |
| 349 | + }, |
| 350 | + "file_extension": ".py", |
| 351 | + "mimetype": "text/x-python", |
| 352 | + "name": "python", |
| 353 | + "nbconvert_exporter": "python", |
| 354 | + "pygments_lexer": "ipython3", |
| 355 | + "version": "3.10.2" |
| 356 | + } |
| 357 | + }, |
| 358 | + "nbformat": 4, |
| 359 | + "nbformat_minor": 5 |
| 360 | +} |
0 commit comments