├── 01- Comments, Variables & Concatenation └── 01.py ├── 02- Strings and it's Methods └── 01.py ├── 03- Numbers & Arithmetic Operators └── 01.py ├── 04- Lists and it's Methods └── 01.py ├── 05- Tuples and it's Methods └── 01.py ├── 06- Sets, Dictionaries and their Methods ├── 01- Sets.py └── 02- Dictionaries.py ├── 07- Boolean, Operators & Type Conversion └── 01.py ├── 08- User Input └── 01.py ├── 09- If, elif, else statement ├── 01.py ├── 02.py ├── 03.py └── 04.py ├── 10- Loop ├── 1- While loop │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py └── 2- For loop │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 11- Function ├── Function │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py └── Packing, Recursion and Lambda │ ├── 01.py │ ├── 02.py │ └── 03.py ├── 12- Files Handling └── 01.py ├── 13- Built In Functions ├── Built In Functions │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py └── Map, Filter, Reduce │ ├── 01.py │ ├── 02.py │ ├── 03.py │ └── 04.py ├── 14- Modules & Packages ├── 01- Task 1.py └── 02- Task 2,3,4.py ├── 15- Date & Time ├── 01.py └── 02.py ├── 16- Generators & Decorators ├── 01.py └── 02.py ├── 17- Collection of Modules ├── 01 zip function.py ├── 02 zip function.py ├── 03 Image Manipulation With Pillow.py ├── 04 Doc String.py └── 05 Using PyLint to rate the code.py ├── 18- Error Handling & Debugging ├── 01.py ├── 02.py └── 03.py ├── 19- Regular Expression ├── 01.py ├── 02.py ├── 03.py ├── 04.py └── 05.py ├── 20- OOP ├── 01.py ├── 02.py ├── 03.py ├── 04.py ├── 05.py └── 06.py ├── 21- SQLite Database ├── 01- Task 1.py └── 02- Task 2,3,4 and 5.py ├── 22- Advanced Concepts ├── 01.py └── 02.py └── README.md /01- Comments, Variables & Concatenation/01.py: -------------------------------------------------------------------------------- 1 | # ---------------------------------------- 2 | # This is my first python file 3 | # I'm ali moustafa 4 | # I'm from Egypt 5 | # I started learning python today 6 | # ---------------------------------------- 7 | 8 | name = "Ali" 9 | age = "22" 10 | country = "Egypt" 11 | 12 | print(type(name)) 13 | print(type(age)) 14 | print(type(country)) 15 | 16 | print("=" * 40) 17 | 18 | print("Name:" + name) 19 | print("Age:" + age) 20 | print("Country:" + country) 21 | 22 | print("=" * 40) 23 | 24 | print("Hello, My Name Is" + " " + name + "," + " " + "Iam" + " " + age + " " + "Years Old" + " " + "And I'm from" + " " + country + ".") 25 | 26 | -------------------------------------------------------------------------------- /02- Strings and it's Methods/01.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | 3 | name = "Ali" 4 | age = 22 5 | country = "Egypt" 6 | 7 | print(f'Hello {name}, How are you doing? \\""" Your age is "{age}" + Your country is:{country}') 8 | 9 | print("="*40) 10 | 11 | # ---------------(Assignment 2)--------------- 12 | 13 | name = "Ali" 14 | age = 22 15 | country = "Egypt" 16 | 17 | print(f'Hello {name}, How are you doing? \\\n""" Your age is "{age}" +\nYour country is:{country}') 18 | 19 | print("="*40) 20 | 21 | # ---------------(Assignment 3)--------------- 22 | 23 | name = "Abdelkader" 24 | 25 | 26 | print(f'Second Letter Is "{name[1]}"') 27 | print(f'Third Letter Is "{name[2]}"') 28 | print(f'Last Letter Is "{name[-1]}"') 29 | 30 | print("="*40) 31 | 32 | # ---------------(Assignment 4)--------------- 33 | 34 | name = "Abdelkader" 35 | 36 | 37 | print(f'Second Letter Is "{name[1:4]}"') 38 | print(f'Third Letter Is "{name[:9:2]}"') 39 | 40 | print("="*40) 41 | 42 | # ---------------(Assignment 5)--------------- 43 | 44 | name = "#@#@Ali#@#@" 45 | 46 | print(name.strip("#@")) 47 | 48 | print("="*40) 49 | 50 | # ---------------(Assignment 6)--------------- 51 | 52 | num1 = "9" 53 | num2 = "15" 54 | num3 = "130" 55 | num4 = "950" 56 | num5 = "1500" 57 | 58 | print(num1.zfill(4)) 59 | print(num2.zfill(4)) 60 | print(num3.zfill(4)) 61 | print(num4.zfill(4)) 62 | print(num5.zfill(4)) 63 | 64 | print("="*40) 65 | 66 | # ---------------(Assignment 7)--------------- 67 | 68 | name_one = "Ali" 69 | name_two = "Ali_Moustafa" 70 | 71 | print(name_one.rjust(20,"@")) 72 | print(name_two.rjust(20,"@")) 73 | 74 | print("="*40) 75 | 76 | # ---------------(Assignment 8)--------------- 77 | 78 | name_one = "MoUstaFa" 79 | name_two = "osaMA" 80 | 81 | print(name_one.swapcase()) 82 | print(name_two.swapcase()) 83 | 84 | print("="*40) 85 | 86 | # ---------------(Assignment 9)--------------- 87 | 88 | msg = "I Love Python And, I Love Elzero Web School" 89 | 90 | print(msg.count('Love')) 91 | 92 | print("="*40) 93 | 94 | # ---------------(Assignment 10)--------------- 95 | 96 | name = "Ali" 97 | 98 | print(name.index('i')) 99 | 100 | print("="*40) 101 | 102 | # ---------------(Assignment 11)--------------- 103 | 104 | msg = "I Love Python And, I Love Elzero Web School" 105 | 106 | print(msg.replace('Love', '<3', 1)) 107 | 108 | print("="*40) 109 | 110 | # ---------------(Assignment 12)--------------- 111 | 112 | msg = "I <3 Python And Although <3 Elzero Web School" 113 | 114 | print(msg.replace('<3', 'Love')) 115 | 116 | print("="*40) 117 | 118 | # ---------------(Assignment 13)--------------- 119 | 120 | name = "Ali" 121 | age = 22 122 | country = "Egypt" 123 | 124 | 125 | print(f"My Name Is {name}, My Age Is {age}, And My Country Is {country}") 126 | -------------------------------------------------------------------------------- /03- Numbers & Arithmetic Operators/01.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | 3 | print(type(5)) 4 | print(type(5.5)) 5 | print(type(5+6j)) 6 | 7 | print("="*40) 8 | 9 | # ---------------(Assignment 2)--------------- 10 | 11 | my_complex_number = 1+2j 12 | 13 | print(my_complex_number.imag) 14 | print(my_complex_number.real) 15 | 16 | print("="*40) 17 | 18 | # ---------------(Assignment 3)--------------- 19 | 20 | num1 = 10 21 | 22 | print("{:.10f}".format(num1)) 23 | 24 | print("="*40) 25 | 26 | # ---------------(Assignment 4)--------------- 27 | 28 | num = 159.650 29 | 30 | num2 = int(num) 31 | print(num2) 32 | print(type(num2)) 33 | 34 | print("="*40) 35 | 36 | # ---------------(Assignment 5)--------------- 37 | 38 | print(100 - 115) 39 | print(50 * 30) 40 | print(21 % 4) 41 | print(110 / 11) 42 | print(97 // 20) 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /04- Lists and it's Methods/01.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | 3 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 4 | 5 | print(friends[0]) # 1st method 6 | print(friends.pop(0)) # 2nd method 7 | print(friends[-1]) # 1st method 8 | print(friends.pop(-1)) # 2nd method 9 | 10 | print("="*40) 11 | 12 | # ---------------(Assignment 2)--------------- 13 | 14 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 15 | 16 | print(friends[ : :2]) 17 | print(friends[1: :2]) 18 | 19 | print("="*40) 20 | 21 | # ---------------(Assignment 3)--------------- 22 | 23 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 24 | 25 | print(friends[1:4]) 26 | print(friends[-2: ]) 27 | 28 | print("="*40) 29 | 30 | # ---------------(Assignment 4)--------------- 31 | 32 | friends = ["Osama", "Ahmed", "Sayed", "Ali", "Mahmoud"] 33 | 34 | friends[3] = 'Elzero' 35 | friends[4] = 'Elzero' 36 | 37 | print(friends) 38 | 39 | print("="*40) 40 | 41 | # ---------------(Assignment 5)--------------- 42 | 43 | friends = ["Osama", "Ahmed", "Sayed"] 44 | 45 | friends.insert(0, "Ali") 46 | 47 | print(friends) 48 | 49 | friends.append("Gamal") 50 | 51 | print(friends) 52 | 53 | print("="*40) 54 | 55 | # ---------------(Assignment 6)--------------- 56 | 57 | friends = ["Nasser", "Osama", "Ahmed", "Sayed", "Salem"] 58 | 59 | friends.remove("Nasser") 60 | friends.remove("Osama") 61 | print(friends) 62 | 63 | friends.remove("Salem") 64 | print(friends) 65 | 66 | print("="*40) 67 | 68 | # ---------------(Assignment 7)--------------- 69 | 70 | friends = ["Ahmed", "Sayed"] 71 | employees = ["Samah", "Eman"] 72 | school = ["Ramy", "Shady"] 73 | 74 | friends.extend(employees) 75 | friends.extend(school) 76 | 77 | print(friends) 78 | 79 | print("="*40) 80 | 81 | # ---------------(Assignment 8)--------------- 82 | 83 | friends = ["Ahmed", "Sayed", "Samah", "Eman", "Ramy", "Shady"] 84 | 85 | friends.sort() 86 | print(friends) 87 | 88 | friends.sort(reverse=True) 89 | print(friends) 90 | 91 | print("="*40) 92 | 93 | # ---------------(Assignment 9)--------------- 94 | 95 | friends = ["Ahmed", "Sayed", "Samah", "Eman", "Ramy", "Shady"] 96 | 97 | print(len(friends)) 98 | 99 | print("="*40) 100 | 101 | # ---------------(Assignment 10)--------------- 102 | 103 | technologies = ["Html", "CSS", "JS", "Python", ["Django", "Flask", "Web"]] 104 | 105 | print(technologies[-1][0]) 106 | print(technologies[-1][-1]) 107 | 108 | print("="*40) 109 | 110 | # ---------------(Assignment 11)--------------- 111 | 112 | my_list = [1, 2, 3, 3, 4, 5, 1] 113 | my_list.remove(1) 114 | my_list.remove(3) 115 | my_list.sort() 116 | unique_list = my_list 117 | 118 | print(unique_list) 119 | print(type(unique_list)) 120 | print(unique_list[0:4]) 121 | -------------------------------------------------------------------------------- /05- Tuples and it's Methods/01.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | 3 | name = "Ali", 4 | 5 | print(name) 6 | print(type(name)) 7 | 8 | print("="*40) 9 | 10 | # ---------------(Assignment 2)--------------- 11 | 12 | my_friends = ("Osama", "Ahmed", "Sayed") 13 | 14 | friends_list = list(my_friends) 15 | friends_list [0] = "Elzero" 16 | friends_tuple = tuple(friends_list) 17 | 18 | print(friends_tuple) 19 | print(type(friends_tuple)) 20 | print(f"{len(friends_tuple)} Elements") 21 | 22 | print("="*40) 23 | 24 | # ---------------(Assignment 3)--------------- 25 | 26 | nums = (1, 2, 3) 27 | letters = ("A", "B", "C") 28 | 29 | my_tuple = nums + letters 30 | 31 | print(f"my Tuple = {my_tuple}") 32 | print(f"{len(my_tuple)} Elements") 33 | 34 | print("="*40) 35 | 36 | # ---------------(Assignment 4)--------------- 37 | 38 | my_tuple = (1, 2, 3, 4) 39 | 40 | A,B,_,C = my_tuple 41 | 42 | print(A) 43 | print(B) 44 | print(C) 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /06- Sets, Dictionaries and their Methods/01- Sets.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | nums = {1, 2, 3} 3 | letters = {"A", "B", "C"} 4 | 5 | print(nums | letters) 6 | print(nums.union(letters)) 7 | 8 | nums.update(letters) 9 | print(nums) 10 | 11 | print("="*40) 12 | 13 | # ---------------(Assignment 2)--------------- 14 | 15 | my_set = {1, 2, 3} 16 | 17 | print(my_set) 18 | 19 | my_set.clear() 20 | print(my_set) 21 | 22 | my_set.add("A") 23 | my_set.add("B") 24 | my_set.discard("C") 25 | print(my_set) 26 | 27 | print("="*40) 28 | 29 | # ---------------(Assignment 3)--------------- 30 | 31 | set_one = {1, 2, 3} 32 | set_two = {1, 2, 3, 4, 5, 6} 33 | 34 | print(set_one.issubset(set_two)) 35 | 36 | -------------------------------------------------------------------------------- /06- Sets, Dictionaries and their Methods/02- Dictionaries.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | 3 | skills = { 4 | 'Python':'80%', 5 | 'HTML':'50%', 6 | 'CSS':'20%' 7 | } 8 | 9 | skills.update({'AI':'30%'}) 10 | 11 | print(f"Python Progress Is {skills['Python']}") 12 | print(f"HTML Progress Is {skills['HTML']}") 13 | print(f"CSS Progress Is {skills['CSS']}") 14 | print(f"AI Progress Is {skills['AI']}") 15 | -------------------------------------------------------------------------------- /07- Boolean, Operators & Type Conversion/01.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | 3 | print(bool(True)) 4 | print(bool("ali")) 5 | print(bool(100)) 6 | print(bool(["ali","ahmed"])) 7 | print(bool(False)) 8 | print(bool(0)) 9 | print(bool()) 10 | print(bool(None)) 11 | 12 | print("="*40) 13 | 14 | # ---------------(Assignment 2)--------------- 15 | 16 | html = 80 17 | css = 60 18 | javascript = 70 19 | 20 | print(html > 50 and css > 50 and javascript > 50 ) 21 | 22 | print("="*40) 23 | 24 | # ---------------(Assignment 3)--------------- 25 | 26 | num_one = 10 27 | num_two = 20 28 | num = 20 29 | 30 | print(num > num_one or num > num_two) 31 | 32 | print(num > num_one and num > num_two) 33 | 34 | print("="*40) 35 | 36 | # ---------------(Assignment 4)--------------- 37 | 38 | num_one = 10 39 | num_two = 20 40 | result = num_one + num_two 41 | 42 | print(result) 43 | 44 | Exponent = result ** 3 45 | print(Exponent) 46 | 47 | Modulus = Exponent % 26000 48 | print(Modulus) 49 | 50 | Division = Modulus / 5 51 | print(Division) 52 | 53 | final = str(Division) 54 | 55 | print(type(final)) 56 | -------------------------------------------------------------------------------- /08- User Input/01.py: -------------------------------------------------------------------------------- 1 | # ---------------(Assignment 1)--------------- 2 | 3 | User_name = input("What's your name? ").strip().capitalize() 4 | 5 | print(f"Hello {User_name}, Happy To See You Here.") 6 | 7 | print("="*40) 8 | 9 | # ---------------(Assignment 2)--------------- 10 | 11 | User_age = int(input("How old are you? ").strip().capitalize()) 12 | 13 | if User_age < 16 : 14 | print("Hello Your Age Is Under 16, Some Articles Is Not Suitable For You") 15 | 16 | else: 17 | print(f"Hello Your Age Is {User_age}, All Articles Is Suitable For You") 18 | 19 | print("="*40) 20 | 21 | # ---------------(Assignment 3)--------------- 22 | 23 | First_Name = input("What's your first name? ").strip().capitalize() 24 | Second_Name = input("What's your second name? ").strip().capitalize() 25 | 26 | print(f"Hello, {First_Name} {Second_Name[0]}.") 27 | 28 | print("="*40) 29 | 30 | # ---------------(Assignment 4)--------------- 31 | 32 | User_email = input("Email Address? ").strip().lower() 33 | 34 | print(f"Your username Is {User_email.capitalize()[:User_email.index('@')]}") 35 | 36 | print(f"Email Service Provider Is {User_email[User_email.index('@')+1: User_email.index('.')]}") 37 | 38 | print(f"Top Level Domain Is {User_email[User_email.index('.')+1:]}") 39 | 40 | -------------------------------------------------------------------------------- /09- If, elif, else statement/01.py: -------------------------------------------------------------------------------- 1 | num1 = int(input("Enter the first number. ").strip()) 2 | num2 = int(input("Enter the second number. ").strip()) 3 | operation = input('Select the operation: ["+" Or "-" Or "*" Or "/" Or "%"] ').strip() 4 | 5 | 6 | if operation == '+': 7 | result = num1 + num2 8 | 9 | if operation == '-': 10 | result = num1 - num2 11 | 12 | if operation == '*': 13 | result = num1 * num2 14 | 15 | if operation == '/': 16 | result = num1 / num2 17 | 18 | if operation == '%': 19 | result = num1 % num2 20 | 21 | 22 | print(f"{num1} {operation} {num2} = {result}") 23 | -------------------------------------------------------------------------------- /09- If, elif, else statement/02.py: -------------------------------------------------------------------------------- 1 | user_age = int(input("What is your age? ").strip()) 2 | 3 | print("Unfortunately, your age is not suitable for the program" if user_age >= 30 or user_age < 18 else "This program is suitable for you") 4 | -------------------------------------------------------------------------------- /09- If, elif, else statement/03.py: -------------------------------------------------------------------------------- 1 | user_age = int(input("What is your age? ").strip()) 2 | 3 | months = user_age * 12 4 | weeks = months * 4 5 | days = user_age * 365 6 | hours = days * 24 7 | minutes = hours * 60 8 | seconds = minutes * 60 9 | 10 | 11 | if user_age >= 10 and user_age <= 100: 12 | print(f"Your Age In months Is {months:,} months") 13 | print(f"Your Age In weeks Is {weeks:,} weeks") 14 | print(f"Your Age In days Is {days:,} days") 15 | print(f"Your Age In hours Is {hours:,} hours") 16 | print(f"Your Age In minutes Is {minutes:,} minutes") 17 | print(f"Your Age In seconds Is {seconds:,} seconds") 18 | 19 | else: 20 | print("Your age is out of range") 21 | -------------------------------------------------------------------------------- /09- If, elif, else statement/04.py: -------------------------------------------------------------------------------- 1 | country = input("What is Your Country? ").strip().lower() 2 | countries = ["egypt", "palestine", "syria", "yemen", "ksa", "usa", "bahrain", "england"] 3 | price = 100 4 | discount = 30 5 | 6 | if country in countries: 7 | print(f"Your Country Eligible For Discount And The Price After Discount Is ${price -discount }") 8 | 9 | else: 10 | print(f"Your Country Not Eligible For Discount And The Price Is $ {price}") 11 | -------------------------------------------------------------------------------- /10- Loop/1- While loop/01.py: -------------------------------------------------------------------------------- 1 | User_num = int(input('Enter your number. ')) 2 | num = User_num 3 | 4 | if num > 0: 5 | while num > 1: 6 | num -= 1 7 | print(num) 8 | 9 | else: 10 | print(f"Number {num} isn't larger than 0") 11 | 12 | 13 | print(f"{User_num - 1} Numbers Printed Successfully.") 14 | -------------------------------------------------------------------------------- /10- Loop/1- While loop/02.py: -------------------------------------------------------------------------------- 1 | friends = ["Mohamed", "Shady", "ahmed", "eman", "Sherif", "ola"] 2 | 3 | 4 | a = 0 5 | friends == friends.sort() 6 | while friends[a] == friends[a].capitalize(): 7 | print(friends[a]) 8 | a += 1 9 | 10 | 11 | else: 12 | print(f"Friends Printed And Ignored Names Count Is: {len(friends) - a}") 13 | -------------------------------------------------------------------------------- /10- Loop/1- While loop/03.py: -------------------------------------------------------------------------------- 1 | skills = ["HTML", "CSS", "JavaScript", "PHP", "Python"] 2 | 3 | while skills: 4 | print("\n".join(skills)); break 5 | -------------------------------------------------------------------------------- /10- Loop/1- While loop/04.py: -------------------------------------------------------------------------------- 1 | my_friends = [] 2 | number = 4 3 | 4 | name = input("What's your friend name? ").strip() 5 | 6 | 7 | while name != name.upper(): 8 | number -= 1 9 | 10 | if name == name.capitalize(): 11 | my_friends.append(name) 12 | print(f"Your friend: {name} Added") 13 | 14 | else: 15 | my_friends.append(name.capitalize()) 16 | print(f"Your friend: {name.capitalize()} Added => 1st Letter Become Capital") 17 | 18 | print(f"Names Left in List Is {number}") 19 | print(my_friends) 20 | 21 | if number == 0: 22 | break 23 | else: 24 | name = input("What's your friend name? ").strip() 25 | 26 | 27 | else: 28 | print('Invalid name') 29 | -------------------------------------------------------------------------------- /10- Loop/2- For loop/01.py: -------------------------------------------------------------------------------- 1 | my_numbers = [15, 81, 5, 17, 20, 21, 13] 2 | my_numbers.sort(reverse=True) 3 | a = 1 4 | 5 | for num in my_numbers: 6 | if num % 5 == 0: 7 | print(f"{a} => {num}") 8 | a += 1 9 | else: 10 | pass 11 | 12 | print("All Numbers are Printed") 13 | -------------------------------------------------------------------------------- /10- Loop/2- For loop/02.py: -------------------------------------------------------------------------------- 1 | my_numbers = range(1, 21) 2 | 3 | for num in my_numbers: 4 | if num < 10 and num != 6 and num != 8 and num != 12: 5 | print(str(num).zfill(2)) 6 | elif num == 6 or num == 8 or num == 12: 7 | continue 8 | else: 9 | print(num) 10 | 11 | print("All Numbers are Printed") 12 | -------------------------------------------------------------------------------- /10- Loop/2- For loop/03.py: -------------------------------------------------------------------------------- 1 | my_ranks = { 2 | 'Math': 'A', 3 | 'Science': 'B', 4 | 'Drawing': 'A', 5 | 'Sports': 'C' 6 | } 7 | 8 | my_points = { 9 | "A": 100, 10 | "B": 80, 11 | "C": 40 12 | } 13 | 14 | 15 | sum = 0 16 | 17 | for subject in my_ranks: 18 | 19 | for points in my_points: 20 | 21 | if my_ranks[subject] == points: 22 | 23 | sum += my_points[points] 24 | 25 | print(f"My Rank in {subject} Is '{my_ranks[subject]}' And This Equal {my_points[points]} Points.") 26 | 27 | print(f"Total Points Is: {sum}") 28 | -------------------------------------------------------------------------------- /10- Loop/2- For loop/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 | my_points = { 26 | "A": 100, 27 | "B": 80, 28 | "C": 40, 29 | "D" : 20 30 | } 31 | 32 | sum1 = 0 33 | sum2 = 0 34 | sum3 = 0 35 | 36 | for student in students: 37 | print("-" * 30) 38 | print(f"Student Name => {student}") 39 | print("-" * 30) 40 | 41 | for subjects in students[student]: 42 | 43 | for points in my_points: 44 | 45 | if students[student][subjects] == points and student == "Ahmed": 46 | sum1 += my_points[points] 47 | print(f"- {subjects} => {my_points[points]} Points") 48 | 49 | elif students[student][subjects] == points and student == "Sayed": 50 | sum2 += my_points[points] 51 | print(f"- {subjects} => {my_points[points]} Points") 52 | 53 | elif students[student][subjects] == points and student == "Mahmoud": 54 | sum3 += my_points[points] 55 | 56 | print(f"- {subjects} => {my_points[points]} Points") 57 | 58 | print(f"= Total Points For {student} Is: {sum1 if student == 'Ahmed' else sum2 if student == 'Sayed' else sum3}") 59 | -------------------------------------------------------------------------------- /11- Function/Function/01.py: -------------------------------------------------------------------------------- 1 | def calculate (n1, n2, operation): 2 | if operation == '+' or operation == 'add' or operation == 'a': 3 | print(int(n1) + int(n2)) 4 | elif operation == '-' or operation == 'subtract' or operation == 's': 5 | print(int(n1) - int(n2)) 6 | elif operation == '*' or operation == 'multiply' or operation == 'm': 7 | print(int(n1) * int(n2)) 8 | elif operation == "": 9 | print(int(n1) + int(n2)) 10 | else: 11 | print("This Operation Not Available!") 12 | 13 | calculate(*input("Enter 2 numbers ").split(), input("Choose the operation [+, -, *] ").lower()) -------------------------------------------------------------------------------- /11- Function/Function/02.py: -------------------------------------------------------------------------------- 1 | 2 | def addition (*numbers): 3 | 4 | sum = 0 5 | 6 | for number in numbers: 7 | if number == 10: 8 | continue 9 | 10 | elif number == 5: 11 | sum-=5 12 | 13 | else: 14 | sum+=number 15 | 16 | 17 | print(sum) 18 | 19 | addition(10, 20, 30, 10, 15) 20 | # 65 21 | 22 | addition(10, 20, 30, 10, 15, 5, 100) 23 | # 160 -------------------------------------------------------------------------------- /11- Function/Function/03.py: -------------------------------------------------------------------------------- 1 | def member_skills (name = "",*skills): 2 | 3 | if name == "": 4 | name = "Unknown" 5 | 6 | if skills == (): 7 | print(f'Hello {name} You Have No Skills To Show') 8 | 9 | else: 10 | print(f"Hello {name} Your skills are: ") 11 | 12 | for skill in skills: 13 | 14 | print(f"- {skill}") 15 | 16 | member_skills (input("What's Your Name? ").strip().capitalize(), *input("Enter Your skills? ").split()) 17 | 18 | member_skills () -------------------------------------------------------------------------------- /11- Function/Function/04.py: -------------------------------------------------------------------------------- 1 | # --------------------(Method 1)-------------------- 2 | 3 | def new_member(name = "Unknown", age = "Unknown", country = "Unknown"): 4 | 5 | print(f"Hello {name}, You are from {country} and your age is {age}.") 6 | 7 | 8 | 9 | new_member('Ali', 22, 'Egypt') 10 | # Hello Ali, You are from Egypt and your age is 22. 11 | 12 | new_member() 13 | # Hello Unknown, You are from Unknown and your age is Unknown. 14 | 15 | print("=" * 40) 16 | 17 | # --------------------(Method 2)-------------------- 18 | 19 | def new_member(name, age, country): 20 | 21 | if name == "": 22 | name = "Unknown" 23 | 24 | if age == "": 25 | age = "Unknown" 26 | 27 | if country == "": 28 | country = "Unknown" 29 | 30 | print(f"Hello {name}, You are from {country} and your age is {age}.") 31 | 32 | 33 | 34 | new_member(input("What's your name? ").capitalize().strip(), input("How old are you? ").capitalize().strip(), input("Where are you from? ").capitalize().strip()) -------------------------------------------------------------------------------- /11- Function/Packing, Recursion and Lambda/01.py: -------------------------------------------------------------------------------- 1 | def get_score (**subjects): 2 | 3 | for subject in subjects: 4 | 5 | print(f"- {subject} => {subjects[subject]}") 6 | 7 | 8 | 9 | get_score(Math = 90, Science = 80, Language = 70) 10 | 11 | print('=' * 40) 12 | 13 | get_score(Logic=70, Problems=60) -------------------------------------------------------------------------------- /11- Function/Packing, Recursion and Lambda/02.py: -------------------------------------------------------------------------------- 1 | def get_people_scores (name = "", **subjects): 2 | 3 | if name == "" : 4 | pass 5 | 6 | elif name != "" and subjects != {}: 7 | print(f"Hello {name}, This Is Your Score Table:") 8 | 9 | if subjects == {} and name != "": 10 | print(f"Hello {name} You Have No Scores To Show.") 11 | 12 | else: 13 | for subject in subjects: 14 | print(f"- {subject} => {subjects[subject]}") 15 | 16 | 17 | get_people_scores("Ali", Math=90, Science=80, Language=70) 18 | 19 | print('=' * 40) 20 | 21 | get_people_scores("Ali", Logic=70, Problems=60) 22 | 23 | print('=' * 40) 24 | 25 | get_people_scores(Logic=70, Problems=60) 26 | 27 | print('=' * 40) 28 | 29 | get_people_scores("Ali") 30 | 31 | -------------------------------------------------------------------------------- /11- Function/Packing, Recursion and Lambda/03.py: -------------------------------------------------------------------------------- 1 | student_score = { 2 | "Math" : "90%", 3 | "Science" : "80%", 4 | "Language" : "70%" 5 | } 6 | 7 | 8 | def get_people_scores (name = "", **subjects): 9 | 10 | if name == "" : 11 | pass 12 | 13 | elif name != "" and subjects != {}: 14 | print(f"Hello {name}, This Is Your Score Table:") 15 | 16 | if subjects == {} and name != "": 17 | print(f"Hello {name} You Have No Scores To Show.") 18 | 19 | else: 20 | for subject in subjects: 21 | print(f"- {subject} => {subjects[subject]}") 22 | 23 | 24 | get_people_scores("Ali", **student_score) 25 | 26 | print('=' * 40) 27 | 28 | get_people_scores("Ali") 29 | 30 | print('=' * 40) 31 | 32 | get_people_scores(**student_score) 33 | 34 | -------------------------------------------------------------------------------- /12- Files Handling/01.py: -------------------------------------------------------------------------------- 1 | i = 0 2 | 3 | for file in range(1,51,1): 4 | 5 | if file == 25: 6 | 7 | filename = "special-text.txt" 8 | file = open(filename,"w") 9 | 10 | else: 11 | 12 | filename = f"txt{file}.txt" 13 | file = open(filename,"w") 14 | 15 | i += 1 16 | if i < 25: 17 | file.write(f"Elzero Web School => {i}\n") 18 | 19 | if i >= 25: 20 | file.write(f"Elzero Web School => {i + 1}\n") 21 | 22 | 23 | import os 24 | 25 | 26 | # To print Current Working Directory 27 | 28 | print(os.getcwd()) 29 | print("=" * 40) 30 | 31 | 32 | # To print file name 33 | 34 | myfile = open(r"C:\Users\A L I\Desktop\Python\assign.py","r") 35 | 36 | print(myfile.name) 37 | print("=" * 40) 38 | 39 | 40 | # To print number of files inside the directory 41 | 42 | files_num = len(os.listdir(r"C:\Users\A L I\Desktop\Python")) 43 | print(f"Number of files is : {files_num}") 44 | print("=" * 40) 45 | 46 | 47 | # To write "Appended => Elzero Web School" in txt1.txt 50 times 48 | 49 | myfile = open(r"C:\Users\A L I\Desktop\Python\txt1.txt","a") 50 | 51 | myfile.write("Appended => Elzero Web School\n" * 50) 52 | 53 | 54 | # To print number of lines in a file 55 | 56 | myfile = open(r"C:\Users\A L I\Desktop\Python\txt1.txt","r") 57 | lines = len(myfile.readlines()) 58 | print(f"Number Of Lines Is => {lines}") 59 | print("=" * 40) 60 | 61 | 62 | # To print number of words in a file 63 | 64 | myfile = open(r"C:\Users\A L I\Desktop\Python\txt1.txt","r") 65 | words = len(myfile.read().split()) 66 | print(f"Number Of Words Is => {words}") 67 | print("=" * 40) 68 | 69 | 70 | # To print number of Characters in a file 71 | 72 | myfile = open(r"C:\Users\A L I\Desktop\Python\txt1.txt","r") 73 | Characters = len(myfile.read().replace(" ","").replace("\n","")) 74 | print(f"Number Of Characters Is => {Characters}") 75 | print("=" * 40) 76 | 77 | 78 | # To print number of specific Character in a file 79 | 80 | myfile = open(r"C:\Users\A L I\Desktop\Python\txt1.txt","r") 81 | Character_l = myfile.read().count('l') 82 | print(f"Number Of Character[l] Is => {Character_l}") 83 | print("=" * 40) 84 | 85 | 86 | # To remove the last 10 files 87 | 88 | x = 50 89 | 90 | import os 91 | 92 | for file in os.listdir(r"C:\Users\A L I\Desktop\Python"): 93 | 94 | os.remove(rf"C:\Users\A L I\Desktop\Python\txt{x}.txt") 95 | 96 | x-=1 97 | 98 | if x == 40: 99 | 100 | break 101 | -------------------------------------------------------------------------------- /13- Built In Functions/Built In Functions/01.py: -------------------------------------------------------------------------------- 1 | values = (0, 1, 2) 2 | 3 | # if any value from values True: my_var = 0 => 1 & 2 = True => so my_var = 0 4 | if any(values): 5 | 6 | my_var = 0 7 | 8 | my_list = [True, 1, 1, ["A", "B"], 10.5, my_var] # my_var = 0 => False 9 | 10 | # all(my_list[:4]) => True 11 | if all(my_list[:4]) or all(my_list[:6]) or all(my_list[:]): 12 | 13 | print("Good") 14 | 15 | else: 16 | 17 | print("Bad") 18 | 19 | 20 | # Output => Good 21 | -------------------------------------------------------------------------------- /13- Built In Functions/Built In Functions/02.py: -------------------------------------------------------------------------------- 1 | # find the value of 'v' that makes the Output '820'. 2 | 3 | # my_range = list(range(v)) 4 | 5 | # print(sum(my_range, v) + pow(v, v, v)) => 820 6 | 7 | # -------------------------------------------------- 8 | 9 | v = 1 10 | 11 | while v < 1000: 12 | 13 | my_range = list(range(v)) 14 | 15 | if (sum(my_range, v) + pow(v, v, v)) == 820: 16 | 17 | print(f"v = {v}") 18 | 19 | break 20 | 21 | v += 1 22 | 23 | 24 | # Output 25 | # v = 40 -------------------------------------------------------------------------------- /13- Built In Functions/Built In Functions/03.py: -------------------------------------------------------------------------------- 1 | # find the value of 'n' that makes the Output 'Good'. 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 | # ------------------------------------------------------- 10 | 11 | n = 1 12 | 13 | while n < 1000: 14 | 15 | l = list(range(n)) 16 | 17 | if round(sum(l) / n) == max(0, 3, 10, 2, -100, -23, 9): 18 | 19 | print (f"'n' may be => {n}") 20 | 21 | n+=1 22 | 23 | # Output 24 | # 'n' may be => 20 25 | # 'n' may be => 21 26 | # 'n' may be => 22 27 | -------------------------------------------------------------------------------- /13- Built In Functions/Built In Functions/04.py: -------------------------------------------------------------------------------- 1 | # ------------------------- 2 | # ----------(all)---------- 3 | # ------------------------- 4 | 5 | def my_all (items): 6 | 7 | for item in items: 8 | 9 | if bool(item) == False: 10 | 11 | return False 12 | 13 | else: 14 | 15 | return True 16 | 17 | 18 | print(my_all([1, 2, 3])) 19 | # True 20 | print(my_all([1, 2, 3, []])) 21 | # False 22 | 23 | 24 | # ------------------------- 25 | # ----------(any)---------- 26 | # ------------------------- 27 | 28 | def my_any (items): 29 | 30 | for item in items: 31 | 32 | if bool(item) == True: 33 | 34 | return True 35 | 36 | else: 37 | 38 | return False 39 | 40 | 41 | print(my_any([0, 1, [], False])) 42 | # True 43 | print(my_any([(), 0, False])) 44 | # False 45 | 46 | 47 | # ------------------------- 48 | # ----------(min)---------- 49 | # ------------------------- 50 | 51 | def my_min (items): 52 | 53 | a = list(items) 54 | 55 | a.sort() 56 | 57 | return a [0] 58 | 59 | 60 | print(my_min([10, 100, -20, -100, 50])) 61 | # -100 62 | print(my_min((10, 100, -20, -100, 50))) 63 | # -100 64 | 65 | 66 | # ------------------------- 67 | # ----------(max)---------- 68 | # ------------------------- 69 | 70 | def my_max (items): 71 | 72 | a = list(items) 73 | 74 | a.sort() 75 | 76 | return a [-1] 77 | 78 | 79 | print(my_max([10, 100, -20, -100, 50, 700])) 80 | # 700 81 | print(my_max((10, 100, -20, -100, 50, 700))) 82 | # 700 83 | -------------------------------------------------------------------------------- /13- Built In Functions/Map, Filter, Reduce/01.py: -------------------------------------------------------------------------------- 1 | friends_map = ["AEmanS", "AAhmedS", "DSamehF", "LOsamaL"] 2 | 3 | def remove_chars (text): 4 | 5 | return text[1:-1] 6 | 7 | 8 | # using map with predefined function 9 | 10 | modified_texts = map(remove_chars, friends_map) 11 | 12 | for name in modified_texts: 13 | 14 | print(name) 15 | 16 | 17 | # ------------------------------ 18 | print("=" * 50) 19 | # ------------------------------ 20 | 21 | 22 | # using map with lambda function 23 | 24 | for name in map(lambda item: item[1:-1], friends_map): 25 | 26 | print(name) -------------------------------------------------------------------------------- /13- Built In Functions/Map, Filter, Reduce/02.py: -------------------------------------------------------------------------------- 1 | friends_filter = ["Osama", "Wessam", "Amal", "Essam", "Gamal", "Othman"] 2 | 3 | def get_names (name): 4 | 5 | if name[-1] == 'm' : 6 | 7 | return name 8 | 9 | 10 | # using filter with predefined function 11 | 12 | names = filter(get_names, friends_filter) 13 | 14 | for name in names: 15 | 16 | print(name) 17 | 18 | 19 | # ------------------------------ 20 | print("=" * 50) 21 | # ------------------------------ 22 | 23 | 24 | # using filter with lambda function 25 | 26 | for name in filter(lambda item: item.endswith("m"), friends_filter): 27 | 28 | print(name) 29 | 30 | -------------------------------------------------------------------------------- /13- Built In Functions/Map, Filter, Reduce/03.py: -------------------------------------------------------------------------------- 1 | nums = [2, 4, 6, 2] 2 | 3 | from functools import reduce 4 | 5 | def multiply (num1, num2): 6 | 7 | return num1 * num2 8 | 9 | 10 | # using reduce with predefined function 11 | 12 | result = reduce(multiply, nums) 13 | 14 | print(result) 15 | 16 | 17 | # ------------------------------ 18 | print("=" * 50) 19 | # ------------------------------ 20 | 21 | 22 | # using reduce with lambda function 23 | 24 | result = reduce(lambda num1, num2: num1 * num2 , nums) 25 | 26 | print(result) -------------------------------------------------------------------------------- /13- Built In Functions/Map, Filter, Reduce/04.py: -------------------------------------------------------------------------------- 1 | skills = ("HTML", "CSS", 10, "PHP", "Python", 20, "JavaScript") 2 | 3 | reversed_skills = reversed(skills) 4 | 5 | enumerated_skills = enumerate(reversed_skills, 50) 6 | 7 | for counter, skill in enumerated_skills: 8 | 9 | if type(skill) == int : 10 | 11 | continue 12 | 13 | else: 14 | 15 | print(f"{counter} - {skill}") -------------------------------------------------------------------------------- /14- Modules & Packages/01- Task 1.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | print(f"Random Number Between 10 And 50 => {random.randint(10,50)}") 4 | 5 | print(f"Random Even Number Between 2 And 10 => {random.randrange(2,10,2)}") 6 | 7 | print(f"Random Odd Number Between 1 And 9 => {random.randrange(1,9,2)}") 8 | 9 | print(dir(random)) -------------------------------------------------------------------------------- /14- Modules & Packages/02- Task 2,3,4.py: -------------------------------------------------------------------------------- 1 | # ---------------------- 2 | # in my_mod.py file: 3 | # ---------------------- 4 | 5 | # say_welcome function 6 | 7 | def say_welcome (name): 8 | 9 | print(f"Welcome {name}") 10 | 11 | 12 | # say_hello function 13 | 14 | def say_hello (name): 15 | 16 | print(f"Hello {name}") 17 | 18 | 19 | # ================================================== 20 | 21 | # ---------------------- 22 | # in main.py file: 23 | # ---------------------- 24 | 25 | import sys 26 | 27 | sys.path.append(r"C:\Users\A L I\Desktop\Python") 28 | 29 | # Calling the Whole module 30 | import my_mod 31 | my_mod.say_welcome("Ali") 32 | 33 | my_mod.say_hello("Ola") 34 | 35 | # Calling Function only 36 | from my_mod import say_welcome 37 | say_welcome("Ali") 38 | 39 | from my_mod import say_hello 40 | say_hello("Ola") 41 | 42 | # Using Alias 43 | from my_mod import say_welcome as welcome 44 | welcome("Ali") 45 | 46 | from my_mod import say_hello as hello 47 | hello("Ola") -------------------------------------------------------------------------------- /15- Date & Time/01.py: -------------------------------------------------------------------------------- 1 | # print number of days from a specific date to the current date. 2 | 3 | import datetime 4 | 5 | current_date = datetime.datetime.now() 6 | 7 | specific_date = datetime.datetime(2021, 6, 25) 8 | 9 | print(f"Number Of Days From '2021-06-25' To The Current date Is => {(current_date - specific_date).days} days") -------------------------------------------------------------------------------- /15- Date & Time/02.py: -------------------------------------------------------------------------------- 1 | # printing the current date and time in different methods 2 | 3 | import datetime 4 | 5 | # ---------------(DATE)--------------- 6 | 7 | print(datetime.datetime.now().strftime("%Y-%m-%d")) 8 | # 2022-07-01 9 | 10 | print(datetime.datetime.now().strftime("%b %d, %Y")) 11 | # Jul 01, 2022 12 | 13 | print(datetime.datetime.now().strftime("%d-%b-%Y")) 14 | # 01-Jul-2022 15 | 16 | print(datetime.datetime.now().strftime("%d/%b/%y")) 17 | # 01/Jul/22 18 | 19 | print(datetime.datetime.now().strftime("%a, %d %B %Y")) 20 | # Fri, 01 July 2022 21 | 22 | print(datetime.datetime.now().strftime("%x")) 23 | # 07/01/22 24 | 25 | 26 | # ---------------(TIME)--------------- 27 | 28 | print(datetime.datetime.now().strftime("%-I:%-M:%-S %P")) 29 | # 2:49:59 pm 30 | 31 | print(datetime.datetime.now().strftime("%X")) 32 | # 14:49:59 33 | 34 | 35 | # ---------------(DATE & TIME)--------------- 36 | 37 | print(datetime.datetime.now().strftime("%c")) 38 | # Fri Jul 1 14:49:59 2022 39 | 40 | 41 | -------------------------------------------------------------------------------- /16- Generators & Decorators/01.py: -------------------------------------------------------------------------------- 1 | def reverse_string(my_string): 2 | 3 | my_reversed_string = list(reversed(my_string)) 4 | 5 | string = "".join(my_reversed_string) 6 | 7 | yield string[0] 8 | yield string[1] 9 | yield string[2] 10 | yield string[3] 11 | yield string[4] 12 | yield string[5] 13 | 14 | myGen = reverse_string('Python') 15 | 16 | for character in myGen: 17 | 18 | print(character) 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /16- Generators & Decorators/02.py: -------------------------------------------------------------------------------- 1 | def Decorator(my_function): 2 | 3 | def Decorator_mess(): 4 | 5 | print("Sugar Added From Decorators") 6 | 7 | my_function() 8 | 9 | print("#" * 50) 10 | 11 | return Decorator_mess 12 | 13 | @Decorator 14 | 15 | def make_tea(): 16 | 17 | print("Tea Created") 18 | 19 | 20 | @Decorator 21 | 22 | def make_coffe(): 23 | 24 | print("Coffe Created") 25 | 26 | 27 | make_tea() 28 | make_coffe() -------------------------------------------------------------------------------- /17- Collection of Modules/01 zip function.py: -------------------------------------------------------------------------------- 1 | my_list = ["E", "Z", "R", 1, 2, 3] 2 | my_tuple = ("L", "E", "O") 3 | my_data = [] 4 | 5 | for data in zip(my_list, my_tuple): 6 | 7 | a = list(data) 8 | 9 | x = "".join(a) 10 | 11 | my_data.append(x) 12 | 13 | 14 | final_string = "".join(my_data) 15 | 16 | print(final_string.lower().capitalize()) 17 | # Elzero -------------------------------------------------------------------------------- /17- Collection of Modules/02 zip function.py: -------------------------------------------------------------------------------- 1 | my_list = ["E", "L", "Z", "E", "R", "O", 1, 2] 2 | my_tuple1 = ("E", "Z", "R", 1, 2, "E", "R", "O") 3 | my_tuple2 = ("L", "E", "O", 1, 2, "E", "R", "O") 4 | my_data = [] 5 | 6 | for item1, item2, item3 in zip(my_list, my_tuple1, my_tuple2): 7 | 8 | my_data.append(item1) 9 | 10 | 11 | my_data.remove(1) 12 | my_data.remove(2) 13 | 14 | final_string = "".join(my_data) 15 | 16 | print(final_string.lower().capitalize()) 17 | # Elzero 18 | -------------------------------------------------------------------------------- /17- Collection of Modules/03 Image Manipulation With Pillow.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | 3 | 4 | # Open the image 5 | my_image = Image.open("G:\elzero-pillow.jpg") 6 | 7 | # crop "L" letter 8 | box1 = (400, 0, 800, 400) 9 | letter_l = my_image.crop(box1) 10 | 11 | # convert "L" letter to grayscale mood 12 | gray_letter_l = letter_l.convert("L") 13 | 14 | # save "L" letter image 15 | gray_letter_l.save('G:/first_task.jpg') 16 | 17 | # =============================================== 18 | 19 | # crop 2nd row 20 | box2 = (0, 400, 1200, 800) 21 | second_row = my_image.crop(box2) 22 | 23 | # convert 2nd row to grayscale mood 24 | gray_second_row = second_row.convert("L") 25 | 26 | # rotate 2nd row image 27 | angle = 180 28 | rotated_image = gray_second_row.rotate(angle) 29 | 30 | # save 2nd row image 31 | rotated_image.save('G:/second_task.jpg') 32 | 33 | -------------------------------------------------------------------------------- /17- Collection of Modules/04 Doc String.py: -------------------------------------------------------------------------------- 1 | def say_Hello(name): 2 | 3 | """ 4 | This is a function that Says Hello to the user 5 | parameter: 6 | name => Person's Name 7 | return: 8 | Return Hello Message To The Person 9 | """ 10 | 11 | return f"Hello {name}" 12 | 13 | 14 | print(say_Hello("Ali")) 15 | 16 | 17 | print(say_Hello.__doc__) -------------------------------------------------------------------------------- /17- Collection of Modules/05 Using PyLint to rate the code.py: -------------------------------------------------------------------------------- 1 | """A function that says hello to list members""" 2 | 3 | my_friends = ["Ahmed", "Osama", "Sayed"] 4 | 5 | def say_hello(some_peoples) -> list: 6 | 7 | """ 8 | This is a function that Says Hello to list members 9 | parameter: 10 | some_peoples => list 11 | return: 12 | Return Hello Message To The Person 13 | """ 14 | 15 | for someone in some_peoples: 16 | print(f"Hello {someone}") 17 | 18 | say_hello(my_friends) 19 | -------------------------------------------------------------------------------- /18- Error Handling & Debugging/01.py: -------------------------------------------------------------------------------- 1 | user_NUM = input("Add Your Number => ") 2 | 3 | 4 | if len(user_NUM) > 1: 5 | 6 | raise IndexError ("Only One Character Allowed") 7 | 8 | elif len(user_NUM) == 1 and user_NUM == '0': 9 | 10 | raise ValueError ("Number Must Be Larger Than '0'") 11 | 12 | elif ((user_NUM >= 'a' and user_NUM <= 'z') or (user_NUM >= 'A' and user_NUM <= 'Z')): 13 | 14 | raise Exception ("Only Numbers Allowed") 15 | 16 | elif len(user_NUM) == 1 and user_NUM != '0' and user_NUM.isdigit(): 17 | 18 | print("##################") 19 | print(f"The Number Is '{user_NUM}'") 20 | print("##################") 21 | -------------------------------------------------------------------------------- /18- Error Handling & Debugging/02.py: -------------------------------------------------------------------------------- 1 | try: 2 | 3 | user_LETTER = input("Add Letter From A to Z => ") 4 | 5 | if len(user_LETTER) > 1: 6 | 7 | raise IndexError 8 | 9 | elif user_LETTER >= 'A' and user_LETTER <= 'Z' and len(user_LETTER) == 1: 10 | 11 | print(f"You Typed '{user_LETTER}'") 12 | 13 | else: 14 | 15 | raise ValueError 16 | 17 | except IndexError: 18 | 19 | print("You Must Write One Character Only") 20 | 21 | except ValueError: 22 | 23 | print("The Letter Not In A - Z") 24 | -------------------------------------------------------------------------------- /18- Error Handling & Debugging/03.py: -------------------------------------------------------------------------------- 1 | def calculate(num1, num2) -> int: 2 | 3 | return num1 + num2 4 | 5 | 6 | print(calculate(20, 30)) 7 | -------------------------------------------------------------------------------- /19- Regular Expression/01.py: -------------------------------------------------------------------------------- 1 | 2 | # Regular Expression to match => (E-l-z-e-r-o) in this strint => "eeeeE llllLl lllzzZzzzz eroe operationr pollo" 3 | 4 | # RegEx. => (\w ) 5 | 6 | import re 7 | 8 | my_string = "eeeeE llllLl lllzzZzzzz eroe operationr pollo " 9 | 10 | result = re.findall(r"(\w )", my_string) 11 | 12 | print(result) 13 | # ['E ', 'l ', 'z ', 'e ', 'r ', 'o '] 14 | -------------------------------------------------------------------------------- /19- Regular Expression/02.py: -------------------------------------------------------------------------------- 1 | # Regular Expression to match => (LElzero) in this strint => "EElzero11 LElzero111 ZElzero1111 EElzero11111 RElzero111111 OElzero1111111" 2 | 3 | # RegEx. => (L[A-z]+) 4 | 5 | import re 6 | 7 | my_string = "EElzero11 LElzero111 ZElzero1111 EElzero11111 RElzero111111 OElzero1111111" 8 | 9 | result = re.findall(r"(L[A-z]+)", my_string) 10 | 11 | print(result) 12 | # ['LElzero'] 13 | -------------------------------------------------------------------------------- /19- Regular Expression/03.py: -------------------------------------------------------------------------------- 1 | # Regular Expression to match => (+(0100) 600-1234 || +(0100) 60-1234 || (0100) 6000-1234) 2 | 3 | # RegEx. => (\+?)(\(0100\))\s(\d{,4})-(\d{4}) 4 | 5 | import re 6 | 7 | my_string1 = "+(0100) 600-1234" 8 | my_string2 = "+(0100) 60-1234" 9 | my_string3 = "(0100) 6000-1234" 10 | my_string4 = "01006001234" 11 | my_string5 = "0100 600 1234" 12 | my_string6 = "(0100) 600-1" 13 | my_string7 = "(0100) 600-12" 14 | 15 | 16 | result1 = re.findall(r"((\+?)(\(0100\))\s(\d{,4})-(\d{4}))", my_string1) 17 | result2 = re.findall(r"((\+?)(\(0100\))\s(\d{,4})-(\d{4}))", my_string2) 18 | result3 = re.findall(r"((\+?)(\(0100\))\s(\d{,4})-(\d{4}))", my_string3) 19 | result4 = re.findall(r"((\+?)(\(0100\))\s(\d{,4})-(\d{4}))", my_string4) 20 | result5 = re.findall(r"((\+?)(\(0100\))\s(\d{,4})-(\d{4}))", my_string5) 21 | result6 = re.findall(r"((\+?)(\(0100\))\s(\d{,4})-(\d{4}))", my_string6) 22 | result7 = re.findall(r"((\+?)(\(0100\))\s(\d{,4})-(\d{4}))", my_string7) 23 | 24 | 25 | 26 | print(result1) 27 | # ['+(0100) 600-1234'] 28 | print(result2) 29 | # ['+(0100) 60-1234'] 30 | print(result3) 31 | # ['(0100) 6000-1234'] 32 | print(result4) 33 | # [] 34 | print(result5) 35 | # [] 36 | print(result6) 37 | # [] 38 | print(result7) 39 | # [] 40 | -------------------------------------------------------------------------------- /19- Regular Expression/04.py: -------------------------------------------------------------------------------- 1 | # Regular Expression to match => (http://www.elzero.org:8888/link.php || https://elzero.org:8888/link.php || http://www.elzero.com/link.py || https://elzero.com/link.py) 2 | 3 | # RegEx. => (https?://)(www\.)?(\w+)(.com|.org)(:\d+)?(.+) 4 | 5 | import re 6 | 7 | my_string1 = "http://www.elzero.org:8888/link.php" 8 | my_string2 = "https://elzero.org:8888/link.php" 9 | my_string3 = "http://www.elzero.com/link.py" 10 | my_string4 = "https://elzero.com/link.py" 11 | my_string5 = "http://www.elzero.net" 12 | my_string6 = "https://elzero.net" 13 | 14 | result1 = re.findall(r"((https?://)(www\.)?(\w+)(.com|.org)(:\d+)?(.+))", my_string1) 15 | result2 = re.findall(r"((https?://)(www\.)?(\w+)(.com|.org)(:\d+)?(.+))", my_string2) 16 | result3 = re.findall(r"((https?://)(www\.)?(\w+)(.com|.org)(:\d+)?(.+))", my_string3) 17 | result4 = re.findall(r"((https?://)(www\.)?(\w+)(.com|.org)(:\d+)?(.+))", my_string4) 18 | result5 = re.findall(r"((https?://)(www\.)?(\w+)(.com|.org)(:\d+)?(.+))", my_string5) 19 | result6 = re.findall(r"((https?://)(www\.)?(\w+)(.com|.org)(:\d+)?(.+))", my_string6) 20 | 21 | 22 | print(result1) 23 | # ['http://www.elzero.org:8888/link.php'] 24 | print(result2) 25 | # ['https://elzero.org:8888/link.php'] 26 | print(result3) 27 | # ['http://www.elzero.com/link.py] 28 | print(result4) 29 | # ['https://elzero.com/link.py] 30 | print(result5) 31 | # [] 32 | print(result6) 33 | # [] 34 | -------------------------------------------------------------------------------- /19- Regular Expression/05.py: -------------------------------------------------------------------------------- 1 | # Regular Expression to match => (http || https) by 5 methods. 2 | 3 | # RegEx. 1 => https? 4 | # RegEx. 2 => http\w? 5 | # RegEx. 3 => http.? 6 | # RegEx. 4 => http[a-z]? 7 | # RegEx. 5 => http\S? 8 | 9 | import re 10 | 11 | my_string = "http || https || abcd || abcd" 12 | 13 | result = re.findall(r"(http\w?)", my_string) 14 | 15 | print(result) 16 | #['http', 'https'] 17 | -------------------------------------------------------------------------------- /20- OOP/01.py: -------------------------------------------------------------------------------- 1 | class Game: 2 | 3 | def __init__ (self, name, developer, date, price): 4 | 5 | self.name = name 6 | self.developer = developer 7 | self.year = date 8 | self.price = price 9 | 10 | def price_in_pounds(self): 11 | 12 | return f"{self.price * 15.6} Egyptian Pounds" 13 | 14 | game_one = Game("Ys", "Falcom", 2010, 50) 15 | 16 | print(f"Game Name Is \"{game_one.name}\", ", end="") 17 | print(f"Developer Is \"{game_one.developer}\", ", end="") 18 | print(f"Release Date Is \"{game_one.year}\", ", end="") 19 | print(f"Price In Egypt Is {game_one.price_in_pounds()}", end="") 20 | 21 | # Game Name Is "Ys", Developer Is "Falcom", Release Date Is "2010", Price In Egypt Is 780.0 Egyptian Pounds 22 | 23 | -------------------------------------------------------------------------------- /20- OOP/02.py: -------------------------------------------------------------------------------- 1 | class User: 2 | 3 | def __init__ (self, first_name, last_name, age, gender): 4 | 5 | self.fname = first_name 6 | self.lname = last_name 7 | self.age = age 8 | self.gender = gender 9 | 10 | def full_details(self): 11 | 12 | if self.gender == 'Male': 13 | 14 | return f"Hello Mr. {self.fname} {self.lname[0]}. [{40 - self.age}] Years To Reach 40" 15 | 16 | elif self.gender == 'Female': 17 | 18 | return f"Hello Mrs. {self.fname} {self.lname[0]}. [{40 - self.age}] Years To Reach 40" 19 | 20 | 21 | user_one = User("Osama", "Mohamed", 38, "Male") 22 | user_two = User("Eman", "Omar", 25, "Female") 23 | 24 | print(user_one.full_details()) # Hello Mr. Osama M. [2] Years To Reach 40 25 | print(user_two.full_details()) # Hello Mrs. Eman O. [15] Years To Reach 40 26 | -------------------------------------------------------------------------------- /20- OOP/03.py: -------------------------------------------------------------------------------- 1 | class Message: 2 | 3 | def __init__ (self): 4 | 5 | pass 6 | 7 | def print_message(): 8 | 9 | return "Hello From Class Message" 10 | 11 | print(Message.print_message()) 12 | 13 | # Output 14 | # Hello From Class Message 15 | -------------------------------------------------------------------------------- /20- OOP/04.py: -------------------------------------------------------------------------------- 1 | class Games: 2 | 3 | def __init__ (self, games): 4 | 5 | self.games = games 6 | 7 | def show_games(self): 8 | 9 | if type(self.games) == str: 10 | 11 | print (f"I Have One Game Called '{self.games}'") 12 | 13 | elif type(self.games) == list: 14 | 15 | print(f"I Have Many Games:") 16 | 17 | for game in self.games: 18 | 19 | print(f"-- {game}") 20 | 21 | elif type(self.games) == int: 22 | 23 | print (f"I Have {self.games} Game.") 24 | 25 | 26 | 27 | my_game = Games("Shadow Of Mordor") 28 | my_games_names = Games(["Ys II", "Ys Oath In Felghana", "YS Origin"]) 29 | my_games_count = Games(80) 30 | 31 | 32 | my_game.show_games() 33 | # I Have One Game Called 'Shadow Of Mordor' 34 | 35 | my_games_names.show_games() 36 | # I Have Many Games: 37 | # -- Ys II 38 | # -- Ys Oath In Felghana 39 | # -- YS Origin 40 | 41 | my_games_count.show_games() 42 | # I Have 80 Game. 43 | 44 | -------------------------------------------------------------------------------- /20- OOP/05.py: -------------------------------------------------------------------------------- 1 | # Main Class 2 | 3 | class Members: 4 | 5 | def __init__(self, n, p): 6 | 7 | self.name = n 8 | 9 | self.permission = p 10 | 11 | def show_info(self): 12 | 13 | return f"Your Name Is {self.name} And You Are {self.permission}" 14 | 15 | # Admin Class 16 | 17 | class Admins (Members): 18 | 19 | def __init__(self, n, p): 20 | 21 | Members.__init__ (self, n, p) 22 | 23 | 24 | # Moderators Class 25 | 26 | class Moderators (Members): 27 | 28 | def __init__(self, n, p): 29 | 30 | super().__init__ (n, p) 31 | 32 | 33 | member_one = Admins("Osama", "Admin") 34 | member_two = Moderators("Ahmed", "Moderator") 35 | 36 | 37 | print(member_one.show_info()) 38 | # Your Name Is Osama And You Are Admin 39 | 40 | print(member_two.show_info()) 41 | # Your Name Is Ahmed And You Are Moderator 42 | -------------------------------------------------------------------------------- /20- OOP/06.py: -------------------------------------------------------------------------------- 1 | class A: 2 | 3 | def __init__(self, one): 4 | 5 | self.one = one 6 | 7 | class B (A): 8 | 9 | def __init__(self, one, two): 10 | 11 | super().__init__ (one) 12 | 13 | self.two = two 14 | 15 | class C (B): 16 | 17 | def __init__(self, one, two, three): 18 | 19 | super().__init__ (one, two) 20 | 21 | self.three = three 22 | 23 | class Text (C): 24 | 25 | def __init__(self, one, two, three): 26 | 27 | super().__init__ (one, two, three) 28 | 29 | def show_name (self): 30 | 31 | return f"The Name Is {self.one}{self.two}{self.three}" 32 | 33 | 34 | the_name = Text("El", "ze", "ro") 35 | 36 | print(the_name.show_name()) 37 | # The Name Is Elzero 38 | -------------------------------------------------------------------------------- /21- SQLite Database/01- Task 1.py: -------------------------------------------------------------------------------- 1 | # import SQLite module 2 | import sqlite3 3 | 4 | # connect database 5 | db = sqlite3.connect("Database Data Types.db") 6 | 7 | # setting up the cursor 8 | cr = db.cursor() 9 | 10 | # create tables and fields 11 | cr.execute("create table if not exists Data (id INT, name TEXT, age TINYINT, dob DATE, rank FLOAT)") 12 | 13 | # insert data into database 14 | cr.execute("insert into Data (id, name, age, dob, rank) values (1, 'Ali', 22, '6/2/2000', 96.5)") 15 | cr.execute("insert into Data (id, name, age, dob, rank) values (2, 'Ola', 20, '30/7/2002', 92.5)") 16 | 17 | # commit changes 18 | db.commit() 19 | 20 | # close database 21 | db.close() 22 | -------------------------------------------------------------------------------- /21- SQLite Database/02- Task 2,3,4 and 5.py: -------------------------------------------------------------------------------- 1 | # import SQLite module 2 | import sqlite3 3 | 4 | # connect database 5 | db = sqlite3.connect("elzero.db") 6 | 7 | # setting up the cursor 8 | cr = db.cursor() 9 | 10 | # create tables and fields 11 | cr.execute("create table if not exists users (id INT unique, name TEXT unique, dob DATE unique, email TEXT unique)") 12 | 13 | # inserting data into database 14 | try: 15 | cr.execute("insert into users (id, name, dob, email) values (1, 'Ahmed', '3/2/2000', 'a@elzero.org')") 16 | cr.execute("insert into users (id, name, dob, email) values (2, 'Ali', '12/2/2000', 'l@elzero.org')") 17 | cr.execute("insert into users (id, name, dob, email) values (3, 'Mona', '20/2/2000', 'm@elzero.org')") 18 | cr.execute("insert into users (id, name, dob, email) values (4, 'Gamal', '7/2/2000', 'g@elzero.org')") 19 | cr.execute("insert into users (id, name, dob, email) values (5, 'Ola', '26/2/2000', 'o@elzero.org')") 20 | 21 | except: 22 | pass 23 | 24 | 25 | # fetch data of last row 26 | cr.execute("select * from users where id = 5") 27 | fifth_result = cr.fetchall() 28 | print(fifth_result) 29 | 30 | 31 | # user input 32 | user_id = input("Enter your Id ") 33 | 34 | cr.execute(f"select id from users where id = '{user_id}'") 35 | id_results = cr.fetchone() 36 | 37 | if id_results != None: 38 | cr.execute(f"delete from users where id = '{user_id}'") 39 | print(f"User '{user_id}' Deleted.") 40 | print("Show Other Data:") 41 | cr.execute("select * from users") 42 | all_results = cr.fetchall() 43 | for row in all_results: 44 | print(f"ID => {row[0]}, Name => {row[1]}, Date Of Birth => {row[2]}, Email => {row[3]}") 45 | 46 | else: 47 | print("User Not Found.") 48 | 49 | 50 | # commit changes 51 | db.commit() 52 | 53 | # close database 54 | db.close() 55 | -------------------------------------------------------------------------------- /22- Advanced Concepts/01.py: -------------------------------------------------------------------------------- 1 | # import module 2 | import unittest 3 | 4 | # class creation 5 | class MyTestCase (unittest.TestCase): 6 | 7 | def test_one (self): 8 | self.assertIn(10, [5, 7, 8, 10], "10 should be present") 9 | 10 | def test_two (self): 11 | self.assertIs(type(10), int, "The Type Of 10 Is Int") 12 | 13 | def test_three (self): 14 | self.assertTrue(100, "Number 100 Return True") 15 | 16 | def test_four (self): 17 | self.assertFalse([], "Empty List [] Return False") 18 | 19 | def test_five (self): 20 | self.assertGreaterEqual(100, 90, "Number 100 should be greater than or Or Equal 90") 21 | 22 | 23 | if __name__ == "__main__": 24 | 25 | unittest.main() -------------------------------------------------------------------------------- /22- Advanced Concepts/02.py: -------------------------------------------------------------------------------- 1 | # import modules 2 | import string 3 | import random 4 | 5 | # store characters in lists 6 | s1 = list(string.ascii_lowercase) 7 | s2 = list(string.digits) 8 | 9 | # shuffle lists 10 | random.shuffle(s1) 11 | random.shuffle(s2) 12 | 13 | 14 | result = [] 15 | 16 | for x in range(7): 17 | 18 | result.append(s1[x]) 19 | result.append(s2[x]) 20 | 21 | random.shuffle(result) 22 | 23 | result.insert(4, "-") 24 | result.insert(9, "-") 25 | 26 | output = "".join(result) 27 | 28 | print(output) 29 | # p04d-8fj6-71yr3e 30 | # 5qo6-r4s8-1xpc30 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-Course-Assignments 2 |