├── README.md ├── assignments ├── 001-010 │ └── main.py ├── 010-018 │ └── main.py ├── 018-020 │ └── main.py ├── 021-023 │ └── main.py ├── 024-025 │ └── main.py ├── 026-032 │ └── main.py ├── 033-037 │ └── main.py ├── 038-040 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 041-046 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 047-050 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 051-055 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 056-059 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 060-064 │ ├── 01.py │ ├── 02.py │ └── 03.py ├── 065-068 │ ├── 01.py │ ├── 02.py │ └── 03.py ├── 069-071 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 072-075 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 076-078 │ ├── 01 │ │ └── 01.py │ ├── 02 │ │ ├── Python │ │ │ ├── __pycache__ │ │ │ │ └── my_mod.cpython-310.pyc │ │ │ └── my_mod.py │ │ └── main.py │ ├── 03 │ │ ├── Python │ │ │ ├── __pycache__ │ │ │ │ └── my_mod.cpython-310.pyc │ │ │ └── my_mod.py │ │ └── main.py │ └── 04 │ │ ├── Python │ │ ├── __pycache__ │ │ │ └── my_mod.cpython-310.pyc │ │ └── my_mod.py │ │ └── main.py ├── 079-080 │ ├── 01.py │ └── 02.py ├── 081-085 │ ├── 01.py │ └── 02.py ├── 086-089 │ ├── 01.py │ ├── 02.py │ ├── 03 │ │ ├── elzero-pillow.png │ │ └── main.py │ ├── 04.py │ └── 05 │ │ └── main.py ├── 090-094 │ ├── 01.py │ ├── 02.py │ └── 03.py ├── 095-102 │ └── 01.py └── 096-116 │ ├── 01.py │ ├── 02.py │ ├── 03.py │ ├── 04.py │ ├── 05.py │ └── 06.py └── course ├── 59 └── test.py ├── 118 └── main.py ├── 119 └── main.py ├── 120 └── main.py ├── 121 └── main.py ├── 132 └── main.py ├── 133 └── main.py ├── 134 ├── main.py └── templates │ ├── about.html │ └── home.html ├── 135 ├── main.py └── templates │ ├── about.html │ ├── base.html │ ├── css │ └── main.css │ └── home.html ├── 136 ├── main.py ├── static │ └── css │ │ ├── main.css │ │ └── master.css └── templates │ ├── about.html │ ├── base.html │ └── home.html ├── 137 ├── main.py ├── static │ └── css │ │ └── main.css └── templates │ ├── about.html │ ├── base.html │ └── home.html ├── 138 ├── main.py ├── static │ └── css │ │ └── main.css └── templates │ ├── about.html │ ├── base.html │ ├── home.html │ └── skills.html ├── 139 ├── main.py ├── static │ ├── css │ │ ├── main.css │ │ └── skills.css │ └── js │ │ ├── jquery-3.6.0.min.js │ │ └── main.js └── templates │ ├── about.html │ ├── base.html │ ├── home.html │ └── skills.html ├── 150 └── main.py ├── 078 └── test.py ├── 089 └── test.py └── 118 copy └── main.py /README.md: -------------------------------------------------------------------------------- 1 |
2 | source 3 | 4 | # Elzero Web School 5 | 6 | [Python Course](https://www.youtube.com/watch?v=mvZHDpCHphk&list=PLDoPjvoNmBAyE_gei5d18qkfIe-Z8mocs) 7 | 8 |
9 | 10 | # 006 - Some Data Types Overviews 11 | 12 | `type()` 13 | All Data in Python is Object 14 | 15 | # 009 - Escape Sequences Characters 16 | 17 | `\b` => Back Space 18 | `\newline` => Escape New Line + \ 19 | `\\` => Escape Back Slash 20 | `\'` => Escape Single Quotes 21 | `\"` => Escape Double Quotes 22 | `\n` => Line Feed 23 | `\r` => Carriage Return 24 | `\t` => Horizontal Tab 25 | `\xhh` => Character Hex Value 26 | 27 | # 012 - Strings Indexing And Slicing 28 | 29 | Slicing ( Access Multiple Sequence Items ) 30 | `[Start:End]` End Not Included 31 | `[Start:End:Steps]` 32 | 33 | - `[:0]` => If Start Is Not Here Will Start From 0 34 | - `[0:]` => If End Is Not Here Will Go To The End 35 | - `[:]` => Full Data 36 | - `[::2]` => take index+2 37 | - `[::-1]` => reverse string 38 | 39 | # 013 - Strings Methods Part 1 40 | 41 | - `len()` => to get length of element 42 | 43 | ### trim() equivlent in python 44 | 45 | - `.strip()` => to remove spaces at start and end 46 | - `.rstrip()` => to remove spaces at right 47 | - `.lstrip()` => to remove spaces at left 48 | - u can pass string to remove in bracktes eg. `.rstrip("#")` it will remove hashes from right 49 | 50 | - `.title()` => to capitlize first char and char after digits 51 | - `.captalize()` => to capitlize 52 | 53 | - `.zfill(width)` => to fill string with zero 54 | 55 | - `.upper()` => to capitlize each char 56 | - `.lower()` => to make each char lowercase 57 | 58 | # 014 - Strings Methods Part 2 59 | 60 | - `.split()` => to make each char lowercase by default it split by spaces 61 | -- u can pass which char to split and how may element to split `.split("-",3)` 62 | - `.rsplit()` => to make each char lowercase by default it split by spaces 63 | -- u can pass which char to split and how may element to split from right`.rsplit("-",3)` 64 | - `.center(9)` => to center text between by default it center text between space 65 | -- u can define char to center text between `.center(9,"#")` 66 | - `.count("text")` => to count text in string 67 | -- u can define range to sreach in `.count("text", 0, 25)` 68 | - `.swapcase()` => to swap char case if upper make it lower 69 | - `.startswith("text")` => check if text start with something 70 | -- u can define range to sreach in `.startswith("text", 0, 25)` 71 | - `.endswith("text")` => check if text end with something 72 | -- u can define range to sreach in `.endswith("text", 0, 25)` 73 | 74 | # 015 - Strings Methods Part 3 75 | 76 | - `.index("text")` => to get index of subText in string 77 | -- u can define range `index(SubString, Start, End)` 78 | -- if text dosen't exsist it `return error text not found` 79 | - `.find("text")` => to get index of subText in string 80 | -- u can define range `find(SubString, Start, End)` 81 | -- if text dosen't exsist it return `-1` 82 | - `.rjust(Width, Fill Char)` `.ljust(Width, Fill Char)` => work like center 83 | - `.splitlines()` => return lines in list 84 | - `.expandtabs(2)` => control tab between text 85 | 86 | ### check if text 87 | 88 | - `.istitle()` => 89 | - `.istitle()` => 90 | - `.islower()` => 91 | - `.isidentifier()` => check if string can be variable name 92 | - `.isalpha()` => check if string is a-zA-Z 93 | - `.isalnum()` => check if string is alphapetic or number 94 | 95 | # 016 - Strings Methods Part 4 96 | 97 | - `.replace(Old Value, New Value, Count)` => 98 | - `"#".join(Iterable)` => join items with `#` 99 | 100 | # 017 - Strings Formatting Old Way 101 | 102 | ### placeholder 103 | 104 | - `%s` => String 105 | - `%d` => Number 106 | - `%f` => Float 107 | -- u can control precsion like `%.2f` 108 | 109 | ``` 110 | n = "Osama" 111 | l = "Python" 112 | y = 10 113 | 114 | print("My Name is %s Iam %s Developer With %d Years Exp" % (n, l, y)) 115 | ``` 116 | 117 | ### Truncate String | Slice String 118 | 119 | - `%.5s` => String control number of char to show 120 | 121 | # 018 - Strings Formatting New Ways 122 | 123 | ### placeholder 124 | 125 | - `{:s}` => String 126 | - `{:d}` => Number 127 | -- u can format money every 3 digit by `{:_d}` | `{:,d}` 128 | -- not all special char is vaild eg. `{:&d}` is wrong 129 | - `{:f}` => Float 130 | -- u can control precsion like `{.2f}` 131 | 132 | ``` 133 | n = "Osama" 134 | l = "Python" 135 | y = 10 136 | 137 | print("My Name is {} Iam {} Developer With {:d} Years Exp".format(n, l, y)) 138 | ``` 139 | 140 | ### Truncate String | Slice String 141 | 142 | - `{.5s}` => String control number of char to show 143 | 144 | ### ReArrange Items 145 | 146 | ``` 147 | a, b, c = "One", "Two", "Three" 148 | print("Hello {} {} {}".format(a, b, c)) # Hello One Two Three 149 | print("Hello {2} {0} {1}".format(a, b, c)) # Hello Three One Two 150 | ``` 151 | 152 | ``` 153 | x, y, z = 10, 20, 30 154 | print("Hello {2:.2f} {0:.4f} {1:.5f}".format(x, y, z)) 155 | ``` 156 | 157 | ### Format in Version 3.6+ 158 | 159 | - `f"{VarName}"` 160 | 161 | ``` 162 | myName = "Osama" 163 | myAge = 36 164 | 165 | print("My Name is : {myName} and My Age is : {myAge}") 166 | print(f"My Name is : {myName} and My Age is : {myAge}") 167 | ``` 168 | 169 | # 019 - Numbers 170 | 171 | - `myComplexNumber = 5+6j` 172 | -- `.real` => to print real part of complex 173 | -- `.imag` => to print imaginary part of complex 174 | 175 | - [1] You Can Convert From Int To Float or Complex 176 | - [2] You Can Convert From Float To Int or Complex 177 | - [3] You Cannot Convert Complex To Any Type 178 | 179 | - `float(number)` => to convert number to float 180 | - `complex(number)` => to convert number to complex 181 | - `int(number)` => to convert number to int 182 | 183 | # 020 - Arithmetic Operators 184 | 185 | - `[+]` Addition 186 | - `[-]` Subtraction 187 | - `[*]` Multiplication 188 | - `[/]` Division 189 | - `[%]` Modulus 190 | - `[**]` Exponent 191 | - `[//]` Floor Division 192 | 193 | # 021 - Lists 194 | 195 | - [1] List Items Are Enclosed in Square Brackets 196 | - [2] List Are Ordered, To Use Index To Access Item 197 | - [3] List Are Mutable => Add, Delete, Edit 198 | - [4] List Items Is Not Unique 199 | - [5] List Can Have Different Data Types 200 | 201 | - `list[index]` => to access certin element by index if index grater than length it `return index out of range` 202 | - `list[start:end:step]` => to slice list 203 | - `list[index] = ` => change element value 204 | - `list[start:end:step] = ` => replace slice with lsit ot item 205 | 206 | # 022 - Lists Methods Part 1 207 | 208 | - `a.append(b)` => add element to the end of the list 209 | -- if b is a list it will be added to list a as element `list in list` 210 | - `a.extend(b)` => add list elements to list 211 | - `a.remove(element)` => remove first found element from list a 212 | - `.sort()` => to sort list of same type 213 | -- u can define soert direction by pass reverse to method `.sort(reverse=True)` 214 | - `.reverse()` => reverse list of items 215 | 216 | # 023 - Lists Methods Part 2 217 | 218 | - `.clear()` => clear all items in list 219 | - `.copy()` => make shallow copy of list 220 | -- shallow copy => any change made to original list not applied to shallow copy 221 | -- deep copy => any change made to original list applied to shallow copy 222 | - `.count(item)` => count how many `item` in list 223 | - `.index(item)` => get index of `item` in list 224 | - `.insert(index,item)` => add item to list before given index 225 | - `.pop(index)` => to remove item from given index return value is the deleted item 226 | 227 | # 024 - Tuples And Methods Part 1 228 | 229 | - [1] Tuple Items Are Enclosed in Parentheses 230 | - [2] You Can Remove The Parentheses If You Want 231 | - [3] Tuple Are Ordered, To Use Index To Access Item 232 | - [4] Tuple Are Immutable => You Cant Add or Delete 233 | - [5] Tuple Items Is Not Unique 234 | - [6] Tuple Can Have Different Data Types 235 | - [7] Operators Used in Strings and Lists Available In Tuples 236 | 237 | # 025 - Tuples And Methods Part 2 238 | 239 | - Tuple With One Element 240 | -- to make python know that we have a one element tuple we need to put comma after it 241 | 242 | ``` 243 | myTuple1 = ("Osama",) 244 | myTuple2 = "Osama", 245 | ``` 246 | 247 | - Tuple Concatenation 248 | 249 | ``` 250 | a = (1, 2, 3, 4) 251 | b = (5, 6) 252 | 253 | c = a + b 254 | d = a + ("A", "B", True) + b 255 | ``` 256 | 257 | - Tuple, List, String Repeat (\*) 258 | 259 | ``` 260 | myString = "Osama" 261 | myList = [1, 2] 262 | myTuple = ("A", "B") 263 | 264 | print(myString * 6) 265 | print(myList * 6) 266 | print(myTuple * 6) 267 | ``` 268 | 269 | - Tuple Destruct 270 | -- we use underscore `_` to ignore values 271 | 272 | ``` 273 | a = ("A", "B", 4, "C") 274 | 275 | x, y, _, z = a 276 | ``` 277 | 278 | # 026 - Set 279 | 280 | - [1] Set Items Are Enclosed in Curly Braces 281 | - [2] Set Items Are Not Ordered And Not Indexed 282 | - [3] Set Indexing and Slicing Cant Be Done 283 | - [4] Set Has Only Immutable Data Types (Numbers, Strings, Tuples) List and Dict Are Not 284 | - [5] Set Items Is Unique 285 | 286 | # 027 - Set Methods Part 1 287 | 288 | - `.clear()` 289 | 290 | - `.union()` 291 | 292 | ``` 293 | b = {"One", "Two", "Three"} 294 | c = {"1", "2", "3"} 295 | x = {"Zero", "Cool"} 296 | 297 | print(b | c) 298 | print(b.union(c, x)) 299 | 300 | ``` 301 | 302 | - `.add()` 303 | - `.copy()` 304 | - `.remove()` 305 | 306 | ``` 307 | g = {1, 2, 3, 4} 308 | g.remove(1) 309 | # g.remove(7) 310 | ``` 311 | 312 | - `.discard()` 313 | 314 | ``` 315 | h = {1, 2, 3, 4} 316 | h.discard(1) 317 | h.discard(7) 318 | ``` 319 | 320 | - `.pop()` 321 | - `.update()` 322 | 323 | ``` 324 | j = {1, 2, 3} 325 | k = {1, "A", "B", 2} 326 | j.update(['Html', "Css"]) 327 | j.update(k) 328 | ``` 329 | 330 | # 028 - Set Methods Part 2 331 | 332 | - `a.difference(b)` 333 | -- return diffrence between two tupels 334 | -- equal to `a-b` 335 | 336 | ``` 337 | a = {1, 2, 3, 4} 338 | b = {1, 2, 3, "Osama", "Ahmed"} 339 | print(a.difference(b)) # a - b 340 | ``` 341 | 342 | - `difference_update()` 343 | -- update orgin set to be the diffrence 344 | 345 | ``` 346 | c = {1, 2, 3, 4} 347 | d = {1, 2, "Osama", "Ahmed"} 348 | c.difference_update(d) # c - d 349 | ``` 350 | 351 | - `a.intersection(b)` 352 | -- return similar items between tupels 353 | -- equal to `a & b` 354 | 355 | ``` 356 | e = {1, 2, 3, 4, "X", "Osama"} 357 | f = {"Osama", "X", 2} 358 | print(e.intersection(f)) # e & f 359 | ``` 360 | 361 | - `a.intersection_update(b)` 362 | -- update orgin set to be the similar items between tupels 363 | 364 | ``` 365 | g = {1, 2, 3, 4, "X", "Osama"} 366 | h = {"Osama", "X", 2} 367 | g.intersection_update(h) # g & h 368 | ``` 369 | 370 | - `a.symmetric_difference(b)` 371 | -- return items not exsist in a and b 372 | -- equal to `a ^ b` 373 | 374 | ``` 375 | i = {1, 2, 3, 4, 5, "X"} 376 | j = {"Osama", "Zero", 1, 2, 4, "X"} 377 | print(i.symmetric_difference(j)) # i ^ j 378 | ``` 379 | 380 | - `a.symmetric_difference_update(b)` 381 | -- update orgin set to be items not exsist in a and b 382 | 383 | ``` 384 | i = {1, 2, 3, 4, 5, "X"} 385 | j = {"Osama", "Zero", 1, 2, 4, "X"} 386 | k.symmetric_difference_update(l) # k ^ l 387 | ``` 388 | 389 | # 029 - Set Methods Part 3 390 | 391 | - `a.issuperset(b)` 392 | -- check if a is superset of b or all element in b exsist in a 393 | - `a.issubset(b)` 394 | -- check if a is subset of b or all element in a exsist in b 395 | - `a.isdisjoint(b)` 396 | -- check if all items in a is diffrent from all items in b 397 | 398 | ``` 399 | g = {1, 2, 3, 4} 400 | h = {1, 2, 3} 401 | i = {10, 11, 12} 402 | 403 | print(g.isdisjoint(h)) # False 404 | print(g.isdisjoint(i)) # True 405 | ``` 406 | 407 | # 030 - Dictionary 408 | 409 | - [1] Dict Items Are Enclosed in Curly Braces 410 | - [2] Dict Items Are Contains Key : Value 411 | - [3] Dict Key Need To Be Immutable => (Number, String, Tuple) List Not Allowed 412 | - [4] Dict Value Can Have Any Data Types 413 | - [5] Dict Key Need To Be Unique 414 | -- if there is repeated key the last one will applied 415 | - [6] Dict Is Not Ordered You Access Its Element With Key 416 | 417 | - Accessing values 418 | -- `dic[key]` 419 | -- `dic.get(key)` 420 | -- `dic.keys` => get all key 421 | -- `dic.values` => get all values 422 | 423 | ``` 424 | user = { 425 | "name": "Osama", 426 | "age": 36, 427 | "country": "Egypt", 428 | "skills": ["Html", "Css", "JS"], 429 | "rating": 10.5 430 | } 431 | 432 | print(user) 433 | print(user['country']) 434 | print(user.get("country")) 435 | ``` 436 | 437 | - Two-Dimensional Dictionary 438 | 439 | ``` 440 | languages = { 441 | "One": { 442 | "name": "Html", 443 | "progress": "80%" 444 | }, 445 | "Two": { 446 | "name": "Css", 447 | "progress": "90%" 448 | }, 449 | "Three": { 450 | "name": "Js", 451 | "progress": "90%" 452 | } 453 | } 454 | 455 | print(languages) 456 | print(languages['One']) 457 | print(languages['Three']['name']) 458 | ``` 459 | 460 | - `len(dic)` => to get the length of dictionary 461 | 462 | # 031 - Dictionary Methods Part 1 463 | 464 | - `.clear()` 465 | - `.update({"key": value})` => add new item 466 | -- u can do the same with `dic[newkey] = newValue` 467 | - `.copy()` 468 | - `.keys()` => return all keys 469 | - `.values()` => return all values 470 | 471 | # 032 - Dictionary Methods Part 2 472 | 473 | - `a.setdefault(key,value)` 474 | -- get value of key and assign default value if key not exist in dictionary 475 | -- if default value not set and key not exsist it return `none` 476 | 477 | - `.popitem()` 478 | -- return the last added number 479 | -- before v3 it was returning random item 480 | 481 | - `.items()` => retun all items in tupels `(key,value)` 482 | 483 | - `fromkeys(iterable,value)` 484 | 485 | ``` 486 | a = ('MyKeyOne', 'MyKeyTwo', 'MyKeyThree') 487 | b = "X" 488 | 489 | print(dict.fromkeys(a, b)) 490 | ``` 491 | 492 | # 033 - Boolean 493 | 494 | - [1] In Programming You Need to Known Your If Your Code Output is True Or False 495 | - [2] Boolean Values Are The Two Constant Objects False + True. 496 | - all empty object are false `[]` | `()` | `{}` |`""` 497 | 498 | # 034 - Boolean Operators 499 | 500 | - and 501 | - or 502 | - not 503 | 504 | # 035 - Assignment Operators 505 | 506 | - `=` => 507 | - `+=` => 508 | - `-=` => 509 | - `*=` => 510 | - `/=` => 511 | - `**=` => 512 | - `%=` => 513 | - `//=` => 514 | 515 | # 036 - Comparison Operators 516 | 517 | - [ == ] Equal 518 | - [ != ] Not Equal 519 | - [ > ] Greater Than 520 | - [ < ] Less Than 521 | - [ >= ] Greater Than Or Equal 522 | - [ <= ] Less Than Or Equal 523 | 524 | # 037 - Type Converstion 525 | 526 | - `str()` 527 | - `tuple()` 528 | - `list()` 529 | - `set()` 530 | - `dict()` => required list or tuple to be nested with keys and values like 531 | `(("A",1),("B",6),("C",5))` => Tuples 532 | `[["A",1],["B",6],["C",5]]` => Lists 533 | `{{"A",1},{"B",6},{"C",5}}` => Sets 534 | 535 | # 038 - User Input 536 | 537 | - `input(msg)` => to get input from user 538 | 539 | ``` 540 | fName = input('What\'s Is Your First Name?') 541 | ``` 542 | 543 | # 041 - Control Flow - If, Elif, Else 544 | 545 | - `If, Elif, Else` 546 | 547 | # 043 - Control Flow - Ternary Conditional Operator 548 | 549 | - ` Condition If True | If Condition | Else | Condition If False` 550 | 551 | ``` 552 | print("Movie S Not Good 4U" if age < movieRate else "Movie S Good 4U And Happy Watching") 553 | ``` 554 | 555 | # 045 - Membership Operators 556 | 557 | - `thing in somethings` => check if thing is included in somethings 558 | - `not in` => check if thing is not included in somethings 559 | 560 | # 047 - Loop – While and Else 561 | 562 | - `while` 563 | -- u can use `break` to stop loop 564 | 565 | ``` 566 | # while condition_is_true 567 | # Code Will Run Until Condition Become False 568 | # don't forget to put something that end loop 569 | # else: 570 | # When the ondition_is_false 571 | ``` 572 | 573 | # 051 - Loop – For and Else 574 | 575 | - `For` 576 | 577 | ``` 578 | # for item in iterable_object : 579 | # Do Something With Item 580 | # else: 581 | # loop is finished 582 | ``` 583 | 584 | - item Is A Vairable You Create and Call Whenever You Want 585 | - item refer to the current position and will run and visit all items to the end 586 | - iterable_object => Sequence [ list, tuples, set, dict, string of charcaters, etc ... ] 587 | 588 | # 054 - Break Continue Pass 589 | 590 | - `continue` => stop current iteration and go to the next one 591 | - `break` => stop iteration 592 | - `pass` => to use it in empty block which will be implimented later 593 | 594 | # 056 - Function and Return 595 | 596 | - [1] A Function is A Reusable Block Of Code Do A Task 597 | - [2] A Function Run When You Call It 598 | - [3] A Function Accept Element To Deal With Called [Parameters] 599 | - [4] A Function Can Do The Task Without Returning Data 600 | - [5] A Function Can Return Data After Job is Finished 601 | - [6] A Function Create To Prevent DRY 602 | - [7] A Function Accept Elements When You Call It Called [Arguments] 603 | - [8] There's A Built-In Functions and User Defined Functions 604 | - [9] A Function Is For All Team and All Apps 605 | 606 | # 058 - Function Packing, Unpacking Arguments 607 | 608 | - must be last param in function arguments if there another argument 609 | 610 | ``` 611 | # define 612 | def say_hello(*peoples): # n1, n2, n3, n4 613 | 614 | for name in peoples: 615 | 616 | print(f"Hello {name}") 617 | 618 | # call 619 | say_hello("Osama", "Ahmed", "Sayed", "Mahmoud") 620 | ``` 621 | 622 | # 059 - Function Default Parameters 623 | 624 | - It can be done by assign values to arguments 625 | - Only in last arguments or all arguments 626 | 627 | # 060 - Function Packing Unpacking Keyword 628 | 629 | - Function Packing, Unpacking Arguments `**KWArgs` 630 | 631 | ``` 632 | def show_skills(*skills): 633 | 634 | print(type(skills)) 635 | 636 | for skill in skills: 637 | 638 | print(f"{skill}") 639 | 640 | show_skills("Html", "CSS", "JS") 641 | 642 | mySkills = { 643 | 'Html': "80%", 644 | 'Css': "70%", 645 | 'Js': "50%", 646 | 'Python': "80%", 647 | "Go": "40%" 648 | } 649 | 650 | def show_skills(**skills): 651 | 652 | print(type(skills)) 653 | 654 | for skill, value in skills.items(): 655 | 656 | print(f"{skill} => {value}") 657 | 658 | show_skills(**mySkills) 659 | ``` 660 | 661 | # 061 - Function Packing Unpacking Arguments 662 | 663 | - `**` => to unpack dictionary 664 | - `*` => to unpack tupels 665 | 666 | # 062 - Function Scope 667 | 668 | - to make local var gloabal we use `global var` 669 | 670 | # 063 - Function Recursion 671 | 672 | - To Understand Recursion, You Need to First Understand Recursion 673 | - A function that it call it self 674 | 675 | ``` 676 | # Test Word [ WWWoooorrrldd ] # print(x[1:]) 677 | 678 | def cleanWord(word): 679 | 680 | if len(word) == 1: 681 | 682 | return word 683 | 684 | print(f"Print Start Function {word}") 685 | 686 | if word[0] == word[1]: 687 | 688 | print(f"Print Before Condition {word}") 689 | 690 | return cleanWord(word[1:]) 691 | 692 | print(f"Print Before Return {word}") 693 | 694 | return word[0] + cleanWord(word[1:]) 695 | 696 | # Stash [ World ] 697 | 698 | print(cleanWord("WWWoooorrrldd")) 699 | ``` 700 | 701 | # 064 - Function Lambda 702 | 703 | - Anonymous Function 704 | - [1] It Has No Name 705 | - [2] You Can Call It Inline Without Defining It 706 | - [3] You Can Use It In Return Data From Another Function 707 | - [4] Lambda Used For Simple Functions and Def Handle The Large Tasks 708 | - [5] Lambda is One Single Expression not Block Of Code 709 | - [6] Lambda Type is Function 710 | 711 | ``` 712 | def say_hello(name, age) : return f"Hello {name} your Age Is: {age}" 713 | print(say_hello("Ahmed", 36)) 714 | ``` 715 | 716 | ``` 717 | hello = lambda name, age : f"Hello {name} your Age Is: {age}" 718 | print(hello("Ahmed", 36)) 719 | ``` 720 | 721 | - U can get method or function name by using `__name__` 722 | 723 | # 065 - Files Handling – Part 1 Intro 724 | 725 | - file modes 726 | -- `"a"` Append Open File For Appending Values, Create File If Not Exists 727 | -- `"r"` Read [Default Value] Open File For Read and Give Error If File is Not Exists 728 | -- `"w"` Write Open File For Writing, Create File If Not Exists 729 | -- `"x"` Create Create File, Give Error If File Exists 730 | 731 | - `open(path,mode)` 732 | - path can be relative or absolute 733 | - mode can be any from above 734 | 735 | ``` 736 | import os 737 | 738 | # Main Current Working Directory 739 | print(os.getcwd()) 740 | 741 | # Directory For The Opened File 742 | print(os.path.dirname(os.path.abspath(__file__))) 743 | 744 | # Change Current Working Directory 745 | os.chdir(os.path.dirname(os.path.abspath(__file__))) 746 | 747 | print(os.getcwd()) 748 | 749 | print(os.path.abspath(__file__)) 750 | 751 | file = open(r"D:\Python\Files\nfiles\osama.txt") 752 | 753 | file = open("D:\Python\Files\osama.txt") 754 | ``` 755 | 756 | - To make string ignore every special char and make it a raw string u must put `r` before quotes `r"this is raw text and this \n won't work"` 757 | 758 | # 066 - Files Handling Part 2 Read Files 759 | 760 | - By default when print file it give u data about it not the containing content 761 | 762 | ``` 763 | myFile = open("D:\Python\Files\osama.txt", "r") 764 | 765 | print(myFile) # File Data Object 766 | ``` 767 | 768 | - U can access certin data like that 769 | 770 | ``` 771 | print(myFile.name) 772 | print(myFile.mode) 773 | print(myFile.encoding) 774 | ``` 775 | 776 | - To read content use `read()` 777 | -- u can define bytes to read 778 | -- by default bytes is set to `-1` mean get all content 779 | 780 | ``` 781 | print(myFile.read()) 782 | print(myFile.read(5)) 783 | ``` 784 | 785 | - `readline()` used to get content from line 786 | -- u can specify bytes to read from this line 787 | -- if u called it again it will read the next line 788 | 789 | ``` 790 | print(myFile.readline(5)) 791 | print(myFile.readline()) 792 | print(myFile.readline()) 793 | 794 | print(myFile.readlines()) 795 | print(myFile.readlines(50)) 796 | ``` 797 | 798 | - `readlines` to get all lines as a list 799 | 800 | ``` 801 | print(type(myFile.readlines())) 802 | 803 | for line in myFile: 804 | 805 | print(line) 806 | 807 | if line.startswith("07"): 808 | 809 | break 810 | 811 | ``` 812 | 813 | - Best paractise is to close file after finishing ur stuff 814 | 815 | ``` 816 | # Close The File 817 | 818 | myFile.close() 819 | ``` 820 | 821 | # 067 - Files Handling Part 3 Write and Append In Files 822 | 823 | ``` 824 | myFile = open("D:\Python\Files\osama.txt", "w") 825 | myFile.write("Hello\n") 826 | myFile.write("Third Line") 827 | 828 | myFile = open(r"D:\Python\Files\fun.txt", "w") 829 | myFile.write("Elzero Web School\n" * 1000) 830 | 831 | myList = ["Oasma\n", "Ahmed\n", "Sayed\n"] 832 | 833 | myFile = open("D:\Python\Files\osama.txt", "w") 834 | myFile.writelines(myList) 835 | 836 | myFile = open("D:\Python\Files\osama.txt", "a") 837 | myFile.write("Elzero") 838 | ``` 839 | 840 | # 068 - Files Handling – Part 4 Important Info 841 | 842 | - `truncate(bytes)` => 843 | 844 | ``` 845 | myFile = open("D:\Python\Files\osama.txt", "a") 846 | myFile.truncate(5) 847 | ``` 848 | 849 | - `tell()` => get cursor postion 850 | -- new line in windows calculate as two bytes 851 | 852 | ``` 853 | myFile = open("D:\Python\Files\osama.txt", "a") 854 | print(myFile.tell()) 855 | ``` 856 | 857 | - `seek(bytes)` => set cursor postion 858 | 859 | ``` 860 | myFile = open("D:\Python\Files\osama.txt", "r") 861 | myFile.seek(11) 862 | print(myFile.read()) 863 | ``` 864 | 865 | - `remove(path)` => remove 866 | 867 | ``` 868 | os.remove("D:\Python\Files\osama.txt") 869 | ``` 870 | 871 | # 069 - Built In Functions Part 1 872 | 873 | - `all(iterable)` => Check if all items in iterable are true then return true 874 | - `any(iterable)` => Check if any item in iterable are true then return true 875 | - `bin(5532)` => Convert to binary 876 | - `id(var)` => Get id or iddress of var in memory 877 | 878 | # 070 - Built In Functions Part 2 879 | 880 | - `sum(iterable,start)` => Get sum of all items in iterable 881 | - `round(num,percision = 0)` => Round flaoting number 882 | - `range(start = 0,end,step = 1)` => Get range of number 883 | - `print()` => print to console 884 | -- `sep=" "` => to define separtor between text when there is too many args to be printed by default it's add space 885 | -- `end="\n"` => to define end of text by default it add new ;ine 886 | 887 | # 071 - Built In Functions Part 3 888 | 889 | - `abs()` => get the absolute value of number 890 | - `pow(number,exponent)` => equal to `number**exp` 891 | - `min(iteratable)` => Get min from list 892 | - `max(iteratable)` => Get max value from list 893 | - `a[slice(start,end ,step)]` => Same as `a[start:end:stop]` but stop must write 894 | 895 | # 072 - Built In Functions Part 4 – Map 896 | 897 | - [1] Map Take A Function + Iterator 898 | - [2] Map Called Map Because It Map The Function On Every Element 899 | - [3] The Function Can Be Pre-Defined Function or Lambda Function 900 | 901 | - Use Map With Predefined Function 902 | 903 | ``` 904 | def formatText(text): 905 | 906 | return f"- {text.strip().capitalize()} -" 907 | 908 | myTexts = [" OSama ", "AHMED", " sAYed "] 909 | 910 | myFormatedData = map(formatText, myTexts) 911 | 912 | print(myFormatedData) 913 | 914 | for name in list(map(formatText, myTexts)): 915 | 916 | print(name) 917 | 918 | print("#" * 50) 919 | ``` 920 | 921 | - Use Map With Lambda Function 922 | 923 | ``` 924 | def formatText(text): 925 | 926 | return f"- {text.strip().capitalize()} -" 927 | 928 | myTexts = [" OSama ", "AHMED", " sAYed "] 929 | 930 | for name in list(map((lambda text: f"- {text.strip().capitalize()} -"), myTexts)): 931 | 932 | print(name) 933 | ``` 934 | 935 | # 073 - Built In Functions Part 5 – Filter 936 | 937 | - [1] Filter Take A Function + Iterator 938 | - [2] Filter Run A Function On Every Element 939 | - [3] The Function Can Be Pre-Defined Function or Lambda Function 940 | - [4] Filter Out All Elements For Which The Function Return True 941 | - [5] The Function Need To Return Boolean Value 942 | 943 | - Example 1 944 | 945 | ``` 946 | def checkNumber(num): 947 | 948 | return num > 10 949 | 950 | myNumbers = [0, 0, 1, 19, 10, 20, 100, 5, 0] 951 | 952 | myResult = filter(checkNumber, myNumbers) 953 | 954 | for number in myResult: 955 | 956 | print(number) 957 | 958 | print("#" * 50) 959 | ``` 960 | 961 | - Example 2 962 | 963 | ``` 964 | def checkName(name): 965 | 966 | return name.startswith("O") 967 | 968 | myTexts = ["Osama", "Omer", "Omar", "Ahmed", "Sayed", "Othman"] 969 | 970 | myReturnedData = filter(checkName, myTexts) 971 | 972 | for person in myReturnedData: 973 | 974 | print(person) 975 | 976 | print("#" * 50) 977 | ``` 978 | 979 | - Example 3 980 | 981 | ``` 982 | myNames = ["Osama", "Omer", "Omar", "Ahmed", "Sayed", "Othman", "Ameer"] 983 | 984 | for p in filter(lambda name: name.startswith("A"), myNames): 985 | 986 | print(p) 987 | ``` 988 | 989 | # 074 - Built In Functions Part 6 – Reduce 990 | 991 | - [1] Reduce Take A Function + Iterator 992 | - [2] Reduce Run A Function On FIrst and Second Element And Give Result 993 | - [3] Then Run Function On Result And Third Element 994 | - [4] Then Run Function On Rsult And Fourth Element And So On 995 | - [5] Till One ELement is Left And This is The Result of The Reduce 996 | - [6] The Function Can Be Pre-Defined Function or Lambda Function 997 | 998 | ``` 999 | from functools import reduce 1000 | 1001 | def sumAll(num1, num2): 1002 | 1003 | return num1 + num2 1004 | 1005 | numbers = [1, 8, 2, 9, 100] 1006 | 1007 | result = reduce(sumAll, numbers) 1008 | 1009 | result = reduce(lambda num1, num2: num1 + num2, numbers) 1010 | 1011 | print(result) 1012 | 1013 | # ((((1 + 8) + 2) + 9) + 100) 1014 | ``` 1015 | 1016 | # 075 - Built In Functions Part 7 1017 | 1018 | - `enumerate(iterable, start=0)` => add counter to itertable 1019 | 1020 | ``` 1021 | mySkills = ["Html", "Css", "Js", "PHP"] 1022 | 1023 | mySkillsWithCounter = enumerate(mySkills, 20) 1024 | 1025 | print(type(mySkillsWithCounter)) 1026 | 1027 | for counter, skill in mySkillsWithCounter: 1028 | 1029 | print(f"{counter} - {skill}") 1030 | 1031 | print("#" * 50) 1032 | ``` 1033 | 1034 | - `help()` => Get the manual of any function in python 1035 | 1036 | ``` 1037 | print(help(print)) 1038 | 1039 | print("#" * 50) 1040 | ``` 1041 | 1042 | - `reversed(iterable)` => Return reversed oreder iteratable 1043 | 1044 | ``` 1045 | myString = "Elzero" 1046 | 1047 | print(reversed(myString)) 1048 | 1049 | for letter in reversed(myString): 1050 | 1051 | print(letter) 1052 | 1053 | for s in reversed(mySkills): 1054 | 1055 | print(s) 1056 | ``` 1057 | 1058 | # 076 - Modules Part 1 - Intro And Built In Modules 1059 | 1060 | - [1] Module is A File Contain A Set Of Functions 1061 | - [2] You Can Import Module in Your App To Help You 1062 | - [3] You Can Import Multiple Modules 1063 | - [4] You Can Create Your Own Modules 1064 | - [5] Modules Saves Your Time 1065 | 1066 | - Import Main Module 1067 | 1068 | ``` 1069 | import random 1070 | print(random) 1071 | print(f"Print Random Float Number {random.random()}") 1072 | ``` 1073 | 1074 | - Show All Functions Inside Module 1075 | 1076 | ``` 1077 | print(dir(random)) 1078 | ``` 1079 | 1080 | - Import One Or Two Functions From Module 1081 | 1082 | ``` 1083 | from random import randint, random 1084 | print(f"Print Random Float {random()}") 1085 | print(f"Print Random Integer {randint(100, 900)}") 1086 | ``` 1087 | 1088 | # 077 - Modules – Part 2 – Create Your Module 1089 | 1090 | - Add path to import module from 1091 | 1092 | ``` 1093 | import sys 1094 | sys.path.append(r"D:\Games") 1095 | print(sys.path) 1096 | ``` 1097 | 1098 | - Import ur own module and use it 1099 | -- `dir(module)` => to list all method included 1100 | 1101 | ``` 1102 | import elzero 1103 | print(dir(elzero)) 1104 | 1105 | elzero.sayHello("Ahmed") 1106 | 1107 | elzero.sayHowAreYou("Ahmed") 1108 | ``` 1109 | 1110 | - Alias => give ur module shorten name or an alias 1111 | -- can be make to module name or function in it 1112 | 1113 | ``` 1114 | import elzero as ee 1115 | 1116 | ee.sayHello("Ahmed") 1117 | 1118 | ee.sayHowAreYou("Ahmed") 1119 | ``` 1120 | 1121 | ``` 1122 | from elzero import sayHello 1123 | 1124 | sayHello("Osama") 1125 | 1126 | from elzero import sayHello as ss 1127 | 1128 | ss("Osama") 1129 | ``` 1130 | 1131 | - To solve problem of import in vscode `cntrl`+`shift`+`P` 1132 | -- open `settings` json file 1133 | -- add `"python.autocomplete.extraPaths":["path"]` 1134 | 1135 | # 078 - Modules – Part 3 – Install External Packages 1136 | 1137 | - [1] Module vs Package 1138 | - [2] External Packages Downloaded From The Internet 1139 | - [3] You Can Install Packages With Python Package Manager PIP 1140 | - [4] PIP Install the Package and Its Dependencies 1141 | - [5] Modules List "https://docs.python.org/3/py-modindex.html" 1142 | - [6] Packages and Modules Directory "https://pypi.org/" 1143 | - [7] PIP Manual "https://pip.pypa.io/en/stable/reference/pip_install/" 1144 | 1145 | - `pip --version` => To check if `pip` is installed 1146 | - `pip list` => List all installed packages or modules and its version 1147 | - `pip install pakageName` => Install package or module 1148 | -- u can write all pakages `pip install pakageName01 pakageName02 pakageName03 ...` 1149 | -- `packName==versio` => Specify certin version 1150 | -- `packName>=versio` => Specify any version above this version 1151 | 1152 | - `pyfiglet` => String to ASCI art 1153 | - `termcolor` => Color string in console 1154 | 1155 | ``` 1156 | import termcolor 1157 | import pyfiglet 1158 | 1159 | print(dir(pyfiglet)) 1160 | print(pyfiglet.figlet_format("Elzero")) 1161 | print(termcolor.colored("Elzero", color="yellow")) 1162 | 1163 | print(termcolor.colored(pyfiglet.figlet_format("Elzero"), color="yellow")) 1164 | ``` 1165 | 1166 | # 079 - Date And Time Introduction 1167 | 1168 | ``` 1169 | import datetime 1170 | ``` 1171 | 1172 | ``` 1173 | # print(dir(datetime)) 1174 | # print(dir(datetime.datetime)) 1175 | ``` 1176 | 1177 | ``` 1178 | # Print The Current Date and Time 1179 | print(datetime.datetime.now()) 1180 | 1181 | print("#" * 40) 1182 | 1183 | # Print The Current Year 1184 | print(datetime.datetime.now().year) 1185 | 1186 | # Print The Current Month 1187 | print(datetime.datetime.now().month) 1188 | 1189 | # Print The Current Day 1190 | print(datetime.datetime.now().day) 1191 | 1192 | print("#" * 40) 1193 | ``` 1194 | 1195 | - Print Start and End Of Date 1196 | 1197 | ``` 1198 | print(datetime.datetime.min) 1199 | print(datetime.datetime.max) 1200 | 1201 | print("#" * 40) 1202 | 1203 | # print(dir(datetime.datetime.now())) 1204 | ``` 1205 | 1206 | - Print The Current Time 1207 | 1208 | ``` 1209 | print(datetime.datetime.now().time()) 1210 | 1211 | print("#" * 40) 1212 | ``` 1213 | 1214 | - Print The Current Time Hour 1215 | 1216 | ``` 1217 | print(datetime.datetime.now().time().hour) 1218 | ``` 1219 | 1220 | - Print The Current Time Minute 1221 | 1222 | ``` 1223 | print(datetime.datetime.now().time().minute) 1224 | ``` 1225 | 1226 | - Print The Current Time Second 1227 | 1228 | ``` 1229 | print(datetime.datetime.now().time().second) 1230 | 1231 | print("#" * 40) 1232 | ``` 1233 | 1234 | - Print Start and End Of Time 1235 | 1236 | ``` 1237 | print(datetime.time.min) 1238 | print(datetime.time.max) 1239 | 1240 | print("#" * 40) 1241 | ``` 1242 | 1243 | - Print Specific Date 1244 | 1245 | ``` 1246 | print(datetime.datetime(1982, 10, 25)) 1247 | print(datetime.datetime(1982, 10, 25, 10, 45, 55, 150364)) 1248 | ``` 1249 | 1250 | ``` 1251 | myBirthDay = datetime.datetime(1982, 10, 25) 1252 | dateNow = datetime.datetime.now() 1253 | 1254 | print(f"My Birthday is {myBirthDay} And ", end="") 1255 | print(f"Date Now Is {dateNow}") 1256 | 1257 | print(f" I Lived For {dateNow - myBirthDay}") 1258 | print(f" I Lived For {(dateNow - myBirthDay).days} Days.") 1259 | ``` 1260 | 1261 | # 080 - Date And Time Format Date 1262 | 1263 | - https://strftime.org/ 1264 | 1265 | ``` 1266 | import datetime 1267 | ``` 1268 | 1269 | ``` 1270 | myBirthday = datetime.datetime(1982, 10, 25) 1271 | 1272 | print(myBirthday) 1273 | print(myBirthday.strftime("%a")) 1274 | print(myBirthday.strftime("%A")) 1275 | print(myBirthday.strftime("%b")) 1276 | print(myBirthday.strftime("%B")) 1277 | 1278 | print(myBirthday.strftime("%d %B %Y")) 1279 | print(myBirthday.strftime("%d, %B, %Y")) 1280 | print(myBirthday.strftime("%d/%B/%Y")) 1281 | print(myBirthday.strftime("%d - %B - %Y")) 1282 | print(myBirthday.strftime("%B - %Y")) 1283 | 1284 | ``` 1285 | 1286 | # 081 - Iterable Vs Iterator 1287 | 1288 | - Iterable 1289 | -- [1] Object Contains Data That Can Be Iterated Upon 1290 | -- [2] Examples (String, List, Set, Tuple, Dictionary) 1291 | 1292 | - Iterator 1293 | -- [1] Object Used To Iterate Over Iterable Using next() Method Return 1 Element At A Time 1294 | -- [2] You Can Generate Iterator From Iterable When Using iter() Method 1295 | -- [3] For Loop Already Calls iter() Method on The Iterable Behind The Scene 1296 | -- [4] Gives "StopIteration" If Theres No Next Element 1297 | 1298 | ``` 1299 | myString = "Osama" 1300 | 1301 | myList = [1, 2, 3, 4, 5] 1302 | 1303 | for letter in myString: 1304 | 1305 | print(letter, end=" ") 1306 | 1307 | for number in myList: 1308 | 1309 | print(number, end=" ") 1310 | 1311 | myIterator = iter(myString) 1312 | 1313 | print(next(myIterator)) 1314 | print(next(myIterator)) 1315 | print(next(myIterator)) 1316 | print(next(myIterator)) 1317 | print(next(myIterator)) 1318 | print(next(myIterator)) 1319 | 1320 | for letter in iter("Elzero"): 1321 | 1322 | print(letter, end=" ") 1323 | ``` 1324 | 1325 | # 082 - Generators 1326 | 1327 | - [1] Generator is a Function With "yield" Keyword Instead of "return" 1328 | - [2] It Support Iteration and Return Generator Iterator By Calling "yield" 1329 | - [3] Generator Function Can Have one or More "yield" 1330 | - [4] By Using next() It Resume From Where It Called "yield" Not From Begining 1331 | - [5] When Called, Its Not Start Automatically, Its Only Give You The Control 1332 | 1333 | ``` 1334 | def myGenerator(): 1335 | yield 1 1336 | yield 2 1337 | yield 3 1338 | yield 4 1339 | 1340 | myGen = myGenerator() 1341 | 1342 | print(next(myGen), end=" ") 1343 | print("Hello From Python") 1344 | print(next(myGen), end=" ") 1345 | 1346 | for number in myGen: 1347 | print(number) 1348 | ``` 1349 | 1350 | # 083 - Decorators – Intro 1351 | 1352 | - [1] Sometimes Called Meta Programming 1353 | - [2] Everything in Python is Object Even Functions 1354 | - [3] Decorator Take A Function and Add Some Functionality and Return It 1355 | - [4] Decorator Wrap Other Function and Enhance Their Behaviour 1356 | - [5] Decorator is Higher Order Function (Function Accept Function As Parameter) 1357 | 1358 | ``` 1359 | def myDecorator(func): # Decorator 1360 | 1361 | def nestedFunc(): # Any Name Its Just For Decoration 1362 | 1363 | print("Before") # Message From Decorator 1364 | 1365 | func() # Execute Function 1366 | 1367 | print("After") # Message From Decorator 1368 | 1369 | return nestedFunc # Return All Data 1370 | ``` 1371 | 1372 | - Sugar syntax `recommended` 1373 | 1374 | ``` 1375 | @myDecorator 1376 | 1377 | def sayHello(): 1378 | 1379 | print("Hello From Say Hello Function") 1380 | 1381 | sayHello() 1382 | ``` 1383 | 1384 | ``` 1385 | @myDecorator 1386 | 1387 | def sayHowAreYou(): 1388 | 1389 | print("Hello From Say How Are You Function") 1390 | 1391 | sayHowAreYou() 1392 | ``` 1393 | 1394 | - replace for sugar format 1395 | 1396 | ``` 1397 | afterDecoration = myDecorator(sayHello) 1398 | 1399 | afterDecoration() 1400 | ``` 1401 | 1402 | # 085 - Decorators – Function with Parameters 1403 | 1404 | - Function accept one or more decoration 1405 | 1406 | ``` 1407 | def myDecorator(func): # Decorator 1408 | 1409 | def nestedFunc(num1, num2): # Any Name Its Just For Decoration 1410 | 1411 | if num1 < 0 or num2 < 0: 1412 | 1413 | print("Beware One Of The Numbers Is Less Than Zero") 1414 | 1415 | func(num1, num2) # Execute Function 1416 | 1417 | return nestedFunc # Return All Data 1418 | 1419 | def myDecoratorTwo(func): # Decorator 1420 | 1421 | def nestedFunc(num1, num2): # Any Name Its Just For Decoration 1422 | 1423 | print("Coming From Decorator Two") 1424 | 1425 | func(num1, num2) # Execute Function 1426 | 1427 | return nestedFunc # Return All Data 1428 | ``` 1429 | 1430 | ``` 1431 | @myDecorator 1432 | @myDecoratorTwo 1433 | 1434 | def calculate(n1, n2): 1435 | 1436 | print(n1 + n2) 1437 | 1438 | calculate(-5, 90) 1439 | ``` 1440 | 1441 | # 086 - Practical Loop on Many Iterators With Zip 1442 | 1443 | - zip() Return A Zip Object Contains All Objects 1444 | - zip() Length Is The Length of Lowest Object 1445 | 1446 | ``` 1447 | list1 = [1, 2, 3, 4, 5] 1448 | list2 = ["A", "B", "C", "D"] 1449 | tuple1 = ("Man", "Woman", "Girl", "Boy") 1450 | dict1 = {"Name": "Osama", "Age": 36, "Country": "Egypt", "Skill": "Python"} 1451 | 1452 | for item1, item2, item3, item4 in zip(list1, list2, tuple1, dict1): 1453 | 1454 | print("List 1 Item =>", item1) 1455 | print("List 2 Item =>", item2) 1456 | print("Tuple 1 Item =>", item3) 1457 | print("Dict 1 Key =>", item4, "Value =>", dict1[item4]) 1458 | 1459 | ultimateList = zip(list1, list2) 1460 | print(ultimateList) 1461 | for item in ultimateList: 1462 | print(item) 1463 | ``` 1464 | 1465 | # 087 - Practical Image Manipulation With Pillow 1466 | 1467 | ``` 1468 | from PIL import Image 1469 | 1470 | # Open The Image 1471 | myImage = Image.open("D:\Python\Files\game.jpg") 1472 | 1473 | # Show The Image 1474 | myImage.show() 1475 | 1476 | # My Cropped Image 1477 | myBox = (300, 300, 800, 800) 1478 | myNewImage = myImage.crop(myBox) 1479 | 1480 | # Show The New Image 1481 | myNewImage.show() 1482 | 1483 | # My Converted Mode Image 1484 | myConverted = myImage.convert("L") 1485 | myConverted.show() 1486 | ``` 1487 | 1488 | # 088 - Doc String & Commenting vs Documenting 1489 | 1490 | - [1] Documentation String For Class, Module or Function 1491 | - [2] Can Be Accessed From The Help and Doc Attributes 1492 | - [3] Made For Understanding The Functionality of The Complex Code 1493 | - [4] Theres One Line and Multiple Line Doc Strings 1494 | 1495 | - Single Line doc 1496 | 1497 | ``` 1498 | def elzero_function(name): 1499 | ''' DOC Text ''' 1500 | print(f"Hello {name} From Elzero") 1501 | ``` 1502 | 1503 | - MultiLine doc 1504 | 1505 | ``` 1506 | def elzero_function(name): 1507 | """ 1508 | Elzero Function 1509 | It Say Hello From Elzero 1510 | Parameter: 1511 | name => Person Name That Use Function 1512 | Return: 1513 | Return Hello Message To The Person 1514 | """ 1515 | print(f"Hello {name} From Elzero") 1516 | ``` 1517 | 1518 | ``` 1519 | elzero_function("Ahmed") 1520 | 1521 | print(dir(elzero_function)) 1522 | 1523 | print(elzero_function.__doc__) 1524 | 1525 | help(elzero_function) 1526 | ``` 1527 | 1528 | # 089 - Installing And Use Pylint For Better Code 1529 | 1530 | - `pip install pylint` 1531 | - [Vscode extension](https://marketplace.visualstudio.com/items?itemName=ms-python.pylint) 1532 | 1533 | - In Terminal `pylint.exe fileLocation` 1534 | -- eg. `pylint.exe d:/python/main.py` 1535 | 1536 | # 090 - Errors And Exceptions Raising 1537 | 1538 | - [1] Exceptions Is A Runtime Error Reporting Mechanism 1539 | - [2] Exception Gives You The Message To Understand The Problem 1540 | - [3] Traceback Gives You The Line To Look For The Code in This Line 1541 | - [4] Exceptions Have Types (SyntaxError, IndexError, KeyError, Etc...) 1542 | - [5] [Exceptions List](https://docs.python.org/3/library/exceptions.html) 1543 | - [6] raise Keyword Used To Raise Your Own Exceptions 1544 | 1545 | ``` 1546 | x = -10 1547 | 1548 | if x < 0: 1549 | 1550 | raise Exception(f"The Number {x} Is Less Than Zero") 1551 | 1552 | print("This Will Not Print Because The Error") 1553 | 1554 | else: 1555 | 1556 | print(f"{x} Is Good Number and Ok") 1557 | 1558 | print('Print Message After If Condition') 1559 | 1560 | y = 10 1561 | 1562 | if type(y) != int: 1563 | 1564 | raise ValueError("Only Numbers Allowed") 1565 | 1566 | print('Print Message After If Condition') 1567 | ``` 1568 | 1569 | # 091 - Exceptions Handling Try, Except, Else, Finally 1570 | 1571 | - `Try` => Test The Code For Errors 1572 | - `Except` => Handle The Errors 1573 | - `Else` => If No Errors 1574 | - `Finally` => Run The Code 1575 | 1576 | ``` 1577 | number = int(input("Write Your Age: ")) 1578 | 1579 | print(number) 1580 | print(type(number)) 1581 | 1582 | try: # Try The Code and Test Errors 1583 | 1584 | number = int(input("Write Your Age: ")) 1585 | 1586 | print("Good, This Is Integer From Try") 1587 | 1588 | except: # Handle The Errors If Its Found 1589 | 1590 | print("Bad, This is Not Integer") 1591 | 1592 | else: # If Theres No Errors 1593 | 1594 | print("Good, This Is Integer From Else") 1595 | 1596 | finally: 1597 | 1598 | print("Print From Finally Whatever Happens") 1599 | 1600 | 1601 | try: 1602 | 1603 | # print(10 / 0) 1604 | # print(x) 1605 | print(int("Hello")) 1606 | 1607 | except ZeroDivisionError: 1608 | 1609 | print("Cant Divide") 1610 | 1611 | except NameError: 1612 | 1613 | print("Identifier Not Found") 1614 | 1615 | except ValueError: 1616 | 1617 | print("Value Error Elzero") 1618 | 1619 | except: 1620 | 1621 | print("Error Happens") 1622 | ``` 1623 | 1624 | # 093 - Debugging Code 1625 | 1626 | ``` 1627 | my_list = [1, 2, 3] 1628 | 1629 | my_dictionary = {"Name": "Osama", "Age": 36, "Country": "Egypt"} 1630 | 1631 | for num in my_list: 1632 | 1633 | print(num) 1634 | 1635 | for key, value in my_dictionary.items(): 1636 | 1637 | print(f"{key} => {value}") 1638 | 1639 | def function_one_one(): 1640 | 1641 | print("Hello From Function One") 1642 | 1643 | function_one_one() 1644 | ``` 1645 | 1646 | # 094 - Type Hinting 1647 | 1648 | - It's just a type hint for your code 1649 | - Not affect code or put restrict in runtime to var 1650 | 1651 | - `var : type` 1652 | - `def funNamr() -> type:` 1653 | 1654 | ``` 1655 | def say_hello(name) -> str: 1656 | 1657 | print(f"Hello {name}") 1658 | 1659 | say_hello("Ahmed") 1660 | 1661 | def calculate(n1, n2) -> str: 1662 | 1663 | print(n1 + n2) 1664 | 1665 | calculate(10, 40) 1666 | ``` 1667 | 1668 | # 095 - Regular Expressions Part 1 Intro 1669 | 1670 | - [1] Sequence of Characters That Define A Search Pattern 1671 | - [2] Regular Expression is Not In Python Its General Concept 1672 | - [3] Used In [Credit Card Validation, IP Address Validation, Email Validation] 1673 | - [4] [Test RegEx]("https://pythex.org/") 1674 | - [5] [Characters Sheet]("https://www.debuggex.com/cheatsheet/regex/python") 1675 | 1676 | # 096 - Regular Expressions Part 2 Quantifiers 1677 | 1678 | - `*` 0 or more 1679 | - `+` 1 or more 1680 | - `?` 0 or 1 1681 | - `{2}` Exactly 2 1682 | - `{2, 5}` Between 2 and 5 1683 | - `{2,}` 2 or more 1684 | - `(,5}` Up to 5 1685 | 1686 | - [regex101](https://regex101.com/) 1687 | 1688 | # 098 - Regular Expressions Part 4 Assertions & Email Pattern 1689 | 1690 | - `^` Start of String 1691 | - `$` End of string 1692 | 1693 | ``` 1694 | # [A-z0-9\.]+@[A-z0-9]+\.[A-z]+ 1695 | # ^[A-z0-9\.]+@[A-z0-9]+\.(com|net|org|info)$ 1696 | ``` 1697 | 1698 | # 99 - Regular Expressions Part 5 Logical Or And Escaping 1699 | 1700 | - `|` Or 1701 | - `\` Escape Special Characters 1702 | - `()` Separate Groups 1703 | 1704 | # 100 - Regular Expressions Part 6 Re Module Search And FindAll 1705 | 1706 | - search() => Search A String For A Match And Return A First Match Only 1707 | - findall() => Returns A List Of All Matches and Empty List if No Match 1708 | - Email Pattern => [A-z0-9\.]+@[A-z0-9]+\.(com|net|org|info) 1709 | 1710 | - `.span()` is postion of searched string 1711 | - `.match` is the searched string 1712 | - `.string` is the string u search into 1713 | - `.group()` 1714 | 1715 | ``` 1716 | import re 1717 | ``` 1718 | 1719 | ``` 1720 | my_search = re.search(r"[A-Z]{2}", "OOsamaEElzero") 1721 | 1722 | print(my_search) 1723 | print(my_search.span()) 1724 | print(my_search.string) 1725 | print(my_search.group()) 1726 | 1727 | is_email = re.search(r"[A-z0-9\.]+@[A-z0-9]+\.(com|net)", "os@osama.com") 1728 | 1729 | if is_email: 1730 | 1731 | print("This is A Valid Email") 1732 | 1733 | print(is_email.span()) 1734 | print(is_email.string) 1735 | print(is_email.group()) 1736 | 1737 | else: 1738 | 1739 | print("This is Not A Valid Email") 1740 | ``` 1741 | 1742 | ``` 1743 | email_input = input("Please Write Your Email: ") 1744 | 1745 | search = re.findall(r"[A-z0-9\.]+@[A-z0-9]+\.com|net", email_input) 1746 | 1747 | empty_list = [] 1748 | 1749 | if search != []: 1750 | 1751 | empty_list.append(search) 1752 | 1753 | print("Email Added") 1754 | 1755 | else: 1756 | 1757 | print("Invalid Email") 1758 | 1759 | for email in empty_list: 1760 | 1761 | print(email) 1762 | ``` 1763 | 1764 | # 101 - Regular Expressions Part 7 Re Module Split And Sub 1765 | 1766 | - `split(Pattern, String, MaxSplit)` => Return A List Of Elements Splitted On Each Match 1767 | - `sub(Pattern, Replace, String, ReplaceCount)` => Replace Matches With What You Want 1768 | 1769 | ``` 1770 | import re 1771 | ``` 1772 | 1773 | ``` 1774 | string_one = "I Love Python Programming Language" 1775 | 1776 | search_one = re.split(r"\s", string_one, 1) 1777 | 1778 | print(search_one) 1779 | 1780 | print("#" * 50) 1781 | 1782 | string_two = "How-To_Write_A_Very-Good-Article" 1783 | 1784 | search_two = re.split(r"-|_", string_two) 1785 | 1786 | print(search_two) 1787 | 1788 | print("#" * 50) 1789 | 1790 | # Get Words From URL 1791 | 1792 | for counter, word in enumerate(search_two, 1): 1793 | 1794 | if len(word) == 1: 1795 | 1796 | continue 1797 | 1798 | print(f"Word Number: {counter} => {word.lower()}") 1799 | 1800 | print("#" * 50) 1801 | 1802 | my_string = "I Love Python" 1803 | 1804 | print(re.sub(r"\s", "-", my_string, 1)) 1805 | ``` 1806 | 1807 | # 102 - Regular Expressions Part 8 Group Trainings And Flags 1808 | 1809 | - `.group()` => return matched string grouped as one word 1810 | - `.groups()` => return matched string in group 1811 | -- if the group regx not exsist it returns `none` 1812 | 1813 | - Flags 1814 | -- ignorecase 1815 | -- multiline 1816 | -- notall 1817 | -- notall 1818 | -- verbose 1819 | 1820 | # 103 - OOP – Part 1 Intro 1821 | 1822 | - [1] Python Support Object Oriented Programming 1823 | - [2] OOP Is A Paradigm Or Coding Style 1824 | OOP Paradigm => 1825 | Means Structuring Program So The Methods[Functions] and Attributes[Data] 1826 | Are Bundled Into Objects 1827 | - [3] Methods => Act As Function That Use The Information Of The Object 1828 | - [4] Python Is Multi-Paradigm Programming Language [Procedural, OOP, Functional] 1829 | -- Procedural => Structure App Like Recipe, Sets Of Steps To Make The Task 1830 | -- Functional => Built On the Concept of Mathematical Functions 1831 | - [5] OOP Allow You To Organize Your Code and Make It Readable and Reusable 1832 | - [6] Everything in Python is Object 1833 | - [7] If Man Is Object 1834 | -- Attributes => Name, Age, Address, Phone Number, Info [Can Be Differnet] 1835 | -- Methods[Behaviors] => Walking, Eating, Singing, Playing 1836 | - [8] If Car Is Object 1837 | -- Attributes => Model, Colour, Price 1838 | -- Methods[Behaviors] => Walking, Stopping 1839 | - [9] Class Is The Template For Creating Objects [Object Constructor | Blueprint] 1840 | -- Class Car Can Create Many Cars Object 1841 | 1842 | # 104 - OOP – Part 2 Class Syntax And Info 1843 | 1844 | - [01] Class is The Blueprint Or Construtor Of The Object 1845 | - [02] Class Instantiate Means Create Instance of A Class 1846 | - [03] Instance => Object Created From Class And Have Their Methods and Attributes 1847 | - [04] Class Defined With Keyword class 1848 | - [05] Class Name Written With PascalCase [UpperCamelCase] Style 1849 | - [06] Class May Contains Methods and Attributes 1850 | - [07] When Creating Object Python Look For The Built In **init** Method 1851 | - [08] `__init__` Method Called Every Time You Create Object From Class 1852 | - [09] `__init__` Method Is Initialize The Data For The Object 1853 | - [10] Any Method With Two Underscore in The Start and End Called Dunder or Magic Method 1854 | - [11] self Refer To The Current Instance Created From The Class And Must Be First Param 1855 | - [12] self Can Be Named Anything 1856 | - [13] In Python You Dont Need To Call new() Keyword To Create Object 1857 | 1858 | - any word with two underscoer `__` called dander method or magic method 1859 | 1860 | ``` 1861 | # Syntax 1862 | # class Name: 1863 | # Constructor => Do Instantiation [ Create Instance From A Class ] 1864 | # Each Instance Is Separate Object 1865 | # def __init__(self, other_data) 1866 | # Body Of Function 1867 | ``` 1868 | 1869 | # 105 - OOP – Part 3 Instance Attributes and Methods Part 1 1870 | 1871 | - Self: Point To Instance Created From Class 1872 | - Instance Attributes: Instance Attributes Defined Inside The Constructor 1873 | - Instance Methods: Take Self Parameter Which Point To Instance Created From Class 1874 | - Instance Methods Can Have More Than One Parameter Like Any Function 1875 | - Instance Methods Can Freely Access Attributes And Methods On The Same Object 1876 | - Instance Methods Can Access The Class Itself 1877 | 1878 | ``` 1879 | class Member: 1880 | def __init__(self, first_name, middle_name, last_name): 1881 | self.fname = first_name 1882 | self.mname = middle_name 1883 | self.lname = last_name 1884 | 1885 | member_one = Member("Osama", "Mohamed", "Elsayed") 1886 | member_two = Member("Ahmed", "Ali", "Mahmoud") 1887 | member_three = Member("Mona", "Ali", "Mahmoud") 1888 | 1889 | # print(dir(member_one)) 1890 | 1891 | print(member_one.fname, member_one.mname, member_one.lname) 1892 | print(member_two.fname) 1893 | print(member_three.fname) 1894 | ``` 1895 | 1896 | # 106 - OOP – Part 4 Instance Attributes and Methods Part 2 1897 | 1898 | ``` 1899 | class Member: 1900 | def __init__(self, first_name, middle_name, last_name, gender): 1901 | self.fname = first_name 1902 | self.mname = middle_name 1903 | self.lname = last_name 1904 | self.gender = gender 1905 | 1906 | def full_name(self): 1907 | return f"{self.fname} {self.mname} {self.lname}" 1908 | 1909 | def name_with_title(self): 1910 | if self.gender == "Male": 1911 | return f"Hello Mr {self.fname}" 1912 | elif self.gender == "Female": 1913 | return f"Hello Miss {self.fname}" 1914 | else: 1915 | return f"Hello {self.fname}" 1916 | 1917 | def get_all_info(self): 1918 | return f"{self.name_with_title()}, Your Full Name Is: {self.full_name()}" 1919 | 1920 | 1921 | member_one = Member("Osama", "Mohamed", "Elsayed", "Male") 1922 | member_two = Member("Ahmed", "Ali", "Mahmoud", "Male") 1923 | member_three = Member("Mona", "Ali", "Mahmoud", "Female") 1924 | 1925 | # print(dir(member_one)) 1926 | 1927 | # print(member_one.fname, member_one.mname, member_one.lname) 1928 | # print(member_two.fname) 1929 | # print(member_three.fname) 1930 | 1931 | # print(member_two.full_name()) 1932 | # print(member_two.name_with_title()) 1933 | 1934 | print(member_one.get_all_info()) 1935 | ``` 1936 | 1937 | # 107 - OOP – Part 5 Class Attributes 1938 | 1939 | - Instance attributes exist in `__main__` 1940 | -- use `self` to refrenece it 1941 | - Class attributes exist in class itself 1942 | -- use `className` to refrenece it 1943 | 1944 | ``` 1945 | class Member: 1946 | 1947 | not_allowed_names = ["Hell", "Shit", "Baloot"] 1948 | 1949 | users_num = 0 1950 | 1951 | def __init__(self, first_name, middle_name, last_name, gender): 1952 | 1953 | self.fname = first_name 1954 | 1955 | self.mname = middle_name 1956 | 1957 | self.lname = last_name 1958 | 1959 | self.gender = gender 1960 | 1961 | Member.users_num += 1 # Member.users_num = Member.users_num + 1 1962 | 1963 | def full_name(self): 1964 | 1965 | if self.fname in Member.not_allowed_names: 1966 | 1967 | raise ValueError("Name Not Allowed") 1968 | 1969 | else: 1970 | 1971 | return f"{self.fname} {self.mname} {self.lname}" 1972 | 1973 | def name_with_title(self): 1974 | 1975 | if self.gender == "Male": 1976 | 1977 | return f"Hello Mr {self.fname}" 1978 | 1979 | elif self.gender == "Female": 1980 | 1981 | return f"Hello Miss {self.fname}" 1982 | 1983 | else: 1984 | 1985 | return f"Hello {self.fname}" 1986 | 1987 | def get_all_info(self): 1988 | 1989 | return f"{self.name_with_title()}, Your Full Name Is: {self.full_name()}" 1990 | 1991 | def delete_user(self): 1992 | 1993 | Member.users_num -= 1 # Member.users_num = Member.users_num -1 1994 | 1995 | return f"User {self.fname} Is Deleted." 1996 | 1997 | 1998 | print(Member.users_num) 1999 | 2000 | member_one = Member("Osama", "Mohamed", "Elsayed", "Male") 2001 | member_two = Member("Ahmed", "Ali", "Mahmoud", "Male") 2002 | member_three = Member("Mona", "Ali", "Mahmoud", "Female") 2003 | member_four = Member("Shit", "Hell", "Metal", "DD") 2004 | 2005 | print(Member.users_num) 2006 | 2007 | print(member_four.delete_user()) 2008 | 2009 | print(Member.users_num) 2010 | 2011 | print(dir(member_one)) 2012 | 2013 | print(member_one.fname, member_one.mname, member_one.lname) 2014 | print(member_two.fname) 2015 | print(member_three.fname) 2016 | 2017 | print(member_two.full_name()) 2018 | print(member_two.name_with_title()) 2019 | 2020 | print(member_three.get_all_info()) 2021 | 2022 | print(dir(Member)) 2023 | ``` 2024 | 2025 | # 108 - OOP – Part 6 Class Methods and Static Methods 2026 | 2027 | - Class Methods: 2028 | -- Marked With `@classmethod` Decorator To Flag It As Class Method 2029 | -- It Take `Cls` Parameter Not `Self` To Point To The Class not The Instance 2030 | -- It Doesn't Require Creation of a Class Instance 2031 | -- Used When You Want To Do Something With The Class Itself 2032 | 2033 | - Static Methods: 2034 | -- Marked With `@staticmethod` Decorator To Flag It As Class Method 2035 | -- It Takes No Parameters 2036 | -- Its Bound To The Class Not Instance 2037 | -- Used When Doing Something Doesnt Have Access To Object Or Class But Related To Class 2038 | 2039 | ``` 2040 | print(member_one.full_name()) 2041 | print(Member.full_name(member_one)) 2042 | ``` 2043 | 2044 | # 109 - OOP – Part 7 Class Magic Methods 2045 | 2046 | -- Everything in Python is An Object 2047 | 2048 | - `__init__` Called Automatically When Instantiating Class 2049 | - `self.__class__` The class to which a class instance belongs 2050 | - `__str__` Gives a Human-Readable Output of the Object 2051 | -- Called When We Use the `print()` Function on the Object 2052 | - `__len__` Returns the Length of the Container 2053 | -- Called When We Use the Built-in `len()` Function on the Object 2054 | 2055 | ``` 2056 | class Skill: 2057 | 2058 | def __init__(self): 2059 | 2060 | self.skills = ["Html", "Css", "Js"] 2061 | 2062 | def __str__(self): 2063 | 2064 | return f"This is My Skills => {self.skills}" 2065 | 2066 | def __len__(self): 2067 | 2068 | return len(self.skills) 2069 | 2070 | profile = Skill() 2071 | print(profile) 2072 | print(len(profile)) 2073 | 2074 | profile.skills.append("PHP") 2075 | profile.skills.append("MySQL") 2076 | 2077 | print(len(profile)) 2078 | 2079 | print(profile.__class__) 2080 | my_string = "Osama" 2081 | print(type(my_string)) 2082 | print(my_string.__class__) 2083 | print(dir(str)) 2084 | print(str.upper(my_string)) 2085 | ``` 2086 | 2087 | # 110 - OOP – Part 8 Inheritance 2088 | 2089 | ``` 2090 | class Food: # Base Class 2091 | 2092 | def __init__(self, name, price): 2093 | 2094 | self.name = name 2095 | 2096 | self.price = price 2097 | 2098 | print(f"{self.name} Is Created From Base Class") 2099 | 2100 | def eat(self): 2101 | 2102 | print("Eat Method From Base Class") 2103 | 2104 | class Apple(Food): # Derived Class 2105 | 2106 | def __init__(self, name, price, amount): 2107 | 2108 | # Food.__init__(self, name) # Create Instance From Base Class 2109 | 2110 | super().__init__(name, price) 2111 | 2112 | self.amount = amount 2113 | 2114 | print(f"{self.name} Is Created From Derived Class And Price Is {self.price} And Amount Is {self.amount}") 2115 | 2116 | def get_from_tree(self): 2117 | 2118 | print("Get From Tree From Derived Class") 2119 | 2120 | # food_one = Food("Pizza") 2121 | food_two = Apple("Pizza", 150, 500) 2122 | food_two.eat() 2123 | food_two.get_from_tree() 2124 | ``` 2125 | 2126 | # 111 - OOP – Part 9 Multiple Inheritance & Methods Override 2127 | 2128 | - MRO => Method Resultion Order => order of class and its parents 2129 | -- `.mro` 2130 | 2131 | ``` 2132 | class BaseOne: 2133 | 2134 | def __init__(self): 2135 | 2136 | print("Base One") 2137 | 2138 | def func_one(self): 2139 | 2140 | print("One") 2141 | 2142 | class BaseTwo: 2143 | 2144 | def __init__(self): 2145 | 2146 | print("Base Two") 2147 | 2148 | def func_two(self): 2149 | 2150 | print("Two") 2151 | 2152 | class Derived(BaseOne, BaseTwo): 2153 | 2154 | pass 2155 | 2156 | my_var = Derived() 2157 | 2158 | # print(Derived.mro()) 2159 | 2160 | print(my_var.func_one) 2161 | print(my_var.func_two) 2162 | 2163 | my_var.func_one() 2164 | my_var.func_two() 2165 | 2166 | class Base: 2167 | 2168 | pass 2169 | 2170 | class DerivedOne(Base): 2171 | 2172 | pass 2173 | 2174 | class DerivedTwo(DerivedOne): 2175 | 2176 | pass 2177 | ``` 2178 | 2179 | # 112 - OOP Part 10 - Polymorphism 2180 | 2181 | - Double face method 2182 | 2183 | - U can make method required to be implemented in child or derived calsses by writing `raise NotImplementedError("Text to show)` 2184 | 2185 | ``` 2186 | n1 = 10 2187 | n2 = 20 2188 | 2189 | print(n1 + n2) 2190 | 2191 | s1 = "Hello" 2192 | s2 = "Python" 2193 | 2194 | print(s1 + " " + s2) 2195 | 2196 | print(len([1, 2, 3, 4, 5, 6])) 2197 | print(len("Osama Elzero")) 2198 | print(len({"Key_One": 1, "Key_Two": 2})) 2199 | 2200 | class A: 2201 | 2202 | def do_something(self): 2203 | 2204 | print("From Class A") 2205 | 2206 | raise NotImplementedError("Derived Class Must Implement This Method") 2207 | 2208 | class B(A): 2209 | 2210 | def do_something(self): 2211 | 2212 | print("From Class B") 2213 | 2214 | class C(A): 2215 | 2216 | def do_something(self): 2217 | 2218 | print("From Class C") 2219 | 2220 | my_instance = B() 2221 | my_instance.do_something() 2222 | ``` 2223 | 2224 | # 113 - OOP – Part 11 Encapsulation 2225 | 2226 | - Encapsulation 2227 | -- Restrict Access To The Data Stored in Attirbutes and Methods 2228 | 2229 | - Public 2230 | -- Every Attribute and Method That We Used So Far Is Public 2231 | -- Attributes and Methods Can Be Modified and Run From Everywhere 2232 | -- Inside Our Outside The Class 2233 | 2234 | - Protected 2235 | -- Attributes and Methods Can Be Accessed From Within The Class And Sub Classes 2236 | -- Attributes and Methods Prefixed With One Underscore `_` 2237 | -- Python dosen't support that but the `_` to tell U and developer that this thing mustn't accessed 2238 | -- `print(one._name)` 2239 | - Private 2240 | -- Attributes and Methods Can Be Accessed From Within The Class Or Object Only 2241 | -- Attributes Cannot Be Modified From Outside The Class 2242 | -- Attributes and Methods Prefixed With Two Underscores `__` 2243 | -- Python dosen't support that but the `_` to tell U and developers that this thing mustn't accessed 2244 | -- `print(var._ClassOfVar_privateVar)` 2245 | 2246 | - `Attributes = Variables = Properties` 2247 | 2248 | ``` 2249 | class Member: 2250 | 2251 | def __init__(self, name): 2252 | 2253 | self.name = name # Public 2254 | 2255 | one = Member("Ahmed") 2256 | print(one.name) 2257 | one.name = "Sayed" 2258 | print(one.name) 2259 | 2260 | class Member: 2261 | 2262 | def __init__(self, name): 2263 | 2264 | self._name = name # Protected 2265 | 2266 | one = Member("Ahmed") 2267 | print(one._name) 2268 | one._name = "Sayed" 2269 | print(one._name) 2270 | 2271 | class Member: 2272 | 2273 | def __init__(self, name): 2274 | 2275 | self.__name = name # Private 2276 | 2277 | def say_hello(self): 2278 | 2279 | return f"Hello {self.__name}" 2280 | 2281 | one = Member("Ahmed") 2282 | # print(one.__name) 2283 | print(one.say_hello()) 2284 | print(one._Member__name) 2285 | ``` 2286 | 2287 | # 114 - OOP Part 12 Getters And Setters 2288 | 2289 | ``` 2290 | class Member: 2291 | 2292 | def __init__(self, name): 2293 | 2294 | self.__name = name # Private 2295 | 2296 | def say_hello(self): 2297 | 2298 | return f"Hello {self.__name}" 2299 | 2300 | def get_name(self): # Getter 2301 | 2302 | return self.__name 2303 | 2304 | def set_name(self, new_name): 2305 | 2306 | self.__name = new_name 2307 | 2308 | one = Member("Ahmed") 2309 | 2310 | one._Member__name = "Sayed" 2311 | print(one._Member__name) 2312 | 2313 | print(one.get_name()) 2314 | one.set_name('Abbas') 2315 | print(one.get_name()) 2316 | ``` 2317 | 2318 | # 115 - OOP – Part 13 @Property Decorator 2319 | 2320 | - Any Method dosn't required any param and return values u can use `@Property` Decorator to use it like properties 2321 | 2322 | ``` 2323 | class Member: 2324 | 2325 | def __init__(self, name, age): 2326 | 2327 | self.name = name 2328 | 2329 | self.age = age 2330 | 2331 | def say_hello(self): 2332 | 2333 | return f"Hello {self.name}" 2334 | 2335 | @property 2336 | def age_in_days(self): 2337 | 2338 | return self.age * 365 2339 | 2340 | one = Member("Ahmed", 40) 2341 | 2342 | print(one.name) 2343 | print(one.age) 2344 | print(one.say_hello()) 2345 | # print(one.age_in_days()) 2346 | 2347 | print(one.age_in_days) 2348 | ``` 2349 | 2350 | # 116 - OOP – Part 14 ABC Abstract Base Class 2351 | 2352 | - Class Called Abstract Class If it Has One or More Abstract Methods 2353 | - abc module in Python Provides Infrastructure for Defining Custom Abstract Base Classes. 2354 | - By Adding @absttractmethod Decorator on The Methods 2355 | - ABCMeta Class Is a Metaclass Used For Defining Abstract Base Class 2356 | 2357 | ``` 2358 | from abc import ABCMeta, abstractmethod 2359 | 2360 | class Programming(metaclass=ABCMeta): 2361 | 2362 | @abstractmethod 2363 | def has_oop(self): 2364 | 2365 | pass 2366 | 2367 | @abstractmethod 2368 | def has_name(self): 2369 | 2370 | pass 2371 | 2372 | class Python(Programming): 2373 | 2374 | def has_oop(self): 2375 | 2376 | return "Yes" 2377 | 2378 | class Pascal(Programming): 2379 | 2380 | def has_oop(self): 2381 | 2382 | return "No" 2383 | 2384 | def has_name(self): 2385 | 2386 | return "Pascal" 2387 | 2388 | one = Pascal() 2389 | 2390 | print(one.has_oop()) 2391 | print(one.has_name()) 2392 | ``` 2393 | 2394 | # 117 - Databases – Intro About Databases 2395 | 2396 | - Database Is A Place Where We Can Store Data 2397 | - Database Organized Into Tables (Users, Categories) 2398 | - Tables Has Columns (ID, Username, Password) 2399 | - There's Many Types Of Databases (MongoDB, MySQL, SQLite) 2400 | - SQL Stand For Structured Query Language 2401 | - SQLite => Can Run in Memory or in A Single File 2402 | - You Can Browse File With https://sqlitebrowser.org/ 2403 | - Data Inside Database Has Types (Text, Integer, Date) 2404 | 2405 | # 118 - Databases – SQLite Create Database And Connect 2406 | 2407 | - Connect 2408 | - Execute 2409 | - Close 2410 | 2411 | ``` 2412 | # Import SQLite Module 2413 | import sqlite3 2414 | 2415 | # Create Database And Connect 2416 | db = sqlite3.connect("app.db") 2417 | 2418 | # Create The Tables and Fields 2419 | db.execute( 2420 | "create table if not exists skills (name text, progress integer, user_id integer)") 2421 | 2422 | # Close Database 2423 | db.close() 2424 | ``` 2425 | 2426 | # 119 - Databases – SQLite Insert Data Into Database 2427 | 2428 | - `cursor` => All Operation in SQL Done By Cursor Not The Connection Itself 2429 | - `commit` => Save All Changes 2430 | 2431 | # 120 - Databases - SQLite Retrieve Data From 2432 | 2433 | - `fetchone` => returns a single record or None if no more rows are available. 2434 | - `fetchall` => fetches all the rows of a query result. It returns all the rows 2435 | as a list of tuples. An empty list is returned if there is no record to fetch. 2436 | - `fetchmany(size)` => 2437 | 2438 | # 122 - Databases - SQLite Update And Delete From Database 2439 | 2440 | - Update Data 2441 | -- if `where condition` not exist it will update every record 2442 | 2443 | ``` 2444 | # cr.execute("update users set name = 'Ameer' where user_id = 3") 2445 | ``` 2446 | 2447 | - Delete Data 2448 | -- if `where condition` not exist it will delete all records 2449 | 2450 | ``` 2451 | cr.execute("delete from users where user_id = 4") 2452 | ``` 2453 | 2454 | # 127 - Databases - SQLite Very Important Information 2455 | 2456 | - SQL injection 2457 | 2458 | ``` 2459 | cr.execute("insert into skills values('pascal', '65' , 1)") 2460 | ``` 2461 | 2462 | - To avoid sql injection 2463 | 2464 | ``` 2465 | my_tuple = ('pascal', '65' , 1) 2466 | cr.execute("insert into skills values(?,?,?)",my_tuple) 2467 | ``` 2468 | 2469 | # 128 - Advanced Lessons - `__name__` And "`__main__`" 2470 | 2471 | - `if __name__ == "__main__":` 2472 | - `__name__` => Built In Variable 2473 | - "`__main__`" => Value Of The `__name__` Variable 2474 | Executions Methods 2475 | - Directly => Execute the Python File Using the Command Line. 2476 | - From Import => Import The Code From File To Another File 2477 | 2478 | - In Some Cases You Want To Know If You Are Using A Module Method As Import 2479 | - Or You Use The Original Python File 2480 | 2481 | - In Direct Mode Python Assign A Value `__main__` 2482 | - To The Built In Variable `__name__` in The Background 2483 | 2484 | # 129 - Advanced Lessons - Timing Your Code With Timeit 2485 | 2486 | - timeit: - Get Execution Time Of Code By Running 1M Time And Give You Minimal Time 2487 | -- It Used For Performance By Testing All Functionality 2488 | - timeit(stmt, setup, timer, number) 2489 | - timeit(pass, pass, default, 1.000.000) Default Values 2490 | 2491 | - stmt: Code You Want To Measure The Execution Time 2492 | - setup: Setup Done Before The Code Execution (Import Module Or Anything) 2493 | - timer: The Timer Value 2494 | - number: How Many Execution That Will Run 2495 | 2496 | ``` 2497 | import timeit 2498 | ``` 2499 | 2500 | ``` 2501 | print(dir(timeit)) 2502 | 2503 | print(timeit.timeit("'Elzero' * 1000")) 2504 | ``` 2505 | 2506 | ``` 2507 | name = "Elzero" 2508 | 2509 | print(name * 1000) 2510 | 2511 | print(timeit.timeit("name = 'Elzero'; name * 1000")) 2512 | ``` 2513 | 2514 | ``` 2515 | # print(random.randint(0, 50)) 2516 | 2517 | print(timeit.timeit(stmt="random.randint(0, 50)", setup="import random")) 2518 | 2519 | print(timeit.repeat(stmt="random.randint(0, 50)", setup="import random", repeat=4)) 2520 | ``` 2521 | 2522 | # 130 - Advanced Lessons - Add Logging To Your Code 2523 | 2524 | - Print Out To Console Or File 2525 | - Print Logs Of What Happens 2526 | 2527 | - `DEBUG()` 2528 | - `INFO()` 2529 | - `WARNING()` 2530 | - `ERROR()` 2531 | - `CRITICAL()` 2532 | 2533 | - name => Logging Module Give It To The Default Logger. 2534 | 2535 | - Basic Config 2536 | -- `level` => Level of Severity 2537 | -- `filename` => File Name and Extension 2538 | -- `mode` => Mode Of The File a => Append 2539 | -- `format` => Format For The Log Message 2540 | 2541 | - getLogger => Return a Logger With the Specified Name 2542 | 2543 | ``` 2544 | import logging 2545 | 2546 | # print(dir(logging)) 2547 | 2548 | logging.basicConfig(filename="my_app.log", 2549 | filemode="a", 2550 | format="(%(asctime)s) | %(name)s | %(levelname)s => '%(message)s'", 2551 | datefmt="%d - %B - %Y, %H:%M:%S") 2552 | 2553 | my_logger = logging.getLogger("Elzero") 2554 | 2555 | my_logger.warning("This Is Warning Message") 2556 | ``` 2557 | 2558 | # 131 - Advanced Lessons – Unit Testing With Unittest 2559 | 2560 | - Test Runner 2561 | -- The Module That Run The Unit Testing (unittest, pytest) 2562 | 2563 | - Test Case 2564 | -- Smallest Unit Of Testing 2565 | -- It Use Asserts Methods To Check For Actions And Responses 2566 | -Test Suite 2567 | -- Collection Of Multiple Tests Or Test Cases 2568 | -Test Report 2569 | -- A Full Report Contains The Failure Or Succeed 2570 | 2571 | - unittest 2572 | -- Add Tests Into Classes As Methods 2573 | -- Use a Series of Special Assertion Methods 2574 | -- [Link](https://docs.python.org/3/library/unittest.html) 2575 | 2576 | ``` 2577 | import unittest 2578 | ``` 2579 | 2580 | ``` 2581 | assert 3 * 8 == 24, "Should Be 24" 2582 | 2583 | def test_case_one(): 2584 | 2585 | assert 5 * 10 == 50, "Should Be 50" 2586 | 2587 | def test_case_two(): 2588 | 2589 | assert 5 * 50 == 250, "Should Be 250" 2590 | 2591 | if __name__ == "__main__": 2592 | 2593 | test_case_one() 2594 | test_case_two() 2595 | 2596 | print("All Tests Passed") 2597 | ``` 2598 | 2599 | ``` 2600 | class MyTestCase(unittest.TestCase): 2601 | 2602 | def test_one(self): 2603 | 2604 | self.assertTrue(100 > 99, "Should Be True") 2605 | 2606 | def test_two(self): 2607 | 2608 | self.assertEqual(40 + 60, 100, "Should Be 100") 2609 | 2610 | def test_three(self): 2611 | 2612 | self.assertGreater(100, 101, "Should Be True") 2613 | 2614 | if __name__ == "__main__": 2615 | 2616 | unittest.main() 2617 | ``` 2618 | 2619 | # 132 - Advanced Lessons - Generate Random Serial Numbers 2620 | 2621 | # 133 - Flask – Intro And Your First Page 2622 | 2623 | # 134 - Flask – Create HTML Files 2624 | 2625 | # 135 - Flask – Create And Extends HTML Templates 2626 | 2627 | # 136 - Flask - Jinja Template 2628 | 2629 | # 137 - Flask – Advanced CSS Task Using Jinja 2630 | 2631 | # 138 - Flask – Skills Page Using List Data 2632 | 2633 | # 139 - Flask - Customizing App With Css 2634 | 2635 | # 140 - Flask - Adding The JS Files 2636 | 2637 | # 141 - Web Scraping – Control Browser With Selenium 2638 | 2639 | - Control Browser With Selenium For Automated Testing 2640 | - Download File From The Internet 2641 | - Subtitle Download And Add On Your Movies [ Many Modules ] 2642 | - Get Quotes From Websites 2643 | - Get Gold and Currencies Rate 2644 | - Get News From Websites 2645 | 2646 | - `pip install selenuim` 2647 | - `pip install webdriver-manager` 2648 | 2649 | ``` 2650 | from selenium import webdriver 2651 | from webdriver_manager.chrome import ChromeDriverManager 2652 | 2653 | browser = webdriver.Chrome(ChromeDriverManager().install()) 2654 | 2655 | browser.get("https://elzero.org") 2656 | 2657 | browser.find_element_by_css_selector(".search-field").send_keys("Front-End Developer") 2658 | 2659 | browser.find_element_by_css_selector(".search-submit").click() 2660 | 2661 | browser.find_element_by_css_selector(".all-search-posts .search-post:first-of-type h3 a").click() 2662 | 2663 | browser.implicitly_wait(5) 2664 | 2665 | views_count = browser.find_element_by_css_selector(".z-article-info .z-info:last-of-type span:last-child") 2666 | 2667 | browser.implicitly_wait(5) 2668 | 2669 | print(views_count.get_attribute('innerHTML')) 2670 | 2671 | browser.quit() 2672 | ``` 2673 | 2674 | # 142 - NumPy – Intro 2675 | 2676 | - NumPy Is A Python Third-Party Module To Deal With Arrays & Matrices 2677 | - NumPy Stand For Numerical Python 2678 | - NumPy Is Open Source 2679 | - NumPy Support Dealing With Large Multidimensional Arrays & Matrices 2680 | - NumPy Has Many Mathematical Functions To Deal With This Elements 2681 | 2682 | - Why We Use NumPy Array 2683 | - Consume Less Memory 2684 | - Very Fast Compared To Python List 2685 | - Easy To Use 2686 | - Support Element Wise Operation 2687 | - Elements Are Stored Contiguous 2688 | 2689 | - Python Lists 2690 | -- Homogeneous => Can Contains The Same Type of Objects 2691 | -- Heterogeneous => Can Contains Different Types of Objects. 2692 | 2693 | - The Items in The Array Have to Be Of The Same Type 2694 | - You Can Be Sure Whats The Storage Size Needed for The Array 2695 | - NumPy Arrays Are Indexed From 0 2696 | 2697 | - NumPy On Github => https://github.com/numpy/numpy 2698 | 2699 | ``` 2700 | import numpy as np 2701 | print(np.__version__) 2702 | ``` 2703 | 2704 | # 143 - NumPy – Create Arrays 2705 | 2706 | ``` 2707 | import numpy as np 2708 | ``` 2709 | 2710 | ``` 2711 | # print(dir(np)) 2712 | 2713 | my_list = [1, 2, 3, 4, 5] 2714 | my_array = np.array(my_list) 2715 | 2716 | print(my_list) 2717 | print(my_array) 2718 | 2719 | print("#" * 50) 2720 | ``` 2721 | 2722 | - Type 2723 | 2724 | ``` 2725 | print(type(my_list)) 2726 | print(type(my_array)) 2727 | 2728 | print("#" * 50) 2729 | ``` 2730 | 2731 | - Accessing Elements 2732 | 2733 | ``` 2734 | print(my_list[0]) 2735 | print(my_array[0]) 2736 | 2737 | print("#" * 50) 2738 | 2739 | a = np.array(10) 2740 | b = np.array([10, 20]) 2741 | c = np.array( [ [1, 2], [3, 4] ] ) 2742 | d = np.array( [ [ [5, 6], [7, 9] ], [ [1, 3], [4, 8] ] ] ) 2743 | 2744 | print(d[1][1][-1]) 2745 | print(d[1, 1, 1]) 2746 | print(d[1, 1, -1]) 2747 | 2748 | print("#" * 50) 2749 | ``` 2750 | 2751 | - Number Of Dimensions 2752 | 2753 | ``` 2754 | print(a.ndim) 2755 | print(b.ndim) 2756 | print(c.ndim) 2757 | print(d.ndim) 2758 | 2759 | print("#" * 50) 2760 | ``` 2761 | 2762 | - Custom Dimensions 2763 | 2764 | ``` 2765 | my_custom_array = np.array([1, 2, 3], ndmin=3) 2766 | print(my_custom_array) 2767 | print(my_custom_array.ndim) 2768 | 2769 | print(my_custom_array[0, 0, 0]) 2770 | ``` 2771 | 2772 | # 144 - NumPy – Compare Data Location And Type 2773 | 2774 | ``` 2775 | import numpy as np 2776 | 2777 | my_list = [1, 2, 3, 4, 5] 2778 | my_array = np.array([1, 2, 3, 4, 5]) 2779 | 2780 | print(my_list[0]) 2781 | print(my_list[1]) 2782 | 2783 | print(my_array[0]) 2784 | print(my_array[1]) 2785 | 2786 | print("#" * 50) 2787 | 2788 | print(id(my_list[0])) 2789 | print(id(my_list[1])) 2790 | 2791 | print(id(my_array[0])) 2792 | print(id(my_array[1])) 2793 | 2794 | print("#" * 50) 2795 | 2796 | my_list_of_data = [1, 2, "A", "B", True, 10.50] 2797 | my_array_of_data = np.array([1, 2, "A", "B", True, 10.50]) 2798 | 2799 | print(my_list_of_data) 2800 | print(my_array_of_data) 2801 | 2802 | print("#" * 50) 2803 | 2804 | print(my_list_of_data[0]) 2805 | print(my_array_of_data[0]) 2806 | 2807 | print(type(my_list_of_data[0])) 2808 | print(type(my_array_of_data[0])) 2809 | 2810 | print("#" * 50) 2811 | 2812 | my_list_of_data_two = [1, 2, "A", "B", True, 10.50] 2813 | my_array_of_data_two = np.array([1, 2, "A"]) 2814 | 2815 | print(my_list_of_data_two) 2816 | print(my_array_of_data_two) 2817 | 2818 | print("#" * 50) 2819 | 2820 | print(my_list_of_data_two[0]) 2821 | print(my_array_of_data_two[0]) 2822 | 2823 | print(type(my_list_of_data_two[0])) 2824 | print(type(my_array_of_data_two[0])) 2825 | ``` 2826 | 2827 | # 145 - NumPy – Compare Performance And Memory Use 2828 | 2829 | - One line loop 2830 | -- Noraml 2831 | 2832 | ```` 2833 | for n1, n2 in zip(my_list1, my_list2): 2834 | print(n1 + n2) 2835 | ``` 2836 | ```` 2837 | 2838 | -- Shorten 2839 | 2840 | ``` 2841 | [(n1 + n2) for n1, n2 in zip(my_list1, my_list2)] 2842 | ``` 2843 | 2844 | - COde 2845 | 2846 | ``` 2847 | import numpy as np 2848 | import time 2849 | import sys 2850 | 2851 | elements = 150000 2852 | 2853 | my_list1 = range(elements) 2854 | my_list2 = range(elements) 2855 | 2856 | my_array1 = np.arange(elements) 2857 | my_array2 = np.arange(elements) 2858 | 2859 | list_start = time.time() 2860 | list_result = [(n1 + n2) for n1, n2 in zip(my_list1, my_list2)] 2861 | print(f"List Time: {time.time() - list_start}") 2862 | 2863 | array_start = time.time() 2864 | array_result = my_array1 + my_array2 2865 | print(f"Array Time: {time.time() - array_start}") 2866 | 2867 | # for n1, n2 in zip(my_list1, my_list2): 2868 | 2869 | # print(n1 + n2) 2870 | 2871 | print(list_result) 2872 | print(array_result) 2873 | 2874 | my_array = np.arange(100) 2875 | 2876 | print(my_array) 2877 | print(my_array.itemsize) 2878 | print(my_array.size) 2879 | print(f"All Bytes: {my_array.itemsize * my_array.size}") 2880 | 2881 | print("#" * 50) 2882 | 2883 | my_list = range(100) 2884 | print(sys.getsizeof(1)) 2885 | print(len(my_list)) 2886 | print(f"All Bytes: {sys.getsizeof(1) * len(my_list)}") 2887 | ``` 2888 | 2889 | # 146 - NumPy – Array Slicing 2890 | 2891 | - Slicing => [Start:End:Steps] Not Including End 2892 | 2893 | ``` 2894 | import numpy as np 2895 | 2896 | # Slicing => [Start:End:Steps] Not Including End 2897 | 2898 | a = np.array(["A", "B", "C", "D", "E", "F"]) 2899 | 2900 | print(a.ndim) 2901 | print(a[1]) 2902 | print(a[1:4]) 2903 | print(a[:4]) 2904 | print(a[2:]) 2905 | 2906 | print("#" * 50) 2907 | 2908 | b = np.array([["A", "B", "X"], ["C", "D", "Y"], ["E", "F", "Z"], ["M", "N", "O"]]) 2909 | 2910 | print(b.ndim) 2911 | print(b[1]) 2912 | 2913 | print("#" * 50) 2914 | 2915 | print(b[2:, :2]) 2916 | print(b[2:, :2:2]) 2917 | ``` 2918 | 2919 | # 147 - NumPy – Data Types And Control Array 2920 | 2921 | - [Data types](https://numpy.org/devdocs/user/basics.types.html) 2922 | - [Specifying and constructing data types](https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#specifying-and-constructing-data-types) 2923 | 2924 | - `?` boolean 2925 | - `b` (signed) byte 2926 | - `B` unsigned byte 2927 | - `i` (signed) integer 2928 | - `u` unsigned integer 2929 | - `f` floating-point 2930 | - `c` complex-floating point 2931 | - `m` timedelta 2932 | - `M` datetime 2933 | - `O` (Python) objects 2934 | - `S`, 'a' zero-terminated bytes (not recommended) 2935 | - `U` Unicode string 2936 | - `V` raw data (void) 2937 | 2938 | ``` 2939 | import numpy as np 2940 | ``` 2941 | 2942 | - Show Array Data Type 2943 | 2944 | ``` 2945 | my_array1 = np.array([1, 2, 3]) 2946 | my_array2 = np.array([1.5, 20.15, 3.601]) 2947 | my_array3 = np.array(["Osama_Elzero", "B", "Ahmed"]) 2948 | 2949 | print(my_array1.dtype) 2950 | print(my_array2.dtype) 2951 | print(my_array3.dtype) 2952 | 2953 | print("#" * 50) 2954 | ``` 2955 | 2956 | - Create Array With Specific Data Type 2957 | 2958 | ``` 2959 | my_array4 = np.array([1, 2, 3], dtype=float) # float Or 'float' Or 'f' 2960 | my_array5 = np.array([1.5, 20.15, 3.601], dtype=int) # int Or 'int' Or 'i' 2961 | # my_array6 = np.array(["Osama_Elzero", "B", "Ahmed"], dtype=int) # Value Error 2962 | 2963 | print(my_array4.dtype) 2964 | print(my_array5.dtype) 2965 | # print(my_array6.dtype) 2966 | 2967 | print("#" * 50) 2968 | ``` 2969 | 2970 | - Change Data Type Of Existing Array 2971 | 2972 | ``` 2973 | my_array7 = np.array([0, 1, 2, 3, 0, 4]) 2974 | print(my_array7.dtype) 2975 | print(my_array7) 2976 | 2977 | print("#" * 50) 2978 | 2979 | my_array7 = my_array7.astype('float') 2980 | print(my_array7.dtype) 2981 | print(my_array7) 2982 | 2983 | print("#" * 50) 2984 | 2985 | my_array7 = my_array7.astype('bool') 2986 | print(my_array7.dtype) 2987 | print(my_array7) 2988 | 2989 | print("#" * 50) 2990 | ``` 2991 | 2992 | - Test Capacity 2993 | 2994 | ``` 2995 | my_array8 = np.array([100, 200, 300, 400], dtype='f') 2996 | print(my_array8.dtype) 2997 | print(my_array8[0].itemsize) # 4 Bytes 2998 | 2999 | my_array8 = my_array8.astype('float') # Change To Float64 3000 | print(my_array8.dtype) 3001 | print(my_array8[0].itemsize) # 8 Bytes 3002 | ``` 3003 | 3004 | # 148 - NumPy – Arithmetic And Useful Operations 3005 | 3006 | - `min` 3007 | - `max` 3008 | - `sum` 3009 | - `ravel` => Returns Flattened Array 1 Dimension With Same Type 3010 | 3011 | ``` 3012 | import numpy as np 3013 | ``` 3014 | 3015 | - Arithmetic Operations 3016 | 3017 | ``` 3018 | my_array1 = np.array([10, 20, 30]) 3019 | my_array2 = np.array([5, 2, 4]) 3020 | 3021 | print(my_array1 + my_array2) # result [15, 22, 34] 3022 | print(my_array1 - my_array2) # result [5, 18, 26] 3023 | print(my_array1 * my_array2) # result [50, 40, 120] 3024 | print(my_array1 / my_array2) # result [2, 10, 7.5] 3025 | 3026 | print('#' * 50) 3027 | 3028 | my_array3 = np.array([[1, 4], [5, 9]]) 3029 | my_array4 = np.array([[2, 7], [10, 5]]) 3030 | 3031 | print(my_array3 + my_array4) # result [ [3, 11], [15, 14] ] 3032 | print(my_array3 - my_array4) # result [ [-1, -3], [-5, 4] ] 3033 | print(my_array3 * my_array4) # result [ [2, 28], [50, 45] ] 3034 | print(my_array3 / my_array4) # result [ [0.5, 0.57142857], [0.5, 1.8] ] 3035 | 3036 | print('#' * 50) 3037 | ``` 3038 | 3039 | - Min, Max, Sum 3040 | 3041 | ``` 3042 | my_array5 = np.array([10, 20, 30]) 3043 | print(my_array5.min()) 3044 | print(my_array5.max()) 3045 | print(my_array5.sum()) 3046 | 3047 | print('#' * 50) 3048 | 3049 | my_array6 = np.array([[6, 4], [3, 9]]) 3050 | print(my_array6.min()) 3051 | print(my_array6.max()) 3052 | print(my_array6.sum()) 3053 | 3054 | print('#' * 50) 3055 | ``` 3056 | 3057 | - Ravel 3058 | 3059 | ``` 3060 | my_array7 = np.array([[6, 4], [3, 9]]) 3061 | print(my_array7.ravel()) 3062 | 3063 | my_array8 = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) 3064 | print(my_array8.ndim) 3065 | print(my_array8.ravel()) 3066 | x = my_array8.ravel() 3067 | print(x.ndim) 3068 | ``` 3069 | 3070 | # 149 - Numpy - Array Shape And ReShape 3071 | 3072 | - Shape Returns A Tuple Contains The Number Of Elements in Each Dimension 3073 | 3074 | ``` 3075 | import numpy as np 3076 | ``` 3077 | 3078 | ``` 3079 | my_array1 = np.array([1, 2, 3, 4]) 3080 | print(my_array1.ndim) 3081 | print(my_array1.shape) 3082 | 3083 | print("#" * 50) 3084 | 3085 | my_array2 = np.array([[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]) 3086 | print(my_array2.ndim) 3087 | print(my_array2.shape) 3088 | 3089 | print("#" * 50) 3090 | 3091 | my_array3 = np.array([[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3]]]) 3092 | print(my_array3.ndim) 3093 | print(my_array3.shape) 3094 | 3095 | print("#" * 50) 3096 | 3097 | my_array4 = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) 3098 | print(my_array4.ndim) 3099 | print(my_array4.shape) 3100 | 3101 | reshaped_array4 = my_array4.reshape(3, 4) 3102 | print(reshaped_array4.ndim) 3103 | print(reshaped_array4.shape) 3104 | print(reshaped_array4) 3105 | 3106 | print("#" * 50) 3107 | 3108 | my_array5 = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) 3109 | print(my_array5.ndim) 3110 | print(my_array5.shape) 3111 | 3112 | print("#" * 50) 3113 | 3114 | # reshaped_array5 = my_array5.reshape(-1) 3115 | # reshaped_array5 = my_array5.reshape(4, 5) 3116 | reshaped_array5 = my_array5.reshape(2, 5, 2) 3117 | print(reshaped_array5.ndim) 3118 | print(reshaped_array5.shape) 3119 | print(reshaped_array5) 3120 | ``` 3121 | 3122 | # 150 - Virtual Environment Part 1 3123 | 3124 | - Virtual Environment exsist to handle packages 3125 | 3126 | - Create `env` folder 3127 | - open folder in terminal 3128 | - Run=> `python -m venv envNamw` 3129 | -- `python -m venv ai` 3130 | 3131 | - U can have multi environment 3132 | -- `python -m venv ai` 3133 | -- `python -m venv fire` 3134 | 3135 | # 151 - Virtual Environment Part 2 3136 | 3137 | - To activate certin environment => `source envName/Scripts/activate` 3138 | -- `source ai/Scripts/activate` 3139 | - `deactivate` => To close environment 3140 | 3141 | - `which python` => To show where python run from 3142 | 3143 | - To run file from env `envName/Scripts/python.exe {path of file u want to run}` 3144 | -- `ai/Scripts/python.exe d:/python/151/main.py` 3145 | 3146 | - `pip freeze` => To output all packages and its version from current environment 3147 | -- to make a file from this command u can use unix commands lik `command > fileName` 3148 | -- `pip freeze > requirements.txt` 3149 | 3150 | - `pip install -r FILE` => To install packages from file 3151 | -- `pip install -r requirements.txt` 3152 | 3153 | - Virtual Environment Wrapper? 3154 | 3155 | # 152 - The End And Resources 3156 | 3157 | - [Resources](https://www.youtube.com/watch?v=OwV5R8Qy1e4&list=PLDoPjvoNmBAyE_gei5d18qkfIe-Z8mocs&index=152) 3158 | -- [awesome-python](https://awesome-python.com/) 3159 | -------------------------------------------------------------------------------- /assignments/001-010/main.py: -------------------------------------------------------------------------------- 1 | # 01 2 | # ---------------------------- 3 | # -- Multiple Line Comment -- 4 | # ---------------------------- 5 | # This is the first assignment in 6 | # python course 7 | # from Elzero web school 8 | # ----------------------------- 9 | 10 | # 02 11 | name = "Hassan Eltantawy" 12 | age = "22" 13 | country = "Egypt" 14 | 15 | # 03 16 | print('"Name: ' + name + '"\n"Age: '+ age + '"\n"Country: "' +country + '"') 17 | 18 | # 04 19 | print('"Hello, My Name Is '+name+ ' And Iam '+age+' Years Old and I Live in '+country+'."') 20 | 21 | # 05 22 | print(type( name) ) 23 | print(type(age )) 24 | print(type(country)) -------------------------------------------------------------------------------- /assignments/010-018/main.py: -------------------------------------------------------------------------------- 1 | # 01 2 | # "Hello 'Osama', How You Doing \ """ Your Age Is "38"" + And Your Country Is: Egypt 3 | 4 | name , age , country = "Hassan" , 38,"Egypt" 5 | 6 | print(f'"Hello \'{name}\', How You Doing \\ """ Your Age Is "{age}"" + And Your Country Is: {country}') 7 | 8 | # 02 9 | print("###############") 10 | 11 | print(f'"Hello \'{name}\', How You Doing \\\n """ Your Age Is "{age}"" +\n And Your Country Is: {country}') 12 | 13 | # 03 14 | print("###############") 15 | 16 | name = 'Elzero' 17 | print(f'Second Letter Is "{name[1]}"') 18 | print(f'Third Letter Is "{name[2]}"') 19 | print(f'Last Letter Is "{name[-1]}"') 20 | 21 | # 04 22 | print("###############") 23 | 24 | print(f'"{name[1:3]}"') 25 | print(f'"{name[::2]}"') 26 | print(f'"{name[::2][::-1]}"') 27 | 28 | # 05 29 | print("###############") 30 | 31 | name = "#@#@Elzero#@#@" 32 | print(name.strip("#@")) 33 | 34 | # 06 35 | print("###############") 36 | 37 | num = "9" 38 | print(num.zfill(4)) 39 | num = "15" 40 | print(num.zfill(4)) 41 | num = "130" 42 | print(num.zfill(4)) 43 | num = "950" 44 | print(num.zfill(4)) 45 | num = "1500" 46 | print(num.zfill(4)) 47 | 48 | # 07 49 | print("###############") 50 | 51 | name_one = "Osama" 52 | name_two = "Osama_Elzero" 53 | 54 | # Needed Output 55 | # @@@@@@@@@@@@@@@Osama 56 | # @@@@@@@@Osama_Elzero 57 | 58 | print(name_one.rjust(20,"@")) 59 | print(name_two.rjust(20,"@")) 60 | 61 | # 08 62 | print("###############") 63 | 64 | name_one = "OSamA" 65 | name_two = "osaMA" 66 | 67 | # Needed Output 68 | # osAMa 69 | # OSAma 70 | print(name_one.swapcase()) 71 | print(name_two.swapcase()) 72 | 73 | # 09 74 | print("###############") 75 | 76 | msg = "I Love Python And Although Love Elzero Web School" 77 | print(msg.count("Love")) 78 | 79 | # 10 80 | print("###############") 81 | 82 | name = "Elzero" 83 | print(name.index("z")) 84 | 85 | # 11 86 | print("###############") 87 | 88 | msg = "I <3 Python And Although <3 Elzero Web School" 89 | print(msg.replace("<3","Love",1)) 90 | 91 | # 12 92 | print("###############") 93 | 94 | msg = "I <3 Python And Although <3 Elzero Web School" 95 | print(msg.replace("<3","Love")) 96 | 97 | # 13 98 | print("###############") 99 | 100 | name = "Osama" 101 | age = 38 102 | country = "Egypt" 103 | 104 | print(f"My Name Is {name}, And My Age Is {age}, And My Country Is {country}") -------------------------------------------------------------------------------- /assignments/018-020/main.py: -------------------------------------------------------------------------------- 1 | # 01 2 | 3 | print(2) 4 | print(2.5) 5 | print(5+6j) 6 | 7 | # 02 8 | 9 | compNum = 1+2j 10 | print(f'{compNum.real}\n{compNum.imag}') 11 | 12 | # 03 13 | 14 | num = 10 15 | print("{:.10f}".format(float(num),10)) 16 | 17 | # 04 18 | 19 | num = 159.650 20 | new = int(num) 21 | print(new) 22 | print(type(new)) 23 | 24 | # 05 25 | 26 | print(100 - 115) # -15 27 | print(50 * 30) # 1500 28 | print(21 % 4) # 1 29 | print(110 // 11) # 10 30 | print(97 // 20 ) # 4 -------------------------------------------------------------------------------- /assignments/021-023/main.py: -------------------------------------------------------------------------------- 1 | # 01 2 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 3 | print(friends[0]) 4 | print(friends.pop(0)) 5 | print(friends[-1]) 6 | print(friends.pop(-1)) 7 | 8 | # 02 9 | print("################") 10 | 11 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 12 | print(friends[::2]) 13 | print(friends[1::2]) 14 | 15 | # 03 16 | print("################") 17 | 18 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 19 | print(friends[1:4]) 20 | print(friends[-2:]) 21 | 22 | # 04 23 | print("################") 24 | 25 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 26 | friends[-2:] = ["Elzero","Elzero"] 27 | print(friends) 28 | 29 | # 05 30 | print("################") 31 | 32 | friends = ["Osama", "Ahmed", "Sayed"] 33 | friends.insert(0,"num 01") 34 | print(friends) 35 | friends.insert(-1,"num 02") 36 | # friends.append("num 02") 37 | print(friends) 38 | 39 | # 06 40 | print("################") 41 | 42 | friends = ["Nasser", "Osama", "Ahmed", "Sayed", "Salem"] 43 | 44 | friends[0:2] = [] 45 | print(friends) 46 | friends[-1:] = [] 47 | # friends.pop(-1) 48 | print(friends) 49 | 50 | # 07 51 | print("################") 52 | 53 | friends = ["Ahmed", "Sayed"] 54 | employees = ["Samah", "Eman"] 55 | school = ["Ramy", "Shady"] 56 | friends.extend(employees) 57 | friends.extend(school) 58 | print(friends) 59 | 60 | # 08 61 | print("################") 62 | 63 | friends = ["Ahmed", "Sayed", "Samah", "Eman", "Ramy", "Shady"] 64 | friends.sort() 65 | print(friends) 66 | friends.reverse() 67 | print(friends) 68 | 69 | # 09 70 | print("################") 71 | 72 | friends = ["Ahmed", "Sayed", "Samah", "Eman", "Ramy", "Shady"] 73 | print(len(friends)) 74 | 75 | # 10 76 | print("################") 77 | 78 | technologies = ["Html", "CSS", "JS", "Python", ["Django", "Flask", "Web"]] 79 | # Needed Output 80 | # Django 81 | print(technologies[4][0]) 82 | # Web 83 | print(technologies[4][-1]) -------------------------------------------------------------------------------- /assignments/024-025/main.py: -------------------------------------------------------------------------------- 1 | # 01 2 | 3 | t = "Hassan", 4 | 5 | print(t[0]) 6 | print(type(t)) 7 | 8 | # 02 9 | print("#"*7) 10 | 11 | friends = ("Osama", "Ahmed", "Sayed") 12 | 13 | _,b,c = friends 14 | friendsT = ("Elzero",b,c) 15 | 16 | # friendsT = ("Elzero",friends[1],friends[2]) 17 | 18 | print(friendsT) 19 | print(type(friendsT)) 20 | print(f"{len(friendsT)} Elements") 21 | 22 | # 03 23 | print("#"*7) 24 | 25 | nums = (1, 2, 3) 26 | letters = ("A", "B", "C") 27 | 28 | mixT = nums + letters 29 | 30 | print(mixT) 31 | 32 | # 04 33 | print("#"*7) 34 | 35 | my_tuple = (1, 2, 3, 4) 36 | a,b,_,c = my_tuple 37 | 38 | print(a) 39 | print(b) 40 | print(c) 41 | 42 | # 04 43 | print("#"*7) 44 | 45 | my_tuple = (1, 2, 3, 4) 46 | a,b,_,c = my_tuple 47 | 48 | print(a) 49 | print(b) 50 | print(c) -------------------------------------------------------------------------------- /assignments/026-032/main.py: -------------------------------------------------------------------------------- 1 | # 01 2 | my_list = [1, 2, 3, 3, 4, 5, 1] 3 | 4 | uniquSet = set(my_list) 5 | unique_list = list(uniquSet) 6 | 7 | print( unique_list) 8 | print(type( unique_list)) 9 | unique_list.pop(-1) 10 | print( unique_list) 11 | 12 | # 02 13 | print("#"*10) 14 | 15 | nums = {1, 2, 3} 16 | letters = {"A", "B", "C"} 17 | 18 | print(nums|letters) 19 | print(nums.union(letters)) 20 | print(set(list(nums) + list(letters))) 21 | # # print(nums + letters) 22 | # print(nums+letters) 23 | 24 | # 03 25 | print("#"*10) 26 | 27 | my_set = {1, 2, 3} 28 | letters = {"A", "B", "C"} 29 | 30 | print(my_set) 31 | my_set.clear() 32 | print(my_set) 33 | letters.discard("C") 34 | my_set.update(letters) 35 | print(my_set) 36 | letters.discard("C") -------------------------------------------------------------------------------- /assignments/033-037/main.py: -------------------------------------------------------------------------------- 1 | # 01 2 | 3 | print(bool("S")) 4 | print(bool(1)) 5 | print(bool((1,2))) 6 | print(bool([1,2])) 7 | print(bool({1,2})) 8 | 9 | print(bool("")) 10 | print(bool(0)) 11 | print(bool(())) 12 | print(bool([])) 13 | print(bool({})) 14 | 15 | # 02 16 | print("#" * 10) 17 | 18 | html = 80 19 | css = 60 20 | javascript = 70 21 | 22 | print(html>50 and css>50 and javascript>50) 23 | 24 | 25 | # 02 26 | print("#" * 10) 27 | 28 | num_one = 10 29 | num_two = 20 30 | num = 20 31 | 32 | print(num> num_one or num> num_two) 33 | print(num> num_one and num> num_two) 34 | 35 | # 03 36 | print("#" * 10) 37 | 38 | num_one = 10 39 | num_two = 20 40 | 41 | result = num_one + num_two 42 | print(result) 43 | 44 | result**=3 45 | print(result) 46 | 47 | result %= 26000 48 | print(result) 49 | 50 | result /= 5 51 | print(result) 52 | 53 | result = str(result) 54 | print(type(result)) 55 | 56 | -------------------------------------------------------------------------------- /assignments/038-040/01.py: -------------------------------------------------------------------------------- 1 | # 01 2 | 3 | name = input("Input your name: ") 4 | 5 | print(f"Hello {name.strip().capitalize()}, Happy To See You Here.") 6 | 7 | -------------------------------------------------------------------------------- /assignments/038-040/02.py: -------------------------------------------------------------------------------- 1 | age = int(input("Enter your age: ")) 2 | 3 | if(age < 16): 4 | print("Hello Your Age Is Under 16, Some Articles Is Not Suitable For You") 5 | else : 6 | print(f"Hello Your Age Is {age}, All Articles Is Suitable For You") 7 | -------------------------------------------------------------------------------- /assignments/038-040/03.py: -------------------------------------------------------------------------------- 1 | first_name = input("Enter your first name: ") 2 | second_name = input("Enter your second name: ") 3 | 4 | first_name.strip().capitalize() 5 | second_name.strip().capitalize() 6 | 7 | # print(f"Hello {first_name.strip().capitalize()} {second_name.strip().capitalize():.1s}.") 8 | print(f"Hello {first_name.strip().capitalize()} {second_name.strip().capitalize()[0]}.") -------------------------------------------------------------------------------- /assignments/038-040/04.py: -------------------------------------------------------------------------------- 1 | email = input("Pls enter your email!: ").strip() 2 | 3 | name = email[:email.index("@")] 4 | service = email[email.index("@")+1:email.index(".")] 5 | domain = email[email.index(".")+1:] 6 | 7 | print(f"Your Name Is {name}") 8 | print(f"Email Service Provider Is {service}") 9 | print(f"Top Level Domain Is {domain}") -------------------------------------------------------------------------------- /assignments/041-046/01.py: -------------------------------------------------------------------------------- 1 | num1 = 20 2 | num2 = 40 3 | operation = ["+" , "-" , "*" , "/" , "%"] 4 | 5 | print(eval(f"{num1} {operation[0]} {num2}")) 6 | print(eval(f"{num1} {operation[2]} {num2}")) 7 | 8 | -------------------------------------------------------------------------------- /assignments/041-046/02.py: -------------------------------------------------------------------------------- 1 | age = 17 2 | 3 | 4 | print("App Is Suitable For You" if age>16 else "App Is Not Suitable For You") -------------------------------------------------------------------------------- /assignments/041-046/03.py: -------------------------------------------------------------------------------- 1 | age = int(input("Enter your age: ")) 2 | 3 | months = age * 12 4 | days = age * 365 5 | weeks = age * 52 6 | hours = age * 365 * 24 7 | mintues = age * 365 * 24 * 60 8 | seconds = age * 365 * 24 * 60 * 60 9 | 10 | print(f"Your Age In Months Is {months:,} Months") 11 | print(f"Your Age In Days Is {days:,} Days") 12 | print(f"Your Age In Weeks Is {weeks:,} Weeks") 13 | print(f"Your Age In Hours Is {hours:,} Hours") 14 | print(f"Your Age In Mintues Is {mintues:,} Mintues") 15 | print(f"Your Age In Seconds Is {seconds:,} Seconds") 16 | 17 | -------------------------------------------------------------------------------- /assignments/041-046/04.py: -------------------------------------------------------------------------------- 1 | country = input("Input Your Country: ") 2 | countries = ["Egypt", "Palestine", "Syria", "Yemen", "KSA", "USA", "Bahrain", "England"] 3 | price = 100 4 | discount = 30 5 | 6 | 7 | if country in countries: 8 | print(f"Your Country Eligible For Discount And The Price After Discount Is ${price-discount}") 9 | else: 10 | print("Your Country Not Eligible For Discount And The Price Is $100") -------------------------------------------------------------------------------- /assignments/047-050/01.py: -------------------------------------------------------------------------------- 1 | num = int(input("Enter the number: ")) 2 | count = 0 3 | if num <= 0: 4 | print("Number must be greater than 0") 5 | else: 6 | while num > 0: 7 | num -=1 8 | if num == 0: 9 | continue 10 | if num == 6: 11 | continue 12 | print(num) 13 | count += 1 14 | else: 15 | print(f"{count} Numbers Printed Successfully.") 16 | -------------------------------------------------------------------------------- /assignments/047-050/02.py: -------------------------------------------------------------------------------- 1 | friends = ["Mohamed", "Shady", "ahmed", "eman", "Sherif"] 2 | index = 0 3 | count = 0 4 | 5 | while index < len(friends): 6 | if(friends[index][0] == friends[index][0].capitalize()): 7 | print(friends[index]) 8 | else: 9 | count += 1 10 | index += 1 11 | else : 12 | print(f"Friends Printed And Ignored Names Count Is {count}") 13 | -------------------------------------------------------------------------------- /assignments/047-050/03.py: -------------------------------------------------------------------------------- 1 | skills = ["HTML", "CSS", "JavaScript", "PHP", "Python"] 2 | 3 | # skills.reverse() 4 | # while skills: 5 | # print(skills.pop()) 6 | 7 | while skills: 8 | print(skills.pop(0)) 9 | -------------------------------------------------------------------------------- /assignments/047-050/04.py: -------------------------------------------------------------------------------- 1 | 2 | my_friends = [] 3 | 4 | maxCount = 4 5 | 6 | 7 | index = 0 8 | 9 | while maxCount > 0: 10 | new = input("Friend to add: ").strip() 11 | if new.isupper(): 12 | print("Invalid Name") 13 | elif new.islower(): 14 | new.capitalize() 15 | my_friends.append(new) 16 | print(f"Friend {new} Added => 1st Letter Become Capital") 17 | maxCount -= 1 18 | else: 19 | new.capitalize() 20 | my_friends.append(new) 21 | print(f"Friend {new} Added") 22 | maxCount -= 1 23 | print(f"Names Left in List Is {maxCount}") 24 | 25 | 26 | -------------------------------------------------------------------------------- /assignments/051-055/01.py: -------------------------------------------------------------------------------- 1 | # Input 2 | 3 | my_nums = [15, 81, 5, 17, 20, 21, 13] 4 | my_nums.sort() 5 | index = 0 6 | for num in my_nums: 7 | if num % 5 == 0: 8 | index += 1 9 | print(f"{index } => {num}") 10 | else: 11 | print("All Numbers Printed") -------------------------------------------------------------------------------- /assignments/051-055/02.py: -------------------------------------------------------------------------------- 1 | num = 1 2 | 3 | while num <= 20: 4 | if num == 6 or num == 8 or num == 12: 5 | pass 6 | else: 7 | print(str(num).zfill(2)) 8 | num += 1 9 | else: 10 | print("All Numbers Printed") -------------------------------------------------------------------------------- /assignments/051-055/03.py: -------------------------------------------------------------------------------- 1 | # Input 2 | my_ranks = { 3 | 'Math': 'A', 4 | "Science": 'B', 5 | 'Drawing': 'A', 6 | 'Sports': 'C' 7 | } 8 | 9 | letter_equvilent = { 10 | "A" : 100, 11 | "B" : 80, 12 | "C" : 40, 13 | } 14 | 15 | # Needed Output 16 | "My Rank in Math Is A And This Equal 100 Points" 17 | "My Rank in Science Is B And This Equal 80 Points" 18 | "My Rank in Drawing Is A And This Equal 100 Points" 19 | "My Rank in Sports Is C And This Equal 40 Points" 20 | "Total Points Is 320" 21 | 22 | total = 0 23 | 24 | for skil,degree in my_ranks.items(): 25 | print(f"My Rank in {skil} Is {degree} And This Equal {letter_equvilent[degree]} Points") 26 | total += letter_equvilent[degree] 27 | else: 28 | print(f"Total Points Is {total}") -------------------------------------------------------------------------------- /assignments/051-055/04.py: -------------------------------------------------------------------------------- 1 | students = { 2 | "Ahmed": { 3 | "Math": "A", 4 | "Science": "D", 5 | "Draw": "B", 6 | "Sports": "C", 7 | "Thinking": "A" 8 | }, 9 | "Sayed": { 10 | "Math": "B", 11 | "Science": "B", 12 | "Draw": "B", 13 | "Sports": "D", 14 | "Thinking": "A" 15 | }, 16 | "Mahmoud": { 17 | "Math": "D", 18 | "Science": "A", 19 | "Draw": "A", 20 | "Sports": "B", 21 | "Thinking": "B" 22 | } 23 | } 24 | 25 | letter_equivlent = { 26 | "A":100, 27 | "B":80, 28 | "C":40, 29 | "D":20 30 | } 31 | 32 | table_width = 40 33 | for student,subjects in students.items(): 34 | # print Header 35 | print('"'+"-"*table_width +'"') 36 | print('"'+(f"Student Name => {student}").center(table_width)+'"') 37 | print('"'+"-"*table_width +'"') 38 | 39 | total = 0 40 | # loop for subjects 41 | for subject,degree in subjects.items(): 42 | print('"'+(f"- {subject} => {letter_equivlent[degree]} Points").center(table_width)+'"') 43 | total += letter_equivlent[degree] 44 | else: 45 | print('"'+f"Total Points For {student} Is {total}".center(table_width)+'"') 46 | 47 | # print(len("------------------------------")) 48 | 49 | # Needed Output 50 | # "------------------------------" 51 | # "-- Student Name => Ahmed" 52 | # "------------------------------" 53 | # "- Math => 100 Points" 54 | # "- Science => 20 Points" 55 | # "- Draw => 80 Points" 56 | # "- Sports => 40 Points" 57 | # "- Thinking => 100 Points" 58 | # "Total Points For Ahmed Is 340" -------------------------------------------------------------------------------- /assignments/056-059/01.py: -------------------------------------------------------------------------------- 1 | def calculate(num1,num2,operation = "add"): 2 | if str(operation).lower() == "add" or operation.lower()== "a": 3 | # return num1 + num2 4 | return framedMsgs(f"Add | {num1} + {num2} = {num1 + num2}") 5 | elif operation.lower() == "multiply" or operation.lower() == "m": 6 | # return num1 * num2 7 | return framedMsgs(f"Multiply | {num1} x {num2} = {num1 * num2}") 8 | elif operation.lower() == "subtract" or operation.lower() == "s": 9 | # return num1 - num2 10 | return framedMsgs(f"Subtract | {num1} - {num2} = {num1 - num2}") 11 | else : 12 | return framedMsgs("Use [add | multiply | subtract]") 13 | 14 | def framedMsgs(msg,width=40): 15 | return f'{"-"*width}\n|{msg.center(width-2)}|\n{"-"*width}' 16 | 17 | print(calculate(10, 20)) # 30 18 | print(calculate(10, 20, "AdD")) # 30 19 | print(calculate(10, 20, "a")) # 30 20 | print(calculate(10, 20, "A")) # 30 21 | 22 | print(calculate(10, 20, "S")) # -10 23 | print(calculate(10, 20, "subTRACT")) # -10 24 | 25 | print(calculate(10, 20, "Multiply")) # 200 26 | print(calculate(10, 20, "m")) # 200 27 | 28 | print(calculate(10, 20, "h")) # 200 -------------------------------------------------------------------------------- /assignments/056-059/02.py: -------------------------------------------------------------------------------- 1 | from unittest import result 2 | 3 | 4 | def addition(*numbers): 5 | result = 00 6 | for num in numbers: 7 | if num == 10: 8 | continue 9 | elif num == 5: 10 | result -= 5 11 | else : 12 | result += num 13 | else: 14 | return result 15 | 16 | print(addition(10, 20, 30, 10, 15)) # 65 17 | print(addition(10, 20, 30, 10, 15, 5, 100)) # 160 -------------------------------------------------------------------------------- /assignments/056-059/03.py: -------------------------------------------------------------------------------- 1 | def show_skills(name,*skils): 2 | print( framedMsg(f"Hello {name} Your Skills are")) 3 | if len(skils) == 0: 4 | print( framedMsg(f"Hello {name} You Have No Skills To Show")) 5 | else: 6 | for skil in skils: 7 | print( framedMsg(skil)) 8 | 9 | 10 | def framedMsg(msg,width=40): 11 | return f'{"-"*width}\n|{msg.center(width-2)}|\n{"-"*width}' 12 | 13 | # Input 14 | show_skills("Osama", "HTML", "CSS", "JS", "Python") 15 | 16 | show_skills("Ahmed") -------------------------------------------------------------------------------- /assignments/056-059/04.py: -------------------------------------------------------------------------------- 1 | def framedMsg(msg,width=40): 2 | return f'{"-"*width}\n|{msg.center(width-2)}|\n{"-"*width}' 3 | 4 | def say_hello(name="Unknown", age = "Unknown", country="Unknown"): 5 | return f"Hello {name} Your Age Is {age} And You Live In {country}" 6 | 7 | 8 | print(say_hello("Osama", 38, "Egypt")) 9 | print(say_hello()) -------------------------------------------------------------------------------- /assignments/060-064/01.py: -------------------------------------------------------------------------------- 1 | def get_score(**subjects): 2 | for key,value in subjects.items(): 3 | print(f"{key} => {value}") 4 | 5 | get_score(Math=90, Science=80, Language=70) 6 | 7 | get_score(Logic=70, Problems=60) -------------------------------------------------------------------------------- /assignments/060-064/02.py: -------------------------------------------------------------------------------- 1 | def get_people_scores(name="",**subjects): 2 | print("-"*40) 3 | if (name and not subjects): 4 | print(f"Hello {name} You Have No Scores To Show") 5 | elif(name and subjects): 6 | print(f"Hello {name} This Is Your Score Table:") 7 | for key,value in subjects.items(): 8 | print(f"{key} => {value}") 9 | else: 10 | for key,value in subjects.items(): 11 | print(f"{key} => {value}") 12 | 13 | print("-"*40) 14 | 15 | # Test 1 16 | get_people_scores("Osama", Math=90, Science=80, Language=70) 17 | 18 | # Output 19 | "Hello Osama This Is Your Score Table:" 20 | "Math => 90" 21 | "Science => 80" 22 | "Language => 70" 23 | 24 | # Test 2 25 | get_people_scores("Mahmoud", Logic=70, Problems=60) 26 | 27 | # Output 28 | "Hello Mahmoud This Is Your Score Table:" 29 | "Logic => 70" 30 | "Problems => 60" 31 | 32 | # Test 3 33 | get_people_scores(Logic=70, Problems=60) 34 | 35 | # Output 36 | "Logic => 70" 37 | "Problems => 60" 38 | 39 | # Test 4 40 | get_people_scores("Ahmed") 41 | 42 | # Output 43 | "Hello Ahmed You Have No Scores To Show" -------------------------------------------------------------------------------- /assignments/060-064/03.py: -------------------------------------------------------------------------------- 1 | def get_the_scores(name="",**subjects): 2 | print("-"*40) 3 | if (name and not subjects): 4 | print(f"Hello {name} You Have No Scores To Show") 5 | elif(name and subjects): 6 | print(f"Hello {name} This Is Your Score Table:") 7 | for key,value in subjects.items(): 8 | print(f"{key} => {value}") 9 | else: 10 | for key,value in subjects.items(): 11 | print(f"{key} => {value}") 12 | 13 | print("-"*40) 14 | 15 | scores_list = { 16 | "Math" : 90, 17 | "Science" : 80, 18 | "Language" : 70 19 | } 20 | 21 | # Test 1 22 | get_the_scores("Osama", **scores_list) 23 | 24 | # Output 25 | "Hello Osama This Is Your Score Table:" 26 | "Math => 90" 27 | "Science => 80" 28 | "Language => 70" 29 | 30 | # Test 2 31 | get_the_scores("Osama") 32 | 33 | # Output 34 | "Hello Osama You Have No Scores To Show" 35 | 36 | # Test 3 37 | get_the_scores(**scores_list) 38 | 39 | # Output 40 | "Math => 90" 41 | "Science => 80" 42 | "Language => 70" -------------------------------------------------------------------------------- /assignments/065-068/01.py: -------------------------------------------------------------------------------- 1 | from operator import index 2 | import os 3 | 4 | #FIXME need to resolve 5 | desktop_path = r"C:\Users\Eltantawy\OneDrive\Desktop" 6 | newFile = open(f"{desktop_path}\\assign.py","w") 7 | 8 | index = 1 9 | # os.mkdir(f"{desktop_path}\Python") 10 | while index <50 : 11 | newFile = open(f"{desktop_path}\Python\\txt{index}.py","w") 12 | index += 1 13 | 14 | print(os.getcwd()) 15 | # print(os.path.abspath(__file__)) 16 | print(os.path.dirname(__file__)) 17 | print(newFile.name) 18 | print(newFile.name) -------------------------------------------------------------------------------- /assignments/065-068/02.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/assignments/065-068/02.py -------------------------------------------------------------------------------- /assignments/065-068/03.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/assignments/065-068/03.py -------------------------------------------------------------------------------- /assignments/069-071/01.py: -------------------------------------------------------------------------------- 1 | values = (0, 1, 2) 2 | 3 | # iterate on value list if any value is true 4 | if any(values): # true 5 | 6 | my_var = 0 # local var=0 7 | 8 | 9 | my_list = [True, 1, 1, ["A", "B"], 10.5, my_var] # my_var none 10 | 11 | # True - False - False 12 | if all(my_list[:4]) or all(my_list[:6]) or all(my_list[:]): 13 | 14 | print("Good") # Answer is Good 15 | 16 | else: 17 | 18 | print("Bad") -------------------------------------------------------------------------------- /assignments/069-071/02.py: -------------------------------------------------------------------------------- 1 | v = 40 2 | 3 | my_range = list(range(v)) 4 | 5 | print(sum(my_range, v) + pow(v, v, v)) # 820 -------------------------------------------------------------------------------- /assignments/069-071/03.py: -------------------------------------------------------------------------------- 1 | n = 20 2 | 3 | l = list(range(n)) 4 | 5 | if round(sum(l) / n) == max(0, 3, 10, 2, -100, -23, 9): 6 | 7 | print("Good") 8 | 9 | # Output => Good -------------------------------------------------------------------------------- /assignments/069-071/04.py: -------------------------------------------------------------------------------- 1 | def my_all(list): 2 | for num in list: 3 | if(bool(num)): 4 | pass 5 | else : 6 | return False 7 | return True 8 | 9 | def my_any(list): 10 | for num in list: 11 | if(bool(num)): 12 | return True 13 | else: 14 | pass 15 | return False 16 | 17 | def my_min(list): 18 | minVal = list[0] 19 | for num in list: 20 | if(num < minVal): 21 | minVal=num 22 | return minVal 23 | 24 | def my_max(list): 25 | maxVal = list[0] 26 | for num in list: 27 | if(num > maxVal): 28 | maxVal=num 29 | return maxVal 30 | 31 | # my_all 32 | print(my_all([1, 2, 3])) # True 33 | print(my_all([1, 2, 3, []])) # False 34 | 35 | # # my_any 36 | print(my_any([0, 1, [], False])) # True 37 | print(my_any([(), 0, False])) # False 38 | 39 | # # my_min 40 | print(my_min([10, 100, -20, -100, 50])) # -100 41 | print(my_min((10, 100, -20, -100, 50))) # -100 42 | 43 | # my_max 44 | print(my_max([10, 100, -20, -100, 50, 700])) # 700 45 | print(my_max((10, 100, -20, -100, 50, 700))) # 700 -------------------------------------------------------------------------------- /assignments/072-075/01.py: -------------------------------------------------------------------------------- 1 | #--------# 2 | # 01 # 3 | #--------# 4 | friends_map = ["AEmanS", "AAhmedS", "DSamehF", "LOsamaL"] 5 | 6 | def remove_chars(name): 7 | return name[1:-1] 8 | 9 | for name in map(remove_chars,friends_map): 10 | print(name) 11 | 12 | #--------# 13 | # 02 # 14 | #--------# 15 | friends_map = ["AEmanS", "AAhmedS", "DSamehF", "LOsamaL"] 16 | 17 | def remove_chars(name): 18 | return name[1:-1] 19 | 20 | cleaned_list = map(remove_chars,friends_map) 21 | for name in cleaned_list: 22 | print(name) -------------------------------------------------------------------------------- /assignments/072-075/02.py: -------------------------------------------------------------------------------- 1 | from operator import truediv 2 | 3 | 4 | #--------# 5 | # 01 # 6 | #--------# 7 | friends_filter = ["Osama", "Wessam", "Amal", "Essam", "Gamal", "Othman"] 8 | 9 | def get_names(name): 10 | if(name.endswith("m")): 11 | return True 12 | 13 | for name in filter(get_names,friends_filter): 14 | print(name) 15 | 16 | #--------# 17 | # 02 # 18 | #--------# 19 | friends_filter = ["Osama", "Wessam", "Amal", "Essam", "Gamal", "Othman"] 20 | 21 | def get_names(name): 22 | if(name.endswith("m")): 23 | return True 24 | 25 | names = filter(get_names,friends_filter) 26 | for name in names: 27 | print(name) -------------------------------------------------------------------------------- /assignments/072-075/03.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | 3 | def numProduct(a,b): 4 | return a*b 5 | 6 | nums = [2, 4, 6, 2] 7 | 8 | print(reduce(numProduct,nums)) 9 | print(reduce(lambda a,b: a*b,nums)) 10 | 11 | # Output 12 | 96 -------------------------------------------------------------------------------- /assignments/072-075/04.py: -------------------------------------------------------------------------------- 1 | from typing import Iterator 2 | 3 | 4 | 5 | #--------# 6 | # 01 # 7 | #--------# 8 | 9 | skills = ("HTML", "CSS", 10, "PHP", "Python", 20, "JavaScript") 10 | filtered = filter(lambda a: not str(a).isdigit(),skills) 11 | for index,skil in enumerate(reversed(list(filtered)),50): 12 | print(f'"{index} - {skil}"') 13 | 14 | #--------# 15 | # 02 # 16 | #--------# 17 | print("#"*50) 18 | skills = ("HTML", "CSS", 10, "PHP", "Python", 20, "JavaScript") 19 | index = 50 20 | cursor = len(skills)-1 21 | while cursor >= 0: 22 | if not str(skills[cursor]).isdigit(): 23 | print(f'"{index} - {skills[cursor]}"') 24 | index += 1 25 | cursor -= 1 26 | -------------------------------------------------------------------------------- /assignments/076-078/01/01.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | "Random Number Between 10 And 50 =>" "Show The Random Number Here" 4 | "Random Even Number Between 2 And 10 =>" "Show The Random Even Number Here" 5 | "Random Odd Number Between 1 And 9 =>" "Show The Random Odd Number Here" 6 | 7 | # Module Methods Content Here 8 | 9 | print(f"Random Number Between 10 And 50 => {random.randint(10,50)}") 10 | print(f"Random Number Between 2 And 10 => {random.randint(2,10)}") 11 | print(f"Random Number Between 1 And 9 => {random.randint(1,9)}") 12 | 13 | print(dir(random)) -------------------------------------------------------------------------------- /assignments/076-078/02/Python/__pycache__/my_mod.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/assignments/076-078/02/Python/__pycache__/my_mod.cpython-310.pyc -------------------------------------------------------------------------------- /assignments/076-078/02/Python/my_mod.py: -------------------------------------------------------------------------------- 1 | def say_hello (name): 2 | print(f"Hello {name}") 3 | 4 | 5 | def say_welcome(name): 6 | print(f"Welcome {name}") 7 | -------------------------------------------------------------------------------- /assignments/076-078/02/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | dirName =os.path.dirname(os.path.abspath(__file__)) 5 | sys.path.append(f"{dirName}\Python\\") 6 | 7 | import my_mod 8 | my_mod.say_welcome("Osama") 9 | my_mod.say_hello("Osama") 10 | -------------------------------------------------------------------------------- /assignments/076-078/03/Python/__pycache__/my_mod.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/assignments/076-078/03/Python/__pycache__/my_mod.cpython-310.pyc -------------------------------------------------------------------------------- /assignments/076-078/03/Python/my_mod.py: -------------------------------------------------------------------------------- 1 | def say_hello (name): 2 | print(f"Hello {name}") 3 | 4 | 5 | def say_welcome(name): 6 | print(f"Welcome {name}") 7 | -------------------------------------------------------------------------------- /assignments/076-078/03/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | dirName =os.path.dirname(os.path.abspath(__file__)) 5 | sys.path.append(f"{dirName}\Python\\") 6 | 7 | from my_mod import say_welcome 8 | 9 | say_welcome("Osama") 10 | -------------------------------------------------------------------------------- /assignments/076-078/04/Python/__pycache__/my_mod.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/assignments/076-078/04/Python/__pycache__/my_mod.cpython-310.pyc -------------------------------------------------------------------------------- /assignments/076-078/04/Python/my_mod.py: -------------------------------------------------------------------------------- 1 | def say_hello (name): 2 | print(f"Hello {name}") 3 | 4 | def say_welcome(name): 5 | print(f"Welcome {name}") 6 | -------------------------------------------------------------------------------- /assignments/076-078/04/main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | dirName =os.path.dirname(os.path.abspath(__file__)) 5 | sys.path.append(f"{dirName}\Python\\") 6 | 7 | from my_mod import say_welcome as new_welcome 8 | 9 | new_welcome("Osama") 10 | -------------------------------------------------------------------------------- /assignments/079-080/01.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | today = datetime.datetime.now() 4 | needed = datetime.datetime(2021,6,25) 5 | # The Date Is "2021, 6, 25" 6 | # Today Is "2021, 8, 10" 7 | 8 | # Message Will Be 9 | "Days From 2021-06-25 To 2021-08-10 Is => 46" 10 | 11 | print(f"Days From {needed.date()} To {today.date()} Is => {(today-needed).days}") -------------------------------------------------------------------------------- /assignments/079-080/02.py: -------------------------------------------------------------------------------- 1 | # Today Is "2021, 8, 10" 2 | 3 | "2021-08-10" 4 | "Aug 10, 2021" 5 | "10 - Aug - 2021" 6 | "10 / Aug / 21" 7 | "10 / August / 2021" 8 | "Tue, 10 August 2021" 9 | from datetime import datetime 10 | 11 | 12 | today =datetime.now() 13 | print(today.date()) 14 | print(today.strftime("%b %d, %Y")) 15 | print(today.strftime("%d - %b - %Y")) 16 | print(today.strftime("%d / %b / %y")) 17 | print(today.strftime("%d / %B / %Y")) 18 | print(today.strftime("%a,%d %b %Y")) -------------------------------------------------------------------------------- /assignments/081-085/01.py: -------------------------------------------------------------------------------- 1 | def reverse_string(my_string): 2 | # Your Code Here 3 | length = len(my_string)-1 4 | while length >= 0: 5 | yield my_string[length] 6 | length -= 1 7 | 8 | # Reverse The String 9 | for c in reverse_string("Elzero"): 10 | print(c) -------------------------------------------------------------------------------- /assignments/081-085/02.py: -------------------------------------------------------------------------------- 1 | def hashMaker(fun): 2 | def maker(): 3 | print("Sugar Added From Decorators") 4 | fun() 5 | print("####################") 6 | return maker 7 | 8 | # Create Your Decorator Here 9 | 10 | @hashMaker 11 | def make_tea(): 12 | print("Tea Created") 13 | 14 | @hashMaker 15 | def make_coffe(): 16 | print("Coffe Created") 17 | 18 | make_tea() 19 | make_coffe() 20 | 21 | # Needed Output 22 | 23 | "Sugar Added From Decorators" 24 | "Tea Created" 25 | "####################" 26 | "Sugar Added From Decorators" 27 | "Coffe Created" 28 | "####################" -------------------------------------------------------------------------------- /assignments/086-089/01.py: -------------------------------------------------------------------------------- 1 | """ 2 | Solve Elzero Assigments 3 | """ 4 | from functools import reduce 5 | 6 | 7 | my_list = ["E", "Z", "R", 1, 2, 3] 8 | my_tuple = ("L", "E", "O") 9 | my_data = [] 10 | 11 | for data in zip(my_list, my_tuple): 12 | a,b = data 13 | my_data.append(a) 14 | my_data.append(b) 15 | 16 | final_string =reduce(lambda a,b: f"{a}{b}",my_data) 17 | print(final_string) 18 | -------------------------------------------------------------------------------- /assignments/086-089/02.py: -------------------------------------------------------------------------------- 1 | """ 2 | Assignment solution 3 | """ 4 | from functools import reduce 5 | 6 | 7 | my_list1 = ["E", "L", "Z", "E", "R", "O", 1, 2] 8 | my_tuple = ("E", "Z", "R", 1, 2, "E", "R", "O") 9 | my_list2 = ("L", "E", "O", 1, 2, "E", "R", "O") 10 | my_data = [] 11 | 12 | for item1, item2, item3 in zip(my_list1, my_tuple, my_list2): 13 | if str(item1).isalpha(): 14 | my_data.append(item1) 15 | last_added = item1 16 | 17 | 18 | final_string = reduce(lambda a,b:f"{a}{b}",my_data) 19 | 20 | print(final_string) 21 | -------------------------------------------------------------------------------- /assignments/086-089/03/elzero-pillow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/assignments/086-089/03/elzero-pillow.png -------------------------------------------------------------------------------- /assignments/086-089/03/main.py: -------------------------------------------------------------------------------- 1 | """ 2 | Assigment Soultion 3 | """ 4 | 5 | from PIL import Image 6 | 7 | # Get img 8 | elzero_image = Image.open(r"python\assignments\081-085\03\elzero-pillow.png") 9 | 10 | # First img 11 | croped_area = (400,0,800,400) 12 | cropped_img = elzero_image.crop(croped_area) 13 | cropped_img = cropped_img.convert("L") 14 | cropped_img.show() 15 | 16 | # second img 17 | croped_area = (0,400,1200,800) 18 | cropped_img = elzero_image.crop(croped_area) 19 | cropped_img = cropped_img.convert("L") 20 | cropped_img = cropped_img.rotate(180) 21 | cropped_img.show() 22 | -------------------------------------------------------------------------------- /assignments/086-089/04.py: -------------------------------------------------------------------------------- 1 | """ 2 | Assignment solution 3 | """ 4 | 5 | def say_hello_to(name): 6 | """ 7 | parameter(someone) => Person Name 8 | Function To Say Hello To Anyon 9 | """ 10 | return f"Hello {name}" 11 | 12 | print(say_hello_to("Osama")) # "Hello Osama" 13 | print(say_hello_to.__doc__) -------------------------------------------------------------------------------- /assignments/086-089/05/main.py: -------------------------------------------------------------------------------- 1 | """ 2 | Assignment solution 3 | """ 4 | 5 | my_friends = ["Ahmed", "Osama", "Sayed"] 6 | 7 | def say_hello(some_peoples) -> list: 8 | ''' Function to say Hello''' 9 | for someone in some_peoples: 10 | print(f"Hello {someone}") 11 | 12 | say_hello(my_friends) 13 | -------------------------------------------------------------------------------- /assignments/090-094/01.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | try: 6 | number = input("Add Your Number ") 7 | if str(number).isalpha(): 8 | raise Exception("Only Numbers Allowed") 9 | else: 10 | number = int(number) 11 | if len(str(number)) > 1: 12 | raise IndexError("Only One Character Allowed") 13 | if number>0: 14 | print("####################") 15 | print(f"The Number Is {number}") 16 | print("####################") 17 | else: 18 | raise ValueError("Number Must Be Larger Than 0") 19 | finally: 20 | pass 21 | -------------------------------------------------------------------------------- /assignments/090-094/02.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | LETTER = input("Add Letter From A to Z") 6 | 7 | try: 8 | if not LETTER.isalpha() or LETTER.upper() != LETTER: 9 | raise ValueError 10 | if len(LETTER) > 1: 11 | raise IndexError 12 | print(f"You Typed {LETTER}") 13 | except IndexError: 14 | print("You Must Write One Character Only") 15 | except ValueError: 16 | print("The Letter Not In A - Z") 17 | -------------------------------------------------------------------------------- /assignments/090-094/03.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | def calculate(num1:int, num2:int) -> int: 6 | '''Doc''' 7 | return num1 + num2 8 | 9 | print(calculate(20, 30)) 10 | -------------------------------------------------------------------------------- /assignments/095-102/01.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | ########################################### 6 | # => 01 7 | ##################### 8 | # => "eeeeE llllLl lllzzZzzzz eroe operationr pollo" 9 | ##################### 10 | # => (E|e|l|z|e|r|o)\s 11 | ##################### 12 | 13 | ########################################### 14 | # => 02 15 | ##################### 16 | # => "EElzero11 LElzero111 ZElzero1111 EElzero11111 RElzero111111 OElzero1111111" 17 | ##################### 18 | # => (LElzero) 19 | ##################### 20 | 21 | ########################################### 22 | # => 03 23 | ##################### 24 | # => 25 | ##################### 26 | # => \s[A-Z]{2}\s[0-9]{3}\s\w{0,6} 27 | ##################### 28 | 29 | ########################################### 30 | # => 04 31 | ##################### 32 | # http://www.elzero.org:8888/link.php 33 | # https://elzero.org:8888/link.php 34 | # http://www.elzero.com/link.py 35 | # https://elzero.com/link.py 36 | # http://www.elzero.net 37 | # https://elzero.net 38 | ##################### 39 | # => https?://(www)?.\w+[^net](\w+)(:\d+)?/(\w+.\w+) 40 | ##################### 41 | 42 | ########################################### 43 | # => 05 44 | ##################### 45 | # http 46 | # https 47 | # abcd 48 | # abcd 49 | ##################### 50 | # => https? 51 | # => [htps] 52 | # => [e-z] 53 | # => ht{2}ps? 54 | # => [^a-d] 55 | ##################### 56 | -------------------------------------------------------------------------------- /assignments/096-116/01.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | class Game: 6 | '''Doc''' 7 | def __init__(self,name,developer,year,price): 8 | '''Doc''' 9 | self.name = name 10 | self.developer = developer 11 | self.year = year 12 | self.price = price 13 | def price_in_pounds(self): 14 | '''Doc''' 15 | return f"Price In Egypt Is {self.price * 18.43} Egyptian Pounds" 16 | 17 | 18 | game_one = Game("Ys", "Falcom", 2010, 50) 19 | 20 | print(f"Game Name Is \"{game_one.name}\", ", end="") 21 | print(f"Developer Is \"{game_one.developer}\", ", end="") 22 | print(f"Release Date Is \"{game_one.year}\", ", end="") 23 | print(f"Price In Egypt Is {game_one.price_in_pounds()}", end="") 24 | 25 | # Needed Output 26 | # "Game Name Is "Ys", Developer Is "Falcom", 27 | # Release Date Is "2010", 28 | # Price In Egypt Is 780.0 Egyptian Pounds" 29 | -------------------------------------------------------------------------------- /assignments/096-116/02.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | class User: 6 | '''Doc''' 7 | def __init__(self,name,middle_name,age,gender): 8 | '''Doc''' 9 | self.name = name 10 | self.middle_name = middle_name 11 | self.age = age 12 | self.gender = gender 13 | def full_details(self): 14 | '''Doc''' 15 | return f'Hello Mr {self.name} {self.middle_name[0]}. [{40-self.age}] Years To Reach 40' 16 | 17 | user_one = User("Osama", "Mohamed", 38, "Male") 18 | user_two = User("Eman", "Omar", 25, "Female") 19 | 20 | print(user_one.full_details()) # Hello Mr Osama M. [02] Years To Reach 40 21 | print(user_two.full_details()) # Hello Mrs Eman O. [15] Years To Reach 40 22 | -------------------------------------------------------------------------------- /assignments/096-116/03.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | class Message: 5 | '''Doc''' 6 | @classmethod 7 | def print_message(cls): 8 | '''Doc''' 9 | return "Hello From Class Message" 10 | 11 | print(Message.print_message()) 12 | 13 | # Output 14 | # Hello From Class Message -------------------------------------------------------------------------------- /assignments/096-116/04.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | 6 | # from typing import overload 7 | 8 | 9 | class Games: 10 | '''Doc''' 11 | # @overload 12 | # def __init__(self,game_name:str): 13 | # '''DOC''' 14 | # self.game = game_name 15 | 16 | # @overload 17 | # def __init__(self,game_list:list): 18 | # '''DOC''' 19 | # self.game = game_list 20 | 21 | # def __init__(self,games_count:float): 22 | # '''DOC''' 23 | # self.game = games_count 24 | 25 | def __init__(self,game): 26 | '''DOC''' 27 | self.game = game 28 | 29 | def show_games(self): 30 | '''DOC''' 31 | if isinstance(self.game,str): 32 | print(f'I Have One Game Called "{self.game}"') 33 | 34 | elif isinstance(self.game,list): 35 | print('I Have Many Games:') 36 | for item in self.game: 37 | print(f"-- {item}") 38 | 39 | elif isinstance(self.game,int) or isinstance(self.game,float) : 40 | print(f"I Have {self.game} Game.") 41 | 42 | my_game = Games("Shadow Of Mordor") 43 | my_games_names = Games(["Ys II", "Ys Oath In Felghana", "YS Origin"]) 44 | my_games_count = Games(80) 45 | 46 | my_game.show_games() 47 | # Ouput 48 | # I Have One Game Called "Shadow Of Mordor" 49 | 50 | my_games_names.show_games() 51 | # Ouput 52 | # I Have Many Games: 53 | # -- Ys II 54 | # -- Ys Oath In Felghana 55 | # -- YS Origin 56 | 57 | my_games_count.show_games() 58 | # Output 59 | # I Have 80 Game. 60 | -------------------------------------------------------------------------------- /assignments/096-116/05.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | class Members: 6 | '''DOC''' 7 | def __init__(self, n, p): 8 | '''DOC''' 9 | self.name = n 10 | self.permission = p 11 | 12 | def show_info(self): 13 | '''DOC''' 14 | return f"Your Name Is {self.name} And You Are {self.permission}" 15 | 16 | # Create Admin Class Here 17 | class Admins(Members): 18 | '''DOC''' 19 | # Create Moderators Class Here 20 | class Moderators(Members): 21 | '''DOC''' 22 | 23 | member_one = Admins("Osama", "Admin") 24 | member_two = Moderators("Ahmed", "Moderator") 25 | 26 | print(member_one.show_info()) 27 | # Output 28 | # Your Name Is Osama And You Are Admin 29 | 30 | print(member_two.show_info()) 31 | # Output 32 | # Your Name Is Ahmed And You Are Moderator 33 | -------------------------------------------------------------------------------- /assignments/096-116/06.py: -------------------------------------------------------------------------------- 1 | """ 2 | DOC 3 | """ 4 | 5 | class A: 6 | '''DOC''' 7 | def __init__(self, one): 8 | '''DOC''' 9 | self.one = one 10 | 11 | class B: 12 | '''DOC''' 13 | def __init__(self, two): 14 | '''DOC''' 15 | self.two = two 16 | 17 | class C: 18 | '''DOC''' 19 | def __init__(self, three): 20 | '''DOC''' 21 | self.three = three 22 | 23 | # Write The Class Called "Text" Here 24 | class Text(A,B,C): 25 | '''DOC''' 26 | def __init__(self, one,two,three): 27 | '''DOC''' 28 | A.__init__(self, one) 29 | B.__init__(self, two) 30 | C.__init__(self, three) 31 | def show_name(self): 32 | '''DOC''' 33 | return f"The Name Is {self.one}{self.two}{self.three}" 34 | 35 | the_name = Text("El", "ze", "ro") 36 | 37 | print(the_name.show_name()) 38 | 39 | # Ouput 40 | # The Name Is Elzero 41 | -------------------------------------------------------------------------------- /course/078/test.py: -------------------------------------------------------------------------------- 1 | import pyfiglet 2 | 3 | print(pyfiglet.figlet_format("Eltantawy")) -------------------------------------------------------------------------------- /course/089/test.py: -------------------------------------------------------------------------------- 1 | ############### 2 | """ 3 | Test file 4 | """ 5 | ############### 6 | 7 | def say_hello(name): 8 | '''Function to say hello to user''' 9 | msg = "Hello" 10 | return f"{msg} {name}" 11 | 12 | say_hello("Ahmed") 13 | -------------------------------------------------------------------------------- /course/118 copy/main.py: -------------------------------------------------------------------------------- 1 | # import os 2 | import sqlite3 3 | 4 | 5 | db = sqlite3.connect("app.db") 6 | # print(os.getcwd()) 7 | 8 | db.execute("CREATE TABLE IF NOT EXISTS skills (name TEXT, progress INTEGER,user_id INTEGER)") 9 | 10 | db.close() 11 | -------------------------------------------------------------------------------- /course/118/main.py: -------------------------------------------------------------------------------- 1 | # import os 2 | import sqlite3 3 | 4 | 5 | db = sqlite3.connect("app.db") 6 | # print(os.getcwd()) 7 | 8 | db.execute("CREATE TABLE IF NOT EXISTS skills (name TEXT, progress INTEGER,user_id INTEGER)") 9 | 10 | db.close() -------------------------------------------------------------------------------- /course/119/main.py: -------------------------------------------------------------------------------- 1 | # import os 2 | import sqlite3 3 | 4 | 5 | db = sqlite3.connect("app.db") 6 | # print(os.getcwd()) 7 | 8 | cr = db.cursor() 9 | 10 | cr.execute("CREATE TABLE IF NOT EXISTS skills (name TEXT, progress INTEGER,user_id INTEGER)") 11 | 12 | cr.execute("CREATE TABLE IF NOT EXISTS users (name TEXT,user_id INTEGER)") 13 | 14 | 15 | cr.execute("INSERT INTO users(name ,user_id ) VALUES('ali',1)") 16 | cr.execute("INSERT INTO users(name ,user_id ) VALUES('ahmad',2)") 17 | cr.execute("INSERT INTO users(name ,user_id ) VALUES('sayed',3)") 18 | db.commit() 19 | 20 | db.close() 21 | -------------------------------------------------------------------------------- /course/120/main.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | 3 | # Create Database And Connect 4 | db = sqlite3.connect("app.db") 5 | 6 | # Setting Up The Cursor 7 | cr = db.cursor() 8 | 9 | # Create The Tables and Fields 10 | # cr.execute("create table if not exists users (user_id integer, name text)") 11 | # cr.execute( 12 | # "create table if not exists skills (name text, progress integer, user_id integer)") 13 | 14 | # Inserting Data 15 | # cr.execute("insert into users(user_id, name) values(1, 'Ahmed')") 16 | # cr.execute("insert into users(user_id, name) values(2, 'Sayed')") 17 | # cr.execute("insert into users(user_id, name) values(3, 'Osama')") 18 | 19 | # Fetch Data 20 | cr.execute("select * from skills") 21 | 22 | print(cr.fetchone()) 23 | print(cr.fetchone()) 24 | print(cr.fetchone()) 25 | print(cr.fetchone()) 26 | 27 | # print(cr.fetchall()) 28 | 29 | # print(cr.fetchmany(2)) 30 | 31 | # Save (Commit) Changes 32 | db.commit() 33 | 34 | # Close Database 35 | db.close() -------------------------------------------------------------------------------- /course/121/main.py: -------------------------------------------------------------------------------- 1 | ''' 2 | DOC 3 | ''' 4 | import sqlite3 5 | 6 | def get_all_data(): 7 | '''doc''' 8 | try: 9 | 10 | # Connect To Database 11 | db = sqlite3.connect("app.db") 12 | 13 | # Print Success Message 14 | print("Connected To Database Successfully") 15 | 16 | # Setting Up The Cursor 17 | cr = db.cursor() 18 | 19 | # Fetch Data From Database 20 | cr.execute("select * from users") 21 | 22 | # Assign Data To Variable 23 | results = cr.fetchall() 24 | 25 | # Print Number Of Rows 26 | print(f"Database Has {len(results)} Rows.") 27 | 28 | # Printing Message 29 | print("Showing Data:") 30 | 31 | # Loop On Results 32 | for row in results: 33 | print(f"UserID => {row[0]},", end=" ") 34 | print(f"Username => {row[1]}") 35 | 36 | except sqlite3.Error as er: 37 | print(f"Error Reading Data {er}") 38 | 39 | finally: 40 | 41 | if (db): 42 | 43 | # Close Database Connection 44 | db.close() 45 | print("Connection To Database Is Closed") 46 | 47 | get_all_data() 48 | -------------------------------------------------------------------------------- /course/132/main.py: -------------------------------------------------------------------------------- 1 | """ 2 | Generate random serial 3 | """ 4 | 5 | import string 6 | import random 7 | 8 | 9 | def generate_serial(count): 10 | """Generate random serial""" 11 | char_list =list(string.ascii_letters+string.digits+r"!@#$%^&*()-=+\/") 12 | char_list_len = len(char_list) -1 13 | temp_list = [] 14 | while count > 0: 15 | # get rand nnum 16 | rand_num = random.randint(0,char_list_len) 17 | # get rand char and append it 18 | temp_list.append(char_list[rand_num]) 19 | # suffele list 20 | random.shuffle(char_list) 21 | # to avoid infinte loop 22 | count -= 1 23 | return "".join(temp_list) 24 | # return reduce(lambda a,b : f'{a}{b}',temp_list) 25 | 26 | print(generate_serial(20)) 27 | -------------------------------------------------------------------------------- /course/133/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | # every app should have a uniqe name 4 | kottab_app = Flask(__name__) 5 | 6 | # setup rounting 7 | @kottab_app.route("/") 8 | def homepage(): 9 | return "Kottab Home" 10 | 11 | @kottab_app.route("/about") 12 | def aboutpage(): 13 | return "Kottab About" 14 | 15 | # run app if this file run directly 16 | if __name__ == "__main__": 17 | kottab_app.run(debug=True) -------------------------------------------------------------------------------- /course/134/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,render_template 2 | 3 | # every app should have a uniqe name 4 | kottab_app = Flask(__name__) 5 | 6 | # setup rounting 7 | @kottab_app.route("/") 8 | def homepage(): 9 | return render_template("home.html",pagetitle="4646") 10 | 11 | @kottab_app.route("/about") 12 | def aboutpage(): 13 | return render_template("about.html") 14 | 15 | # run app if this file run directly 16 | if __name__ == "__main__": 17 | kottab_app.run(debug=True) -------------------------------------------------------------------------------- /course/134/templates/about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Kottab | About 8 | 9 | 10 |
11 |

