|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## Day 17" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": null, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "markdown", |
| 19 | + "metadata": {}, |
| 20 | + "source": [ |
| 21 | + "## Packages and Modules:\n", |
| 22 | + "packages-- collection of python scripts(.py)\n", |
| 23 | + "module-- a python script" |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "code", |
| 28 | + "execution_count": 12, |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [ |
| 31 | + { |
| 32 | + "name": "stdout", |
| 33 | + "output_type": "stream", |
| 34 | + "text": [ |
| 35 | + "15511210043330985984000000\n", |
| 36 | + "500500\n", |
| 37 | + "123\n", |
| 38 | + "pto\n", |
| 39 | + "None nohtyP\n" |
| 40 | + ] |
| 41 | + } |
| 42 | + ], |
| 43 | + "source": [ |
| 44 | + "from Python_Scripts import test\n", |
| 45 | + "from Python_Scripts.Strings.StringFunction import *\n", |
| 46 | + "from math import floor\n", |
| 47 | + "\n", |
| 48 | + "print(test.factorial(25))\n", |
| 49 | + "print(test.sum(1000))\n", |
| 50 | + "print(floor(123.999))\n", |
| 51 | + "print(StringFunction.alternateCharacters('python'),end = ' ')\n", |
| 52 | + "print(StringFunction.ReverseString('Python'))\n" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "markdown", |
| 57 | + "metadata": {}, |
| 58 | + "source": [ |
| 59 | + "### Regular Expressions:\n", |
| 60 | + "A set of all possible values that satisfy a given\n", |
| 61 | + "\n", |
| 62 | + "[0-9]\n", |
| 63 | + "[a-z]\n", |
| 64 | + "[A-z]\n", |
| 65 | + "\n", |
| 66 | + "^s*" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": 82, |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "name": "stdout", |
| 76 | + "output_type": "stream", |
| 77 | + "text": [ |
| 78 | + "Doesnt Match\n" |
| 79 | + ] |
| 80 | + } |
| 81 | + ], |
| 82 | + "source": [ |
| 83 | + "import re\n", |
| 84 | + "pattern='[a-z]{3,5},[1-9]{2}$'\n", |
| 85 | + "domain='gmail1'\n", |
| 86 | + "if re.match(pattern,domain):\n", |
| 87 | + " print('match')\n", |
| 88 | + "else:\n", |
| 89 | + " print('Doesnt Match')" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "markdown", |
| 94 | + "metadata": {}, |
| 95 | + "source": [ |
| 96 | + "### 3.Postal Code:" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "code", |
| 101 | + "execution_count": 146, |
| 102 | + "metadata": {}, |
| 103 | + "outputs": [ |
| 104 | + { |
| 105 | + "name": "stdout", |
| 106 | + "output_type": "stream", |
| 107 | + "text": [ |
| 108 | + "match 500001\n", |
| 109 | + "\n", |
| 110 | + "Doesnt Match 032311\n", |
| 111 | + "\n", |
| 112 | + "Doesnt Match 342354356\n", |
| 113 | + "\n" |
| 114 | + ] |
| 115 | + } |
| 116 | + ], |
| 117 | + "source": [ |
| 118 | + "import re\n", |
| 119 | + "def Postal(p):\n", |
| 120 | + " pattern='[4-9][0-9]{5}$'\n", |
| 121 | + " domain=p\n", |
| 122 | + " if re.match(pattern,domain):\n", |
| 123 | + " print('match',domain)\n", |
| 124 | + " else:\n", |
| 125 | + " print('Doesnt Match',domain)\n", |
| 126 | + " return ''\n", |
| 127 | + "\n", |
| 128 | + "print(Postal('500001'))\n", |
| 129 | + "print(Postal('032311'))\n", |
| 130 | + "print(Postal('342354356'))" |
| 131 | + ] |
| 132 | + }, |
| 133 | + { |
| 134 | + "cell_type": "code", |
| 135 | + "execution_count": null, |
| 136 | + "metadata": {}, |
| 137 | + "outputs": [], |
| 138 | + "source": [] |
| 139 | + }, |
| 140 | + { |
| 141 | + "cell_type": "markdown", |
| 142 | + "metadata": {}, |
| 143 | + "source": [ |
| 144 | + "### 4.Phone Number:" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 169, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [ |
| 152 | + { |
| 153 | + "name": "stdout", |
| 154 | + "output_type": "stream", |
| 155 | + "text": [ |
| 156 | + "('+91 7644468654', 'match')\n", |
| 157 | + "('452542454', 'Doesnt Match')\n", |
| 158 | + "('+91 98431231229', 'Doesnt Match')\n" |
| 159 | + ] |
| 160 | + } |
| 161 | + ], |
| 162 | + "source": [ |
| 163 | + "import re\n", |
| 164 | + "def PhoneN(p):\n", |
| 165 | + " pattern='[+][9][1][ ][7-9][0-9]{9}$'\n", |
| 166 | + " domain=p\n", |
| 167 | + " if re.match(pattern,domain):\n", |
| 168 | + " return domain,'match'\n", |
| 169 | + " else:\n", |
| 170 | + " return(domain,'Doesnt Match')\n", |
| 171 | + " \n", |
| 172 | + "print(PhoneN('+91 7644468654'))\n", |
| 173 | + "print(PhoneN('452542454'))\n", |
| 174 | + "print(PhoneN('+91 98431231229'))" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "markdown", |
| 179 | + "metadata": {}, |
| 180 | + "source": [ |
| 181 | + "## Problem 5 :\n", |
| 182 | + "## Statement:\n", |
| 183 | + "Define a function to validate email addresses based on the following rules.\n", |
| 184 | + "\n", |
| 185 | + "Email should be in the format [email protected]\n", |
| 186 | + "username must start with an alphabet and can contain lowercase alphabet, digits, hyphen(-) and underscores( _ ).\n", |
| 187 | + "username must not contain special characters, uppercase letters, whitespaces.\n", |
| 188 | + "Length of username must be in the range (6, 16)\n", |
| 189 | + "Domain can only contain lowercase alphabet and digits with length in range (3, 10) . No special characters are allowed\n", |
| 190 | + "Extension can only contain lower case alphabet and its length must be in the range (2, 4)\n", |
| 191 | + "First line of input contains total number of email addresses n. Next n lines contain n email addresses.\n", |
| 192 | + "\n", |
| 193 | + "Output must contain contain n lines with either 'Valid' or 'Invalid'\n", |
| 194 | + "## Test Cases:\n", |
| 195 | + "* Sample Input : 6\n", |
| 196 | + "\n", |
| 197 | + |
| 198 | + "\n", |
| 199 | + |
| 200 | + "\n", |
| 201 | + |
| 202 | + "\n", |
| 203 | + |
| 204 | + "\n", |
| 205 | + |
| 206 | + "\n", |
| 207 | + |
| 208 | + "\n", |
| 209 | + "* Sample Output : Valid\n", |
| 210 | + "\n", |
| 211 | + "Invalid\n", |
| 212 | + "\n", |
| 213 | + "Invalid\n", |
| 214 | + "\n", |
| 215 | + "Invalid\n", |
| 216 | + "\n", |
| 217 | + "Valid\n", |
| 218 | + "\n", |
| 219 | + "Invalid" |
| 220 | + ] |
| 221 | + }, |
| 222 | + { |
| 223 | + "cell_type": "code", |
| 224 | + "execution_count": 173, |
| 225 | + "metadata": {}, |
| 226 | + "outputs": [ |
| 227 | + { |
| 228 | + "name": "stdout", |
| 229 | + "output_type": "stream", |
| 230 | + "text": [ |
| 231 | + "('[email protected]', 'Valid')\n", |
| 232 | + "('[email protected]', 'Valid')\n", |
| 233 | + "('abc [email protected]', 'Invalid')\n" |
| 234 | + ] |
| 235 | + } |
| 236 | + ], |
| 237 | + "source": [ |
| 238 | + "import re\n", |
| 239 | + "def ValidUserName(m):\n", |
| 240 | + " pattern='^[a-zP-Z][A-Za-z0-9_.-]{2,13}[a-z0-9][@][a-z]{3,9}[.][a-z]{2,3}$'\n", |
| 241 | + " if re.match(pattern,m):\n", |
| 242 | + " return m,\"Valid\"\n", |
| 243 | + " else:\n", |
| 244 | + " return m,\"Invalid\"\n", |
| 245 | + "\n", |
| 246 | + "print(ValidUserName('[email protected]'))\n", |
| 247 | + "print(ValidUserName('[email protected]'))\n", |
| 248 | + "print(ValidUserName('abc [email protected]')) " |
| 249 | + ] |
| 250 | + }, |
| 251 | + { |
| 252 | + "cell_type": "code", |
| 253 | + "execution_count": null, |
| 254 | + "metadata": {}, |
| 255 | + "outputs": [], |
| 256 | + "source": [] |
| 257 | + }, |
| 258 | + { |
| 259 | + "cell_type": "markdown", |
| 260 | + "metadata": {}, |
| 261 | + "source": [ |
| 262 | + "## Problem 6 :\n", |
| 263 | + "## Statement: Password Validation\n", |
| 264 | + "* Should contain atlest one uppercase\n", |
| 265 | + "* Length in range (6,21)\n", |
| 266 | + "* Should contain one special character\n", |
| 267 | + "* should start with uppercase or lowercase\n", |
| 268 | + "* Should contain atleast one digit" |
| 269 | + ] |
| 270 | + }, |
| 271 | + { |
| 272 | + "cell_type": "code", |
| 273 | + "execution_count": 18, |
| 274 | + "metadata": {}, |
| 275 | + "outputs": [ |
| 276 | + { |
| 277 | + "name": "stdout", |
| 278 | + "output_type": "stream", |
| 279 | + "text": [ |
| 280 | + "Strong\n", |
| 281 | + "Weak\n", |
| 282 | + "Strong\n" |
| 283 | + ] |
| 284 | + } |
| 285 | + ], |
| 286 | + "source": [ |
| 287 | + " import re\n", |
| 288 | + "def Password(p):\n", |
| 289 | + " #pattern='^[A-Za-z][A-Za-z0-9!@#$%^&*]{5,21}$'\n", |
| 290 | + " if re.match('(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*0-9]).{8,16}$',p):\n", |
| 291 | + " return(\"Strong\")\n", |
| 292 | + " else:\n", |
| 293 | + " return \"Weak\"\n", |
| 294 | + "\n", |
| 295 | + "\n", |
| 296 | + "print(Password('eAf42$#$'))\n", |
| 297 | + "print(Password('hello123'))\n", |
| 298 | + "print(Password('Python123$'))" |
| 299 | + ] |
| 300 | + }, |
| 301 | + { |
| 302 | + "cell_type": "code", |
| 303 | + "execution_count": null, |
| 304 | + "metadata": {}, |
| 305 | + "outputs": [], |
| 306 | + "source": [] |
| 307 | + }, |
| 308 | + { |
| 309 | + "cell_type": "markdown", |
| 310 | + "metadata": {}, |
| 311 | + "source": [ |
| 312 | + "### Iterators \n", |
| 313 | + "Lists,Tupeles,Strings" |
| 314 | + ] |
| 315 | + }, |
| 316 | + { |
| 317 | + "cell_type": "code", |
| 318 | + "execution_count": 223, |
| 319 | + "metadata": {}, |
| 320 | + "outputs": [ |
| 321 | + { |
| 322 | + "name": "stdout", |
| 323 | + "output_type": "stream", |
| 324 | + "text": [ |
| 325 | + "2 4 6 " |
| 326 | + ] |
| 327 | + } |
| 328 | + ], |
| 329 | + "source": [ |
| 330 | + "li = [1,2,3,4,5,6]\n", |
| 331 | + "type(li)\n", |
| 332 | + "it=iter(li)\n", |
| 333 | + "for i in it:\n", |
| 334 | + " print(next(it),end=\" \")\n", |
| 335 | + "\n" |
| 336 | + ] |
| 337 | + }, |
| 338 | + { |
| 339 | + "cell_type": "code", |
| 340 | + "execution_count": null, |
| 341 | + "metadata": {}, |
| 342 | + "outputs": [], |
| 343 | + "source": [] |
| 344 | + }, |
| 345 | + { |
| 346 | + "cell_type": "code", |
| 347 | + "execution_count": 233, |
| 348 | + "metadata": {}, |
| 349 | + "outputs": [ |
| 350 | + { |
| 351 | + "name": "stdout", |
| 352 | + "output_type": "stream", |
| 353 | + "text": [ |
| 354 | + "10 20 30 40 50 60 70 80 90 100 " |
| 355 | + ] |
| 356 | + } |
| 357 | + ], |
| 358 | + "source": [ |
| 359 | + "gn=(i*10 for i in range(1,11))\n", |
| 360 | + "gn\n", |
| 361 | + "for i in gn:\n", |
| 362 | + " print(i,end=\" \")" |
| 363 | + ] |
| 364 | + }, |
| 365 | + { |
| 366 | + "cell_type": "code", |
| 367 | + "execution_count": null, |
| 368 | + "metadata": {}, |
| 369 | + "outputs": [], |
| 370 | + "source": [] |
| 371 | + } |
| 372 | + ], |
| 373 | + "metadata": { |
| 374 | + "kernelspec": { |
| 375 | + "display_name": "Python 3", |
| 376 | + "language": "python", |
| 377 | + "name": "python3" |
| 378 | + }, |
| 379 | + "language_info": { |
| 380 | + "codemirror_mode": { |
| 381 | + "name": "ipython", |
| 382 | + "version": 3 |
| 383 | + }, |
| 384 | + "file_extension": ".py", |
| 385 | + "mimetype": "text/x-python", |
| 386 | + "name": "python", |
| 387 | + "nbconvert_exporter": "python", |
| 388 | + "pygments_lexer": "ipython3", |
| 389 | + "version": "3.7.3" |
| 390 | + } |
| 391 | + }, |
| 392 | + "nbformat": 4, |
| 393 | + "nbformat_minor": 2 |
| 394 | +} |
0 commit comments