Kottab | About

12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /course/134/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Kottab | Home 8 | 9 | 10 |
11 |

Kottab | Home

12 |

{{pagetitle}}

13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /course/135/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,render_template 2 | 3 | # every app should have a uniqe name 4 | kottab_app = Flask(__name__) 5 | 6 | # setup rounting 7 | @kottab_app.route("/") 8 | def homepage(): 9 | return render_template("home.html",pagetitle="Hellop") 10 | 11 | @kottab_app.route("/about") 12 | def aboutpage(): 13 | return render_template("about.html") 14 | 15 | # run app if this file run directly 16 | if __name__ == "__main__": 17 | kottab_app.run(debug=True) -------------------------------------------------------------------------------- /course/135/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | About

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/135/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{pagetitle}} 8 | 9 | 10 | 11 | {% block body %} {% endblock %} 12 | 13 | 14 | -------------------------------------------------------------------------------- /course/135/templates/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #bada55; 3 | font-size: 30px; 4 | } 5 | -------------------------------------------------------------------------------- /course/135/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | Home

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/136/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,render_template 2 | 3 | # every app should have a uniqe name 4 | kottab_app = Flask(__name__) 5 | 6 | # setup rounting 7 | @kottab_app.route("/") 8 | def homepage(): 9 | return render_template("home.html",pagetitle="Hellop") 10 | 11 | @kottab_app.route("/about") 12 | def aboutpage(): 13 | return render_template("about.html",pagetitle= "about") 14 | 15 | # run app if this file run directly 16 | if __name__ == "__main__": 17 | kottab_app.run(debug=True) -------------------------------------------------------------------------------- /course/136/static/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #bada55; 3 | font-size: 30px; 4 | } 5 | -------------------------------------------------------------------------------- /course/136/static/css/master.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #456; 3 | font-size: 30px; 4 | } 5 | -------------------------------------------------------------------------------- /course/136/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | About

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/136/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{pagetitle}} 8 | 9 | {% if pagetitle == "home"%} 10 | 14 | {% else %} 15 | 19 | {% endif %} 20 | 21 | 25 | 26 | 27 | {% block body %} {% endblock %} 28 | 29 | 30 | -------------------------------------------------------------------------------- /course/136/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | Home

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/137/main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,render_template 2 | 3 | # every app should have a uniqe name 4 | kottab_app = Flask(__name__) 5 | 6 | # setup rounting 7 | @kottab_app.route("/") 8 | def homepage(): 9 | return render_template("home.html",pagetitle="Hellop") 10 | 11 | @kottab_app.route("/about") 12 | def aboutpage(): 13 | return render_template("about.html") 14 | 15 | # run app if this file run directly 16 | if __name__ == "__main__": 17 | kottab_app.run(debug=True) -------------------------------------------------------------------------------- /course/137/static/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #bada55; 3 | font-size: 30px; 4 | } 5 | -------------------------------------------------------------------------------- /course/137/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | About

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/137/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{pagetitle}} 8 | 12 | 13 | 14 | {% block body %} {% endblock %} 15 | 16 | 17 | -------------------------------------------------------------------------------- /course/137/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | Home

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/138/main.py: -------------------------------------------------------------------------------- 1 | # ------------------------------------------ 2 | # -- Flask => Skills Page Using List Data -- 3 | # ------------------------------------------ 4 | 5 | from flask import Flask, render_template 6 | 7 | skills_app = Flask(__name__) 8 | 9 | my_skills = [("Html", 80), ("CSS", 75), ("Python", 95),("JS", 80), ("Rust", 75), ("Go", 95)] 10 | 11 | @skills_app.route("/") 12 | def homepage(): 13 | return render_template("home.html", 14 | title="Homepage", 15 | custom_css="home") 16 | 17 | @skills_app.route("/add") 18 | def add(): 19 | return render_template("add.html", 20 | title="Add Skill", 21 | custom_css="add") 22 | 23 | @skills_app.route("/about") 24 | def about(): 25 | return render_template("about.html", title="About Us") 26 | 27 | @skills_app.route("/skills") 28 | def skills(): 29 | return render_template("skills.html", 30 | title="My Skills", 31 | page_head="My Skills", 32 | description="This Is My Skills Page", 33 | skills=my_skills) 34 | 35 | if __name__ == "__main__": 36 | skills_app.run(debug=True, port=9000) 37 | -------------------------------------------------------------------------------- /course/138/static/css/main.css: -------------------------------------------------------------------------------- 1 | .card { 2 | padding: 10px; 3 | margin: 5px; 4 | width: 250px; 5 | background-color: #eee; 6 | } 7 | -------------------------------------------------------------------------------- /course/138/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | About

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/138/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{pagetitle}} 8 | 12 | 13 | 14 | {% block body %} {% endblock %} 15 | 16 | 17 | -------------------------------------------------------------------------------- /course/138/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | Home

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/138/templates/skills.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

{{ page_head }}

4 |

{{ description }}

5 | 6 | {% for skill in skills %} 7 |
{{ skill[0] }} | {{ skill[1] }}
8 | {% endfor %} 9 |
10 | {% endblock %} 11 | -------------------------------------------------------------------------------- /course/139/main.py: -------------------------------------------------------------------------------- 1 | # --------------------------------------- 2 | # -- Flask => Customizing App With Css -- 3 | # --------------------------------------- 4 | 5 | from flask import Flask, render_template 6 | 7 | skills_app = Flask(__name__) 8 | 9 | my_skills = [("Html", 80), ("CSS", 75), ("Python", 95), ("MySQL", 45)] 10 | 11 | @skills_app.route("/") 12 | def homepage(): 13 | return render_template("homepage.html", 14 | title="Homepage", 15 | custom_css="home") 16 | 17 | @skills_app.route("/add") 18 | def add(): 19 | return render_template("add.html", 20 | title="Add Skill", 21 | custom_css="add") 22 | 23 | @skills_app.route("/about") 24 | def about(): 25 | return render_template("about.html", title="About Us") 26 | 27 | @skills_app.route("/skills") 28 | def skills(): 29 | return render_template("skills.html", 30 | title="My Skills", 31 | page_head="My Skills", 32 | description="This Is My Skills Page", 33 | skills=my_skills, 34 | custom_css="skills") 35 | 36 | if __name__ == "__main__": 37 | skills_app.run(debug=True, port=9000) -------------------------------------------------------------------------------- /course/139/static/css/main.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | } 4 | body { 5 | background-color: #eee; 6 | font-family: Arial, Tahoma; 7 | } 8 | .page-head, 9 | .page-description { 10 | text-align: center; 11 | } 12 | .page-head { 13 | font-size: 40px; 14 | margin: 20px 0 0; 15 | } 16 | .page-description { 17 | font-size: 22px; 18 | margin: 10px 0 40px; 19 | } 20 | -------------------------------------------------------------------------------- /course/139/static/css/skills.css: -------------------------------------------------------------------------------- 1 | .skill-box { 2 | background-color: #fff; 3 | padding: 20px; 4 | margin: 20px auto; 5 | border: 1px solid #ccc; 6 | width: 450px; 7 | } 8 | .skill-box .skill-name { 9 | text-align: center; 10 | margin-bottom: 15px; 11 | font-size: 20px; 12 | font-weight: bold; 13 | } 14 | .skill-box .skill-progress { 15 | background-color: #f7f7f7; 16 | padding: 10px; 17 | position: relative; 18 | } 19 | .skill-box .skill-progress span { 20 | position: absolute; 21 | left: 0; 22 | top: 0; 23 | width: 0; 24 | height: 100%; 25 | background-color: #009688; 26 | } 27 | -------------------------------------------------------------------------------- /course/139/static/js/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/course/139/static/js/main.js -------------------------------------------------------------------------------- /course/139/templates/about.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | About

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/139/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{pagetitle}} 8 | 12 | 16 | 17 | 18 | {% block body %} {% endblock %} 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /course/139/templates/home.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |
3 |

Kottab | Home

4 |

{{pagetitle}}

5 |
6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /course/139/templates/skills.html: -------------------------------------------------------------------------------- 1 | {% extends 'base.html' %} {% block body %} 2 |

{{ page_head }}

3 |

{{ description }}

4 | 5 | {% for skill in skills %} 6 |
7 |
{{ skill[0] }}
8 |
9 | 10 |
11 |
12 | {% endfor %} {% endblock %} 13 | -------------------------------------------------------------------------------- /course/150/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/course/150/main.py -------------------------------------------------------------------------------- /course/59/test.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Courses-journey/python/c4772fb26776247c240a2c64d81b14e35850ac89/course/59/test.py --------------------------------------------------------------------------------