├── .gitignore ├── 01_class(Core Python) ├── main.py └── readme.md ├── 02_class_(Decisions Statements) ├── Decision Statement.py ├── Escape Chracters.py └── Readme.md ├── 03_Class(Strings) ├── README.md └── class,py ├── 03_class(Loops) ├── Break And Continue │ ├── Break & Continue Statements In Python.py │ └── readme.md ├── For Loop │ ├── For Loops In Python.py │ └── readme.md ├── While Loop │ ├── While Loops In Python.py │ └── readme.md └── readme.md ├── 05__class(list_Tuple) ├── lists │ ├── README.md │ └── class.py └── tuple │ ├── README.md │ └── class.py ├── 06_Class(Set_Dict) ├── README.md └── main.py ├── 07_Class_(Function) ├── Functions.py └── Readme.md ├── 08_class(Module & packages) ├── Package.py ├── README.md ├── module.py └── sms │ ├── Admin │ ├── Tech │ │ ├── logout.py │ │ ├── product.py │ │ └── profile.py │ └── _init_.py │ ├── Hashim.py │ ├── User │ ├── _init_.py │ ├── logout.py │ ├── profile.py │ └── request.py │ └── _init_.py ├── 09 _class__Exceptional Handling ├── README.md └── main.py ├── 1-Numbers.py ├── 10-ForLoop.py ├── 10_class_(OOP) ├── README.md └── class10.py ├── 11-WhileLoop.py ├── 11_Class(Python Graphics) ├── Introduction to Python Graphic │ ├── import.PY │ └── readme.md ├── Programming with turtle │ └── Python Graphics for Biggners │ │ ├── Class01.py │ │ ├── image-1.png │ │ ├── image.png │ │ └── readme.md └── Python Graphic projects │ ├── Class01(Make a Spiral Circle) │ ├── Readme.md │ └── spiralcircle.py │ ├── Class02(Make a Rainbow Spiral) │ ├── Readme.md │ └── rainbowspiral.py │ ├── Class03(Make a Car) │ ├── Readme.md │ └── car.py │ ├── Class04(Make a Heart) │ ├── Readme.md │ └── heart.py │ ├── Class05(Make a Tree) │ ├── Readme.md │ └── tree.py │ ├── Class06(Make a Flower) │ ├── Readme.md │ └── flower.py │ ├── Class07(Make a Google Logo) │ ├── Readme.md │ └── google.py │ ├── Class08(Make a Batman logo) │ ├── Readme.md │ └── bat.py │ ├── Class09(Make a Ironman Face) │ ├── Readme.md │ └── ironman.py │ ├── Class10(Make a Python logo) │ ├── Readme.md │ └── pythonlogo.py │ ├── Class11(Make a Spiderman logo) │ ├── Readme.md │ └── spidermanlogo.py │ ├── Class12(Make a Rainbow) │ ├── Readme.md │ └── rainbow.py │ ├── Class13(Make a Character) │ ├── Readme.md │ └── character.py │ ├── Class14(Make Among us) │ ├── Readme.md │ └── amongus.py │ ├── Class15(Make a Spiderman) │ ├── Readme.md │ └── spiderman.py │ ├── Class16(Make a Doraemon) │ ├── Readme.md │ └── doremon.py │ └── Class17(Make a Pokeymon) │ ├── Readme.md │ └── pokemon.py ├── 12-ContinueBreakPass.py ├── 12_Class(Python Garbage Collector) ├── Garbage Collection │ ├── Circular References │ │ ├── Circular References Part1.png │ │ ├── Circular References Part2.png │ │ ├── Circular References Part3.png │ │ └── Circular References Part4.png │ ├── main.py │ └── readme.md ├── Reference Counting │ ├── main.py │ ├── readme.md │ └── refcount │ │ ├── Reference Count Part1.png │ │ ├── Reference Count Part2.png │ │ ├── Reference Count Part3.png │ │ ├── Reference Count Part4.png │ │ ├── Reference Count Part5.png │ │ ├── Reference Count Part6.png │ │ ├── Reference Count Part7.png │ │ └── Reference Count Part8.png └── readme.md ├── 13-Strings.py ├── 13_Class(Deep and Shallow Copy) ├── Class01(Uncorrect way of copying) │ ├── images │ │ ├── Uncorrect way of copying ex1.png │ │ ├── Uncorrect way of copying ex2.png │ │ └── Uncorrect way of copying ex3.png │ ├── main.py │ └── readme.md ├── Class02(Shallow Copy) │ ├── Shallow Copy Example.png │ ├── main.py │ └── readme.md ├── Class03(Deep Copy) │ ├── main.py │ └── readme.md └── readme.md ├── 14-Lists.py ├── 15-Tuple.py ├── 16-Set.py ├── 17-Dictionary.py ├── 18-Functions.py ├── 19-LambdaFunction.py ├── 2-python-comments.py ├── 20-Modules.py ├── 21-ExceptionHandling.py ├── 22-FileHandling.py ├── 23-Classes.py ├── 24-Getting Started mysql with python.pdf ├── 25.What is OOP.pdf ├── 26-Types of Inheritance.pdf ├── 3-PythonLiterals.py ├── 4-PythonVariables.py ├── 5-PythonOperators.py ├── 6-UserInput.py ├── 7-EscapeCharacters.py ├── 8-DecisionStatemets.py ├── 9-Iterations.py ├── Assests ├── Modules │ ├── ModulesPractice │ │ ├── dict.py │ │ ├── functions.py │ │ └── list.py │ └── Python Modules.pdf └── pakages │ └── SMS │ ├── Admin │ ├── __init__.py │ ├── dashboard.py │ ├── logout.py │ ├── product.py │ └── service.py │ ├── Tech │ ├── __init__.py │ ├── logout.py │ ├── profile.py │ └── work.py │ ├── User │ ├── __init__.py │ ├── logout.py │ ├── profile.py │ └── request.py │ ├── __init__.py │ └── main.py ├── ModuleExample.py ├── NewFile.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | .vscode/ 3 | *.pyc -------------------------------------------------------------------------------- /02_class_(Decisions Statements)/Decision Statement.py: -------------------------------------------------------------------------------- 1 | # Decision Statements in Python 2 | 3 | # Example 1: Simple if statement 4 | age = 25 5 | 6 | if age >= 18: 7 | print("You are eligible to vote.") 8 | 9 | # Example 2: if-else statement 10 | temperature = 30 11 | 12 | if temperature > 25: 13 | print("It's a hot day.") 14 | else: 15 | print("It's not too hot.") 16 | 17 | # Example 3: if-elif-else statement 18 | score = 75 19 | 20 | if score >= 90: 21 | grade = 'A' 22 | elif score >= 80: 23 | grade = 'B' 24 | elif score >= 70: 25 | grade = 'C' 26 | else: 27 | grade = 'D' 28 | 29 | print(f"Your grade is: {grade}") 30 | 31 | # Example 4: Nested if statements 32 | is_raining = True 33 | is_cold = False 34 | 35 | if is_raining: 36 | print("Bring an umbrella.") 37 | if is_cold: 38 | print("Wear a jacket.") 39 | else: 40 | print("No need for a jacket.") 41 | else: 42 | print("Enjoy the weather!") 43 | 44 | # Example 5: Ternary conditional expression 45 | age = 22 46 | status = "Minor" if age < 18 else "Adult" 47 | print(f"Status: {status}") 48 | -------------------------------------------------------------------------------- /02_class_(Decisions Statements)/Escape Chracters.py: -------------------------------------------------------------------------------- 1 | # Escape Characters in Python 2 | 3 | # Newline Character (\n) 4 | print("Hello, World!\nHow are you today?") 5 | 6 | # Tab Character (\t) 7 | print("Name:\tJohn Doe") 8 | 9 | # Backslash Character (\\) 10 | print("This is a backslash: \\") 11 | 12 | # Double Quote (\") 13 | print("She said, \"Python is awesome!\"") 14 | 15 | # Single Quote (\') 16 | print('He\'s learning Python.') 17 | 18 | # Raw String (r prefix) 19 | raw_string = r"This is a raw string \n without interpreting escape characters." 20 | print(raw_string) 21 | 22 | 23 | # Escape Characters in Python - Additional Examples 24 | 25 | # Multiple lines using triple-quoted strings 26 | multi_line_text = """This is a multiline string. 27 | It spans across multiple lines. 28 | Using triple quotes makes it easy.""" 29 | print(multi_line_text) 30 | 31 | # Combining newline and tab characters 32 | combined_escape = "First line\nSecond line\tIndented" 33 | print(combined_escape) 34 | 35 | # Unicode escape sequence 36 | unicode_escape = "\u03B1 is the Greek letter alpha" 37 | print(unicode_escape) 38 | 39 | # Bell sound escape character 40 | bell_sound = "Beep!\a" 41 | print(bell_sound) 42 | 43 | # Carriage return and backspace 44 | carriage_return = "This text will\roverwrite." 45 | backspace = "Back\bspace removes the previous character." 46 | print(carriage_return) 47 | print(backspace) 48 | 49 | -------------------------------------------------------------------------------- /03_class(Loops)/Break And Continue/Break & Continue Statements In Python.py: -------------------------------------------------------------------------------- 1 | ########## Break & Continue Statements Tutorial ############### 2 | 3 | # i = 0 4 | 5 | # while(i<45): 6 | # print(i+1) 7 | # i = i+1 8 | 9 | ############### Break Statement ############ 10 | i = 0 11 | 12 | while(True): 13 | # print(i+1, end =" ") 14 | if(i==11): 15 | break # Stop the loop if i become 44 16 | i = i+1 17 | 18 | # After break while loop stops 19 | # Program comes here 20 | 21 | # Output : 1 2 3 4 5 6 7 8 9 10 11 22 | 23 | ############### Continue Statement ############ 24 | 25 | # continue used to not execute codes below it in loop 26 | 27 | # if we want to print numbers which are greater than 5 28 | i = 0 29 | 30 | while(True): 31 | if i+1<5: 32 | i = i+1 33 | continue 34 | # below code inside while will not execute till i+1<5 35 | print(i+1, end =" ") 36 | if(i==11): 37 | i = i+1 38 | break # Stop the loop 39 | i = i+1 40 | 41 | # Output : 5 6 7 8 9 10 11 12 42 | 43 | ###### Quiz ###### 44 | 45 | # Keep taking input from user 46 | # till user enter number greater than 100 47 | 48 | 49 | # Solution : 50 | while(True): 51 | num = input("Please enter a number") 52 | if(int(num)<100): 53 | continue 54 | else: 55 | print("congratulations, you entered number >= 100") 56 | break 57 | 58 | 59 | -------------------------------------------------------------------------------- /03_class(Loops)/Break And Continue/readme.md: -------------------------------------------------------------------------------- 1 | # Python `break` and `continue` 2 | 3 | **Video link:** [https://youtu.be/Mho_1WO-ht4](https://youtu.be/Mho_1WO-ht4) 4 | 5 | In this video, we learned about `break` and `continue` statements in Python that can be used to alter the flow of a normal loop. 6 | 7 | **Programs in the Video** 8 | 9 | - [Python break Statement](#python-break-statement) 10 | - [Python continue Statement](#python-continue-statement) 11 | - [Programming Task](#programming-task) 12 | 13 | --- 14 | ## Python `break` Statement 15 | The `break` statement is used to terminate the loop completely. The control of the program flows to the statement immediately after the body of the loop. 16 | 17 | ```python 18 | for item in range(1, 6): 19 | print(item) 20 | break 21 | ``` 22 | 23 | **Output** 24 | ``` 25 | 1 26 | ``` 27 | 28 | Here, in the first iteration, the value of `item` is **1**. This is printed by the `print()` function. 29 | 30 | When the `break` statement is encountered, the loop immediately ends, so nothing else gets printed. 31 | 32 | If `break` was used in front of the `print()` statement, the loop would have terminated immediately without printing anything. 33 | 34 | ```python 35 | for item in range(1, 6): 36 | break 37 | print(item) 38 | ``` 39 | 40 | --- 41 | 42 | `break` statements are almost always used inside decision-making statements like `if...else` to end the loop only when a certain condition is met. 43 | 44 | 45 | ### Using `break` Statement with `for` 46 | 47 | ```python 48 | for item in range(1, 6): 49 | if item == 3: 50 | break 51 | print(item) 52 | 53 | print("The end") 54 | ``` 55 | 56 | **Ouput** 57 | ``` 58 | 1 59 | 2 60 | The end 61 | ``` 62 | 63 | --- 64 | 65 | ### Using `break` with `while` 66 | 67 | Let's create a program that prints number entered by the user, but terminates once the user enters a negative number. 68 | 69 | ```python 70 | while True: 71 | number = float(input("Enter a number: ")) 72 | if number < 0: 73 | break 74 | print("You entered:", number) 75 | ``` 76 | 77 | **Output** 78 | 79 | ``` 80 | Enter a number: 4 81 | You entered: 4.0 82 | Enter a number: 67 83 | You entered: 67.0 84 | Enter a number: -9 85 | ``` 86 | 87 | Here, the program terminates as soon as the user enteres a negative number. 88 | 89 | --- 90 | 91 | 92 | ## Python `continue` Statement 93 | The `continue` statement in Python skips the rest of the code inside the loop for that iteration. 94 | 95 | The loop will not terminate but continues on with the next iteration. 96 | 97 | --- 98 | 99 | ### Example: Using `continue` with `for` 100 | 101 | ```python 102 | for i in range(5): 103 | number = float(input("Enter a number: ")) 104 | 105 | # check if number if negative 106 | if number < 0: 107 | continue 108 | 109 | print(number) 110 | 111 | ``` 112 | 113 | **Output** 114 | 115 | ``` 116 | Enter a number: 4 117 | You entered: 4.0 118 | Enter a number: 54 119 | You entered: 54.0 120 | Enter a number: -9 121 | Enter a number: 76 122 | You entered: 76.0 123 | Enter a number: 67 124 | You entered: 67.0 125 | ``` 126 | 127 | Here, the `continue` statement is used to skip the current iteration when the number entered by the user is negative. 128 | 129 | Unlike `break`, `continue` does not terminate the loop entirely, the loop runs specified number of times (5 in this case). 130 | 131 | --- 132 | 133 | ## Programming Task 134 | 135 | **Can you create a program so that all items of the `languages` list are printed except `Swift` and `C++`?** 136 | 137 | ```python 138 | languages = ["Python", "Java", "Swift", "C", "C++"] 139 | ``` 140 | 141 | ```python 142 | languages = ["Python", "Java", "Swift", "C", "C++"] 143 | 144 | for language in languages: 145 | if language == "Swift" or language == "C++": 146 | continue 147 | print(language) 148 | 149 | ``` 150 | 151 | **Output** 152 | 153 | ``` 154 | Python 155 | Java 156 | C 157 | ``` 158 | -------------------------------------------------------------------------------- /03_class(Loops)/For Loop/For Loops In Python.py: -------------------------------------------------------------------------------- 1 | ################### For Loop Tutorial ############### 2 | 3 | # A List 4 | list1 = ['Vivek', 'Larry', 'Carry', 'Marie'] 5 | 6 | # To print all elements in list 7 | print(list1[0]) 8 | print(list1[1]) 9 | print(list1[2]) 10 | print(list1[3]) 11 | # Output : 12 | # Vivek 13 | # Larry 14 | # Carry 15 | # Marie 16 | 17 | # We can do same thing easily using for loop 18 | # for loop runs len(list1) times 19 | # each time item is equal to one elemrnt of list from starting 20 | for item in list1: 21 | print(item) 22 | # Output : 23 | # Vivek 24 | # Larry 25 | # Carry 26 | # Marie 27 | 28 | # We can iterate tuple, list of lists, dictionary, 29 | # and many more containers using for loop 30 | 31 | # Examples : 32 | 33 | # Iterating tuple 34 | list1 = ('Vivek', 'Larry', 'Carry', 'Marie') 35 | for item in list1: 36 | print(item) 37 | # Output : 38 | # Vivek 39 | # Larry 40 | # Carry 41 | # Marie 42 | 43 | # Iterating a list of lists 44 | list1 = [ ["Vivek", 1], ["Larry", 2], 45 | ["Carry", 6], ["Marie", 250]] 46 | for item in list1: 47 | print(item) 48 | # Output : 49 | # ['Vivek', 1] 50 | # ['Larry', 2] 51 | # ['Carry', 6] 52 | # ['Marie', 250] 53 | 54 | # Iterating a dictionary 55 | dict1 = dict(list1) 56 | print(dict1) 57 | # Output : 58 | # {'Vivek': 1, 'Larry': 2, 'Carry': 6, 'Marie': 250} 59 | 60 | for item in dict1: 61 | print(item) # It will print only keys 62 | # Output : 63 | # Vivek 64 | # Larry 65 | # Carry 66 | # Marie 67 | 68 | # to print both key and value while iterating dictionary 69 | for item, lollypop in dict1.items(): 70 | print(item, "and lolly is ", lollypop) 71 | # Output : 72 | # Vivek and lolly is 1 73 | # Larry and lolly is 2 74 | # Carry and lolly is 6 75 | # Marie and lolly is 250 76 | 77 | # Quiz time : 78 | # Ques : Create a list if item in list is numerical 79 | # and number is greater than 6 80 | 81 | 82 | # Solution 83 | items = [int, float, "HaERRY", 5,3, 3, 22, 21, 64, 23, 233, 23, 6] 84 | 85 | for item in items: 86 | if str(item).isnumeric() and item>=6: 87 | print(item) 88 | # Remember str(item).isnumeric() is correct 89 | # item.isnumeric() is wrong 90 | 91 | # Output : 92 | # 22 93 | # 21 94 | # 64 95 | # 23 96 | # 233 97 | # 23 98 | # 6 99 | -------------------------------------------------------------------------------- /03_class(Loops)/For Loop/readme.md: -------------------------------------------------------------------------------- 1 | # Python for Loop 2 | 3 | **Video link:** [https://youtu.be/yaqMSBr_NCU](https://youtu.be/yaqMSBr_NCU) 4 | 5 | In this video, we learned about loops to repeat certain blocks of code, specifically using the `for` loop. 6 | 7 | **Programs in the Video** 8 | 9 | - [Python Sequences](#python-sequences) 10 | - [Python for Loop](#python-for-loop-1) 11 | - [Looping Through a List](#looping-through-a-list) 12 | - [Python range()](#python-range) 13 | - [**Example**: Multiplication Table](#example-multiplication-table) 14 | - [**Task**: Sum of Numbers](#programming-task) 15 | 16 | --- 17 | ## Python Sequences 18 | A sequence is a collection of items in an order. We have already used strings numerous times in our programs. 19 | A string is basically a sequence of characters. 20 | 21 | ```python 22 | # Python sequences 23 | text = "Python" 24 | languages = ['English', 'French', 'German'] 25 | ``` 26 | 27 | The sequence with three items separated by commas and enclosed in square brackets is called a list. 28 | We will learn about them in the upcoming tutorials. 29 | 30 | --- 31 | 32 | ## Python `for` loop 33 | The for loop in Python is used to iterate over a sequence, and in each iteration, we can access individual items of that sequence. 34 | 35 | The syntax of the `for` loop in Python is: 36 | 37 | ``` 38 | for item in sequence: 39 | statement(s) 40 | ``` 41 | 42 | Here, the statements inside the `for` loop are executed for every item in `sequence`. 43 | 44 | --- 45 | 46 | ### Example: Using `for` Loops 47 | 48 | ```python 49 | text = "Python" 50 | 51 | for character in text: 52 | print(character) 53 | ``` 54 | 55 | **Output** 56 | 57 | ``` 58 | P 59 | y 60 | t 61 | h 62 | o 63 | n 64 | ``` 65 | 66 | Here, using a for loop we have accessed individual items of this string one by one. 67 | 68 | During the first iteration of the loop, the variable `character` will be the first letter `'P'` and it gets printed to the screen. 69 | 70 | The loop continues similarly until we reach the last item in the sequence. 71 | 72 | --- 73 | 74 | ## Looping Through a List 75 | 76 | We can use the `for` loop to iterate through each item of this list one by one. 77 | 78 | ```python 79 | languages = ["English", "French", "German"] 80 | 81 | for language in languages: 82 | print(language) 83 | ``` 84 | 85 | **Output** 86 | 87 | ``` 88 | English 89 | French 90 | German 91 | ``` 92 | 93 | --- 94 | 95 | ## Python `range()` 96 | 97 | In the previous tutorial, we used `while` loop to repeat a block of code a certain number of times. 98 | 99 | ```python 100 | count = 1 101 | 102 | while count <= 5: 103 | print(count) 104 | count = count + 1 105 | ``` 106 | 107 | **Output** 108 | 109 | ``` 110 | 1 111 | 2 112 | 3 113 | 4 114 | 5 115 | ``` 116 | 117 | We can use `range()` with a `for` loop to write this program in a much simpler way. 118 | 119 | ```python 120 | for count in range(1, 6): 121 | print(count) 122 | ``` 123 | 124 | **Output** 125 | ``` 126 | 1 127 | 2 128 | 3 129 | 4 130 | 5 131 | ``` 132 | 133 | The `range()` function creates a sequence of numbers from 1 to 5. The last value passed (6 in this case) is exclusive. 134 | 135 | --- 136 | ## Example: Multiplication Table 137 | 138 | ```python 139 | number = int(input("Enter an integer: ")) 140 | 141 | for count in range(1, 11): 142 | product = number * count 143 | print(number, "*", count, "=", product) 144 | ``` 145 | 146 | **Output** 147 | ``` 148 | Enter an integer: 9 149 | 9 * 1 = 9 150 | 9 * 2 = 18 151 | 9 * 3 = 27 152 | 9 * 4 = 36 153 | 9 * 5 = 45 154 | 9 * 6 = 54 155 | 9 * 7 = 63 156 | 9 * 8 = 72 157 | 9 * 9 = 81 158 | 9 * 10 = 90 159 | ``` 160 | 161 | --- 162 | 163 | ## Programming Task 164 | 165 | **Can you create a program to find the sum of numbers from 1 to 100.** 166 | 167 | The result should be equal to **1 + 2 + 3 + ... + 100**. 168 | 169 | ```python 170 | total = 0 171 | 172 | # looping from 1 to 100 173 | for number in range(1, 101): 174 | total = total + number 175 | print(total) 176 | ``` 177 | 178 | **Output** 179 | 180 | ``` 181 | 5050 182 | ``` 183 | -------------------------------------------------------------------------------- /03_class(Loops)/While Loop/While Loops In Python.py: -------------------------------------------------------------------------------- 1 | ############## While loop Tutorial ######### 2 | 3 | i = 0 4 | 5 | # While Condition is true 6 | # Inside code of while keep runs 7 | 8 | # This will keep printing 0 9 | # while(i<45): 10 | # print(i) 11 | 12 | # To stop while loop 13 | # update i to break the condition 14 | while(i<8): 15 | print(i) 16 | i = i + 1 17 | # Output : 18 | # 0 19 | # 1 20 | # 2 21 | # 3 22 | # 4 23 | # 5 24 | # 6 25 | # 7 26 | # 8 27 | 28 | # Assuming code inside for and while loop is same 29 | # Both While and for loop takes almost equal time 30 | # As both converted into same machine code 31 | 32 | # So you can use any thing which is convenient -------------------------------------------------------------------------------- /03_class(Loops)/While Loop/readme.md: -------------------------------------------------------------------------------- 1 | # Python while Loop 2 | 3 | **Video link:** [https://youtu.be/5AOfDuV6X30](https://youtu.be/5AOfDuV6X30) 4 | 5 | In this video, we learned about loops to repeat certain blocks of code, specifically using the `while` loop. 6 | 7 | **Programs in the Video** 8 | 9 | - [Python while Loop](#python-while-loop-1) 10 | - [**Task**: Guess the output](#programming-task-1) 11 | - [**Example**: Multiplication Table](#example-multiplication-table) 12 | - [**Task**: Reverse Multiplication Table](#programming-task-2) 13 | 14 | --- 15 | 16 | ## Python `while` loop 17 | Looping is a fundamental concept in all programming languages, not just Python. They are used to repeat a block of code multiple times as per our requirement. One such type of loop is the `while` loop. 18 | 19 | The syntax of the `while` loop in Python is: 20 | 21 | ``` 22 | while test_condition: 23 | statement(s) 24 | ``` 25 | 26 | Here, the statements inside the `while` loop are executed for as long as `test_condition` evaluates to `True`. 27 | 28 | --- 29 | 30 | ### Example: Using `while` Loops 31 | 32 | ```python 33 | count = 0 34 | 35 | while count < 5: 36 | print("I am inside a loop.") 37 | print("Looping is interesting.") 38 | ``` 39 | 40 | **Output** 41 | 42 | ``` 43 | I am inside a loop. 44 | Looping is interesting. 45 | ... 46 | ``` 47 | 48 | Here, the test condition is never `False`, so the loop runs forever until the system's memory runs out. 49 | 50 | --- 51 | 52 | Generally, we want programs that terminate at one point. For that, we can alter the value of `count` at every iteration like: 53 | 54 | ```python 55 | count = 0 56 | 57 | while count < 5: 58 | print("I am inside a Loop.") 59 | print("Looping is interesting.") 60 | count = count + 1 61 | ``` 62 | 63 | **Output** 64 | 65 | ``` 66 | I am inside a loop. 67 | Looping is interesting. 68 | I am inside a loop. 69 | Looping is interesting. 70 | I am inside a loop. 71 | Looping is interesting. 72 | I am inside a loop. 73 | Looping is interesting. 74 | I am inside a loop. 75 | Looping is interesting. 76 | ``` 77 | 78 | To understand what is going on let's print the value of `count`: 79 | 80 | ```python 81 | count = 0 82 | 83 | while count < 5: 84 | print(count) 85 | count = count + 1 86 | ``` 87 | 88 | **Output** 89 | 90 | ``` 91 | 0 92 | 1 93 | 2 94 | 3 95 | 4 96 | ``` 97 | Here, the block of code executes only **5** times as `count` goes from **0** to **4**. At `count = 5` the test condition is `False` and the loop terminates. 98 | 99 | --- 100 | 101 | ## Programming Task 1 102 | 103 | **Can you guess the output of this program?** 104 | 105 | ```python 106 | count = 5 107 | 108 | while count <= 10: 109 | print(count) 110 | count = count + 1 111 | ``` 112 | 113 | **Output** 114 | 115 | ``` 116 | 5 117 | 6 118 | 7 119 | 8 120 | 9 121 | 10 122 | ``` 123 | 124 | --- 125 | 126 | ## Example: Multiplication Table 127 | 128 | ```python 129 | number = int(input("Enter a number: ")) 130 | 131 | count = 1 132 | 133 | while count <= 10: 134 | product = number * count 135 | print(product) 136 | count = count + 1 137 | ``` 138 | 139 | **Output** 140 | 141 | ``` 142 | Enter a number: 6 143 | 6 144 | 12 145 | 18 146 | 24 147 | 30 148 | 36 149 | 42 150 | 48 151 | 54 152 | 60 153 | ``` 154 | 155 | To make it more readable, we can print `number`, `count`, and `product` adjacently using the following code: 156 | 157 | ```python 158 | number = int(input("Enter a number: ")) 159 | 160 | count = 1 161 | 162 | while count <= 10: 163 | product = number * count 164 | print(number, "x", count, "=", product) 165 | count = count + 1 166 | ``` 167 | 168 | **Output** 169 | 170 | ``` 171 | Enter a number: 6 172 | 6 * 1 = 6 173 | 6 * 2 = 12 174 | 6 * 3 = 18 175 | 6 * 4 = 24 176 | 6 * 5 = 30 177 | 6 * 6 = 36 178 | 6 * 7 = 42 179 | 6 * 8 = 48 180 | 6 * 9 = 54 181 | 6 * 10 = 60 182 | ``` 183 | 184 | --- 185 | 186 | ## Programming Task 2 187 | 188 | **Can you modify our multiplication table program so that we get a multiplication table from 10 to 1 instead of 1 to 10.** 189 | 190 | ```python 191 | number = int(input("Enter a number: ")) 192 | 193 | count = 10 194 | 195 | while count >= 1: 196 | product = number * count 197 | print(number, "x", count, "=", product) 198 | count = count - 1 199 | ``` 200 | 201 | **Output** 202 | 203 | ``` 204 | Enter a number: 6 205 | 6 x 10 = 60 206 | 6 x 9 = 54 207 | 6 x 8 = 48 208 | 6 x 7 = 42 209 | 6 x 6 = 36 210 | 6 x 5 = 30 211 | 6 x 4 = 24 212 | 6 x 3 = 18 213 | 6 x 2 = 12 214 | 6 x 1 = 6 215 | ``` -------------------------------------------------------------------------------- /05__class(list_Tuple)/tuple/README.md: -------------------------------------------------------------------------------- 1 | ## Using python to manipulate tuples 2 | 3 | Python Tuple is used to store the sequence of immutable Python 4 | objects. 5 | 6 | Tuples are written as a list of "comma-separated" 7 | ```python 8 | values (items) between parentheses. () 9 | ``` 10 | 11 | Tuples are immutable - this means that items can not be changed. 12 | However,a tuple can contain mutable objects. 13 | 14 | ### Tuple has 2 methods available. 15 | 16 | 1. count() Returns the number of elements with the specified value 17 | 2. index() Returns the index of the first element with the specified value 18 | 19 | 20 | ### The basics - tuple packing 21 | ```python 22 | 23 | # Original code 24 | t: Tuple[Union[int, str, str]] = 12345, 54321, 'hello!' 25 | print(t[0]) 26 | print(t) 27 | print(type(t)) 28 | 29 | T1: Tuple[int, str, int] = (101, "Peter", 22) 30 | T2: Tuple[str, str, str] = ("Apple", "Banana", "Orange") 31 | T3: Tuple[int, int, int, int, int] = 10, 20, 30, 40, 50 32 | 33 | print(type(T1)) 34 | print(type(T2)) 35 | print(type(T3)) # Class Tuple 36 | 37 | ``` 38 | The tuple which is created without using parentheses is also known as tuple packing. 39 | ```python 40 | # Creating a tuple with mixed types 41 | a: Tuple[Union[str, int, int, str]] = 'abc', 2, 4, 'd' 42 | print(type(a)) # Class Tuple 43 | 44 | ``` 45 | ### An empty tuple can be created as follows. 46 | ```python 47 | T4: Tuple[()] = () 48 | ``` 49 | 50 | ### Creating a tuple with single element is slightly different. 51 | 52 | We will need to put comma after the element to declare the tuple 53 | 54 | ```python 55 | # Creating a tuple with a single string element 56 | tup1: Tuple[str] = ("JavaTpoint",) # String 57 | print(type(tup1)) 58 | 59 | # Creating a tuple with a single element 60 | tup2: Tuple[str] = ("JavaTpoint",) # Tuple 61 | print(type(tup2)) 62 | 63 | ``` 64 | ## Output 65 | ```python 66 | 67 | 68 | 69 | ``` 70 | ### Example 1 71 | ```python 72 | # Creating a tuple with integers 73 | tuple1: Tuple[int, int, int, int, int, int] = (10, 20, 30, 40, 50, 60) 74 | print(tuple1) 75 | 76 | count: int = 0 77 | for i in tuple1: 78 | print("tuple1[%d] = %d" % (count, i)) 79 | count += 1 80 | 81 | ``` 82 | ### Output 83 | ```python 84 | (10, 20, 30, 40, 50, 60) 85 | tuple1[0] = 10 86 | tuple1[1] = 20 87 | tuple1[2] = 30 88 | tuple1[3] = 40 89 | tuple1[4] = 50 90 | tuple1[5] = 60 91 | 92 | ``` 93 | 94 | ### Example 2 95 | ```python 96 | # Assuming the tuple elements are strings 97 | tuple1: Tuple[str, ...] = tuple(input("Enter the tuple elements ...")) 98 | print(tuple1) 99 | 100 | count: int = 0 101 | for i in tuple1: 102 | print("tuple1[%d] = %s" % (count, i)) 103 | count += 1 104 | 105 | ``` 106 | ### Output 107 | ```python 108 | Enter the tuple elements ...123456 109 | ('1', '2', '3', '4', '5', '6') 110 | tuple1[0] = 1 111 | tuple1[1] = 2 112 | tuple1[2] = 3 113 | tuple1[3] = 4 114 | tuple1[4] = 5 115 | tuple1[5] = 6 116 | 117 | ``` 118 | ### indexing 119 | ```python 120 | tuple = (1,2,3,4,5,6,7) 121 | ``` 122 | ### element 1 to end 123 | ```python# 124 | print(tuple[1:]) 125 | 126 | ``` 127 | ### element 0 to 3 element 128 | ```python 129 | print(tuple[:4]) 130 | ``` 131 | #### element 1 to 4 element 132 | ```python 133 | print(tuple[1:5]) 134 | 135 | ``` 136 | ### element 0 to 6 and take step of 2 137 | ```python 138 | print(tuple[0:6:2]) 139 | 140 | ``` 141 | ### Output 142 | ```python 143 | (2, 3, 4, 5, 6, 7) 144 | (1, 2, 3, 4) 145 | (1, 2, 3, 4) 146 | (1, 3, 5) 147 | 148 | ``` 149 | 150 | ### Negative Indexing 151 | ```python 152 | tuple1: Tuple[int, int, int, int, int] = (1, 2, 3, 4, 5) 153 | print(tuple1[-1]) 154 | print(tuple1[-4]) 155 | print(tuple1[-3:-1]) 156 | print(tuple1[:-1]) 157 | print(tuple1[-2:]) 158 | 159 | ``` 160 | ### Output 161 | ```python 162 | 5 163 | 2 164 | (3, 4) 165 | (1, 2, 3, 4) 166 | (4, 5) 167 | 168 | ``` 169 | ### Deleting Tuple 170 | 171 | Unlike lists, the tuple items cannot be deleted by using the del keyword 172 | as tuples are immutable. To delete an entire tuple, we can use the del 173 | keyword with the tuple name. 174 | 175 | ```python 176 | tuple1: Tuple[int, int, int, int, int] = (1, 2, 3, 4, 5) 177 | print(tuple1) 178 | del tuple1[0] 179 | print(tuple1) 180 | del tuple1 181 | print(tuple1) 182 | 183 | ``` 184 | ### Output 185 | ```python 186 | (1, 2, 3, 4, 5, 6) 187 | 188 | ``` 189 | ```python 190 | Traceback (most recent call last): 191 | File "tuple.py", line 4, in 192 | print(tuple1) 193 | NameError: name 'tuple1' is not defined 194 | 195 | ``` 196 | 197 | ### Python Tuple inbuilt functions 198 | 199 | SN Function Description 200 | ```python 201 | 202 | 1 cmp(tuple1, tuple2) It compares two tuples and returns true 203 | if tuple1 is greater than tuple2 otherwise false. 204 | 2 len(tuple) It calculates the length of the tuple. 205 | 3 max(tuple) It returns the maximum element of the tuple 206 | 4 min(tuple) It returns the minimum element of the tuple. 207 | 5 tuple(seq) It converts the specified sequence to the tuple. 208 | 209 | ``` 210 | 211 | ### Where use tuple? 212 | ```python 213 | 1. Using tuple instead of list gives us a clear idea that tuple data 214 | is constant and must not be changed. 215 | 2. Tuple can simulate a dictionary without keys. Consider the following 216 | nested structure, which can be used as a dictionary. 217 | [(101, "John", 22), (102, "Mike", 28), (103, "Dustin", 30)] 218 | 219 | ``` 220 | 221 | ### Tuples may be nested: 222 | ```python 223 | v = ([1, 2, 3], [3, 2, 1]) 224 | u = v, (1, 2, 3, 4, 5) 225 | 226 | ``` 227 | 228 | -------------------------------------------------------------------------------- /05__class(list_Tuple)/tuple/class.py: -------------------------------------------------------------------------------- 1 | #Using python to manipulate tuples 2 | ''' 3 | Python Tuple is used to store the sequence of immutable Python 4 | objects. 5 | 6 | Tuples are written as a list of "comma-separated" 7 | values (items) between parentheses. () 8 | 9 | Tuples are immutable - this means that items can not be changed. 10 | However,a tuple can contain mutable objects. 11 | 12 | Tuple has 2 methods available. 13 | count() Returns the number of elements with the specified value 14 | index() Returns the index of the first element with the specified value 15 | ''' 16 | 17 | #The basics - tuple packing 18 | from typing import Tuple, Union 19 | 20 | # Original code 21 | t = 12345, 54321, 'hello!' 22 | print(t[0]) 23 | print(t) 24 | print(type(t)) 25 | 26 | T1: Tuple[Union[int, str, int]] = (101, "Peter", 22) 27 | T2: Tuple[str, str, str] = ("Apple", "Banana", "Orange") 28 | T3: Tuple[int, int, int, int, int] = 10, 20, 30, 40, 50 29 | 30 | print(type(T1)) 31 | print(type(T2)) 32 | print(type(T3)) # Class Tuple 33 | 34 | # The tuple which is created without using parentheses 35 | # is also known as tuple packing. 36 | a: Tuple[str, int, int, str] = 'abc', 2, 4, 'd' 37 | print(type(a)) # Class Tuple 38 | 39 | # An empty tuple can be created as follows. 40 | T4: Tuple[()] = () 41 | 42 | # Creating a tuple with a single element is slightly different. 43 | # We will need to put a comma after the element to declare the tuple 44 | tup1: Tuple[str] = ("JavaTpoint",) # String 45 | print(type(tup1)) 46 | 47 | # Creating a tuple with a single element 48 | tup2: Tuple[str] = ("JavaTpoint",) # Tuple 49 | print(type(tup2)) 50 | 51 | ''' 52 | Output 53 | 54 | 55 | ''' 56 | #Example 1 57 | tuple1: Tuple[int, int, int, int, int, int] = (10, 20, 30, 40, 50, 60) 58 | print(tuple1) 59 | 60 | count: int = 0 61 | for i in tuple1: 62 | print("tuple1[%d] = %d" % (count, i)) 63 | count += 1 64 | 65 | ''' 66 | (10, 20, 30, 40, 50, 60) 67 | tuple1[0] = 10 68 | tuple1[1] = 20 69 | tuple1[2] = 30 70 | tuple1[3] = 40 71 | tuple1[4] = 50 72 | tuple1[5] = 60 73 | ''' 74 | 75 | #Example 2 76 | # Assuming you want the tuple elements to be strings 77 | 78 | tuple1: Tuple[str, ...] = tuple(input("Enter the tuple elements ...")) 79 | print(tuple1) 80 | 81 | count: int = 0 82 | for i in tuple1: 83 | print("tuple1[%d] = %s" % (count, i)) 84 | count += 1 85 | ''' 86 | Output 87 | Enter the tuple elements ...123456 88 | ('1', '2', '3', '4', '5', '6') 89 | tuple1[0] = 1 90 | tuple1[1] = 2 91 | tuple1[2] = 3 92 | tuple1[3] = 4 93 | tuple1[4] = 5 94 | tuple1[5] = 6 95 | ''' 96 | #indexing 97 | tuple = (1,2,3,4,5,6,7) 98 | #element 1 to end 99 | print(tuple[1:]) 100 | #element 0 to 3 element 101 | print(tuple[:4]) 102 | #element 1 to 4 element 103 | print(tuple[1:5]) 104 | # element 0 to 6 and take step of 2 105 | print(tuple[0:6:2]) 106 | ''' 107 | Output 108 | (2, 3, 4, 5, 6, 7) 109 | (1, 2, 3, 4) 110 | (1, 2, 3, 4) 111 | (1, 3, 5) 112 | ''' 113 | 114 | #Negative Indexing 115 | tuple1 = (1, 2, 3, 4, 5) 116 | print(tuple1[-1]) 117 | print(tuple1[-4]) 118 | print(tuple1[-3:-1]) 119 | print(tuple1[:-1]) 120 | print(tuple1[-2:]) 121 | ''' 122 | Output 123 | 5 124 | 2 125 | (3, 4) 126 | (1, 2, 3, 4) 127 | (4, 5) 128 | ''' 129 | #Deleting Tuple 130 | ''' 131 | Unlike lists, the tuple items cannot be deleted by using the del keyword 132 | as tuples are immutable. To delete an entire tuple, we can use the del 133 | keyword with the tuple name. 134 | ''' 135 | tuple1 = (1, 2, 3, 4, 5, 6) 136 | print(tuple1) 137 | del tuple1[0] 138 | print(tuple1) 139 | del tuple1 140 | print(tuple1) 141 | ''' 142 | Output 143 | (1, 2, 3, 4, 5, 6) 144 | Traceback (most recent call last): 145 | File "tuple.py", line 4, in 146 | print(tuple1) 147 | NameError: name 'tuple1' is not defined 148 | ''' 149 | #Python Tuple inbuilt functions 150 | ''' 151 | SN Function Description 152 | 1 cmp(tuple1, tuple2) It compares two tuples and returns true 153 | if tuple1 is greater than tuple2 otherwise false. 154 | 2 len(tuple) It calculates the length of the tuple. 155 | 3 max(tuple) It returns the maximum element of the tuple 156 | 4 min(tuple) It returns the minimum element of the tuple. 157 | 5 tuple(seq) It converts the specified sequence to the tuple. 158 | ''' 159 | 160 | #Where use tuple? 161 | ''' 162 | 1. Using tuple instead of list gives us a clear idea that tuple data 163 | is constant and must not be changed. 164 | 2. Tuple can simulate a dictionary without keys. Consider the following 165 | nested structure, which can be used as a dictionary. 166 | [(101, "John", 22), (102, "Mike", 28), (103, "Dustin", 30)] 167 | ''' 168 | # Tuples may be nested: 169 | v: Tuple[List[int], List[int]] = ([1, 2, 3], [3, 2, 1]) 170 | u: Tuple[Tuple[List[int], List[int]], Tuple[int, int, int, int, int]] = v, (1, 2, 3, 4, 5) 171 | 172 | print(u) 173 | 174 | 175 | -------------------------------------------------------------------------------- /06_Class(Set_Dict)/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/06_Class(Set_Dict)/main.py -------------------------------------------------------------------------------- /07_Class_(Function)/Readme.md: -------------------------------------------------------------------------------- 1 | # Python Functions Overview 2 | 3 | Python functions are fundamental components of the language, enhancing code organization and enabling code reuse. 4 | 5 | ## Table of Contents 6 | 7 | - [Predefined Functions](#predefined-functions) 8 | - [User-defined Functions](#user-defined-functions) 9 | - [Handling Arguments and Parameters](#handling-arguments-and-parameters) 10 | - [Default Function Parameters](#default-function-parameters) 11 | - [Varied Argument Types](#varied-argument-types) 12 | - [Lambda Functions](#lambda-functions) 13 | - [Recursive Functions](#recursive-functions) 14 | - [Decorators](#decorators) 15 | - [Handling Unlimited Arguments](#handling-unlimited-arguments) 16 | 17 | ## Predefined Functions 18 | 19 | Python offers a diverse range of built-in functions, such as `len()`, readily available for immediate use without requiring additional imports. 20 | 21 | ## User-defined Functions 22 | 23 | Users have the ability to define their own functions using the `def` keyword, facilitating tailored functionality to suit specific requirements. 24 | 25 | ## Handling Arguments and Parameters 26 | 27 | Functions can receive inputs in the form of arguments, defined within the function signature as parameters. 28 | 29 | ## Default Function Parameters 30 | 31 | Parameters can possess default values, granting them an optional status when the function is invoked. 32 | 33 | ## Varied Argument Types 34 | 35 | Functions accommodate different argument types, including optional arguments with predefined defaults, positional arguments reliant on their order, and keyword arguments specified by name. 36 | 37 | ## Lambda Functions 38 | 39 | Python allows the creation of anonymous functions using the `lambda` keyword for on-the-fly functionality definition. 40 | 41 | ## Recursive Functions 42 | 43 | Functions can call themselves, enabling the resolution of problems in a recursive manner. 44 | 45 | ## Decorators 46 | 47 | Functions can be wrapped by other functions to extend their behavior seamlessly, without direct modification of their core code. 48 | 49 | ## Handling Unlimited Arguments 50 | 51 | Functions can be designed to accept an indefinite number of arguments, either as positional or keyword arguments. 52 | 53 | Understanding and proficiently utilizing these diverse features of Python functions empowers developers to craft cleaner, more efficient, and maintainable code. 54 | 55 | 56 | 57 | ## Table of Contents 58 | 1. [Pre-defined Functions](#pre-defined-functions) 59 | 2. [User-defined Functions](#user-defined-functions) 60 | 3. [Arguments and Parameters](#arguments-and-parameters) 61 | 4. [Default Functions](#default-functions) 62 | 5. [Optional, Positional, and Keyword Arguments](#optional-positional-and-keyword-arguments) 63 | 6. [Lambda Functions](#lambda-functions) 64 | 7. [Recursive Functions](#recursive-functions) 65 | 8. [Decorators](#decorators) 66 | 9. [Functions with Unlimited Arguments](#functions-with-unlimited-arguments) 67 | 68 | --- 69 | 70 | ## Pre-defined Functions 71 | 72 | Python provides several built-in functions that are readily available for use. 73 | 74 | ```python 75 | # Example of a pre-defined function 76 | result: int = len("Hello, World!") 77 | print(result) # Output: 12 78 | ``` 79 | 80 | --- 81 | 82 | ## User-defined Functions 83 | 84 | You can define your own functions in Python using the `def` keyword. 85 | 86 | ```python 87 | def greet(name: str) -> None: 88 | print(f"Hello, {name}!") 89 | 90 | greet("John") # Output: Hello, John! 91 | ``` 92 | 93 | --- 94 | 95 | ## Arguments and Parameters 96 | 97 | Parameters are the variables listed inside the parentheses in the function definition, whereas arguments are the values passed to the function when it is called. 98 | 99 | ```python 100 | def add(a: int, b: int) -> int: 101 | return a + b 102 | 103 | result: int = add(5, 3) 104 | print(result) # Output: 8 105 | ``` 106 | 107 | --- 108 | 109 | ## Default Functions 110 | 111 | You can assign default values to parameters, making them optional during a function call. 112 | 113 | ```python 114 | def power(base: int, exponent: int = 2) -> int: 115 | return base ** exponent 116 | 117 | print(power(3)) # Output: 9 118 | print(power(3, 3)) # Output: 27 119 | ``` 120 | 121 | --- 122 | 123 | ## Optional, Positional, and Keyword Arguments 124 | 125 | ### Optional Arguments 126 | Optional arguments are those that have a default value. 127 | 128 | ```python 129 | def greet(name: str = "Guest") -> None: 130 | print(f"Hello, {name}!") 131 | 132 | greet() # Output: Hello, Guest! 133 | greet("John") # Output: Hello, John! 134 | ``` 135 | 136 | ### Positional Arguments 137 | Positional arguments are arguments that need to be included in the proper position or order. 138 | 139 | ```python 140 | def subtract(a: int, b: int) -> int: 141 | return a - b 142 | 143 | result: int = subtract(10, 5) 144 | print(result) # Output: 5 145 | ``` 146 | 147 | ### Keyword Arguments 148 | Keyword arguments are arguments passed to a function by explicitly specifying the name of the parameter. 149 | 150 | ```python 151 | def divide(dividend: int, divisor: int) -> float: 152 | return dividend / divisor 153 | 154 | result: float = divide(divisor=5, dividend=25) 155 | print(result) # Output: 5.0 156 | ``` 157 | 158 | --- 159 | 160 | ## Lambda Functions 161 | 162 | Lambda functions are anonymous functions defined using the `lambda` keyword. 163 | 164 | ```python 165 | square: callable = lambda x: x * x 166 | print(square(4)) # Output: 16 167 | ``` 168 | 169 | --- 170 | 171 | ## Recursive Functions 172 | 173 | A recursive function is a function that calls itself. 174 | 175 | ```python 176 | def factorial(n: int) -> int: 177 | if n == 0: 178 | return 1 179 | else: 180 | return n * factorial(n - 1) 181 | 182 | result: int = factorial(5) 183 | print(result) # Output: 120 184 | ``` 185 | 186 | --- 187 | 188 | ## Decorators 189 | 190 | Decorators are a way to modify or extend the behavior of a function. 191 | 192 | ```python 193 | def my_decorator(func: callable) -> callable: 194 | def wrapper(*args, **kwargs) -> None: 195 | print("Something is happening before the function is called.") 196 | func(*args, **kwargs) 197 | print("Something is happening after the function is called.") 198 | return wrapper 199 | 200 | @my_decorator 201 | def say_hello(name: str) -> None: 202 | print(f"Hello {name}!") 203 | 204 | say_hello("John") 205 | ``` 206 | 207 | --- 208 | 209 | ## Functions with Unlimited Arguments 210 | 211 | You can define functions that accept an arbitrary number of arguments. 212 | 213 | ### Unlimited Positional Arguments 214 | 215 | ```python 216 | def add(*numbers: int) -> int: 217 | return sum(numbers) 218 | 219 | result: int = add(1, 2, 3, 4, 5) 220 | print(result) # Output: 15 221 | ``` 222 | 223 | ### Unlimited Keyword Arguments 224 | 225 | ```python 226 | def print_key_values(**kwargs: str) -> None: 227 | for key, value in kwargs.items(): 228 | print(f"{key}: {value}") 229 | 230 | print_key_values(name="John", age="30", country="USA") 231 | ``` -------------------------------------------------------------------------------- /08_class(Module & packages)/Package.py: -------------------------------------------------------------------------------- 1 | #PACKAGE: 2 | #A package can have one or more modules which means, a package is collection of modules and packages. 3 | # A package can contain packages. 4 | # Package is nothing but a Directory/Folder 5 | # It MUST contain a special file called __init__.py. 6 | # __init__.py file can be empty, it indicates that the directory it contains is a Python package, so it can be imported the same way a module can be imported. 7 | 8 | 9 | # Syntax:- import packageName.moduleName 10 | # Syntax:- import packageName.subPackageName.moduleName 11 | 12 | 13 | # How to Access Variable, Function, Method, Class etc. ? 14 | 15 | # Syntax:- packageName.moduleName.functionName() 16 | # Syntax:- packageName.subPackageName.moduleName.functionName() 17 | 18 | # Syntax:- from packageName import moduleName 19 | # Syntax:- from packageName.subPackageName import moduleName 20 | 21 | 22 | # if a package’s __init__.py code defines a list named __all__, it is taken to be the list of module names that should be imported when from package import * is encountered. 23 | # __all__ = [] 24 | -------------------------------------------------------------------------------- /08_class(Module & packages)/module.py: -------------------------------------------------------------------------------- 1 | # MODULE: 2 | # In Python we are able to write a long program and save as a module. 3 | # This is known as creating a script. We are able to import modules 4 | # across modulesand into the Python interpreter. This negates the 5 | # need to keep repeating ourselves. 6 | # DRY!....Don't repeat yourself 7 | # ''' 8 | # import ModuleExample 9 | # ModuleExample.add(4,5.5) 10 | 11 | # #We can import a module by renaming it as follows: 12 | # # import module by renaming it 13 | 14 | # import ModuleExample as m 15 | # print("The addition is ",m.add(4,5.5)) 16 | 17 | # #Python import statement 18 | # # import statement example 19 | # # to import standard module math 20 | # import math 21 | # print("The value of pi is", math.pi) 22 | 23 | # #Python from...import statement 24 | # # import only pi from math module 25 | # from math import pi 26 | # print("The value of pi is", pi) 27 | 28 | # Example: 29 | 30 | # Python/cal.py 31 | 32 | def square(myList:list) -> list: 33 | return [i**2 for i in myList] 34 | 35 | 36 | def info(**what:dict)->None: 37 | for key, value in what.items(): 38 | print(f"{key} is {value}") 39 | 40 | def add(a : int, b: int) ->int: 41 | return a+b 42 | 43 | # Python/error.py 44 | def zeroError(a : int) -> str: 45 | if (a == 0): 46 | raise "Zero Division Error" 47 | else: 48 | return "You nailed it!" 49 | 50 | # Python/msg.py 51 | 52 | message : str = """ 53 | Welcome to Our 54 | Python Programming 55 | World 56 | Python is not For Innocent People 57 | """ 58 | line : str = "THANK YOU" 59 | 60 | # Python/main.py 61 | 62 | from msg import message as M, line as L 63 | from cal import square as s, add as a, info as i 64 | from error import zeroError as e 65 | print(L) 66 | print(M) 67 | print(L) 68 | lt : list = s([1,2,3,4,5,6]) 69 | add : int = a(10,5) 70 | dt : dict = i(name="Umer", age = 16) 71 | print(lt) 72 | print(L) 73 | print(dt) 74 | print(L) 75 | print(add) 76 | print(L) 77 | print(e(0)) 78 | print(L) 79 | 80 | print("-------------------------------------------------------") 81 | 82 | -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/Admin/Tech/logout.py: -------------------------------------------------------------------------------- 1 | a : str =""" 2 | to all 3 | 4 | """ -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/Admin/Tech/product.py: -------------------------------------------------------------------------------- 1 | b : str =""" 2 | come 3 | """ -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/Admin/Tech/profile.py: -------------------------------------------------------------------------------- 1 | c : str =""" 2 | Well 3 | 4 | """ -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/Admin/_init_.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/08_class(Module & packages)/sms/Admin/_init_.py -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/Hashim.py: -------------------------------------------------------------------------------- 1 | from Admin.Tech import profile 2 | print(profile.c) 3 | g : str =""" 4 | Welcome to new world 5 | """ -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/User/_init_.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/08_class(Module & packages)/sms/User/_init_.py -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/User/logout.py: -------------------------------------------------------------------------------- 1 | d : str =""" 2 | Well come to all 3 | hello 4 | """ -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/User/profile.py: -------------------------------------------------------------------------------- 1 | e : str =""" 2 | Python is not for innocent people 3 | """ -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/User/request.py: -------------------------------------------------------------------------------- 1 | f : str =""" 2 | Well come to all 3 | hello 4 | """ -------------------------------------------------------------------------------- /08_class(Module & packages)/sms/_init_.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/08_class(Module & packages)/sms/_init_.py -------------------------------------------------------------------------------- /09 _class__Exceptional Handling/README.md: -------------------------------------------------------------------------------- 1 | # Exceptional-Handling And File_Handling 2 | 3 | ## Exception Handling: 4 | In Python is a way to deal with errors that might occur during the execution of a program. It allows you to gracefully manage unexpected situations that could cause your program to crash. The `try`, `except`, `finally`, and `raise` keywords are used to implement exception handling in Python. 5 | 6 | Here's a basic example: 7 | 8 | ```python 9 | def divide_numbers() -> None: 10 | try: 11 | # Code block where an exception might occur 12 | result: float = 10 / 0 # This will raise a ZeroDivisionError 13 | except ZeroDivisionError as e: 14 | # Handle the specific exception 15 | print("Error:", e) 16 | else: 17 | # This block is executed if no exception is raised in the try block 18 | print("No errors occurred.") 19 | finally: 20 | # This block is always executed, regardless of whether an exception occurred 21 | print("Execution complete.") 22 | 23 | # Example usage 24 | divide_numbers() 25 | 26 | ``` 27 | 28 | In this example: 29 | - The code inside the `try` block is executed. 30 | - If an exception of type `ZeroDivisionError` occurs, it's caught in the `except` block, and a message is printed. 31 | - If no exception occurs, the `else` block is executed. 32 | - Finally, the `finally` block is executed whether an exception occurred or not. It's commonly used for cleanup tasks. 33 | 34 | You can also create custom exceptions using the `raise` statement: 35 | 36 | ```python 37 | def validate_age(age: int) -> None: 38 | if age < 0 or age > 120: 39 | raise ValueError("Invalid age!") 40 | else: 41 | print("Age is valid.") 42 | 43 | try: 44 | validate_age(150) # This will raise a ValueError 45 | except ValueError as e: 46 | print("Error:", e) 47 | 48 | ``` 49 | 50 | This code defines a function `validate_age` that raises a `ValueError` if the age is not within a certain range. 51 | 52 | Remember, handling exceptions is important for writing robust code, but it's also crucial to handle them appropriately based on the context and potential errors that might arise. 53 | 54 | ## Types Of Error: 55 | In Python, errors can be categorized into three main types: 56 | 57 | ### Syntax Errors: 58 | These occur when the code doesn't follow the correct syntax of the Python language. It's often detected by the interpreter when the code is being compiled. For example, missing colons, incorrect indentation, or using an invalid keyword. 59 | 60 | ### Runtime Errors (Exceptions): 61 | These occur during the execution of the program. They can happen due to various reasons such as division by zero, trying to access an undefined variable, or attempting to open a file that doesn't exist. 62 | 63 | ### Semantic Errors (Logical Errors): 64 | These errors don’t cause the program to crash, but they lead to incorrect behavior. The code runs without throwing an error, but it doesn’t produce the expected output due to faulty logic or incorrect algorithms. These errors can be the trickiest to identify since they don’t generate error messages. 65 | 66 | Python provides a wide range of built-in exceptions that cover various types of errors. Some common built-in exceptions include SyntaxError, TypeError, NameError, ValueError, ZeroDivisionError, FileNotFoundError, and more. You can handle these exceptions using try-except blocks to gracefully manage errors and prevent the program from crashing. 67 | 68 | File handling in Python involves working with files: creating, reading, writing, and manipulating their contents. Python provides built-in functions and methods to perform these operations. 69 | 70 | ### Opening a File 71 | You can open a file using the open() function, specifying the file path and the mode ('r' for reading, 'w' for writing, 'a' for appending, and more). 72 | 73 | 74 | ### Open a file for reading 75 | ```python 76 | file = open('filename.txt', 'r') 77 | ``` 78 | 79 | ### Open a file for writing 80 | ```python 81 | file = open('filename.txt', 'w') 82 | ``` 83 | 84 | ### Open a file for appending 85 | ```python 86 | file = open('filename.txt', 'a') 87 | ``` 88 | Reading from a File 89 | To read the contents of a file, you can use various methods like read(), readline(), or readlines(). 90 | 91 | 92 | ### Read the entire file 93 | ```python 94 | content = file.read() 95 | ``` 96 | 97 | ### Read one line at a time 98 | ```python 99 | line = file.readline() 100 | ``` 101 | 102 | ### Read all lines into a list 103 | ```python 104 | lines = file.readlines() 105 | ``` 106 | ### Writing to a File 107 | To write content to a file, use the write() method. Remember to open the file in write or append mode. 108 | ```python 109 | 110 | file.write("This is some text.") 111 | ``` 112 | 113 | # To write multiple lines 114 | ```python 115 | lines = ["Line 1\n", "Line 2\n", "Line 3\n"] 116 | file.writelines(lines) 117 | ``` 118 | ### Closing a File 119 | After performing operations on a file, it's essential to close it using the close() method. 120 | ```python 121 | file.close() 122 | ``` 123 | Using 'with' Statement (Context Manager) 124 | A cleaner way to handle files is by using the with statement. It automatically closes the file once the block is exited. 125 | ```python 126 | with open('filename.txt', 'r') as file: 127 | content = file.read() 128 | ``` 129 | 130 | ### File automatically closed outside the block 131 | Error Handling 132 | Handle file-related errors using try and except blocks to ensure graceful handling of exceptions. 133 | 134 | ```python 135 | from typing import TextIO 136 | 137 | def read_file_content(file: TextIO[str]) -> str: 138 | return file.read() 139 | 140 | try: 141 | with open('filename.txt', 'r') as file: 142 | content = read_file_content(file) 143 | # Perform operations on the content 144 | except FileNotFoundError: 145 | print("File not found.") 146 | except IOError: 147 | print("Error reading the file.") 148 | except Exception as e: 149 | print("An unexpected error occurred:", e) 150 | 151 | ``` 152 | Remember to handle file paths carefully and be cautious while performing write operations as they can overwrite existing content. 153 | -------------------------------------------------------------------------------- /1-Numbers.py: -------------------------------------------------------------------------------- 1 | #Using python as a calculator 2 | 3 | ''' 4 | We can use the interpreter to take an input and return an output! 5 | 6 | Arithmetic Operators: 7 | We have a whole bunch of opperators at our disposal 8 | + Addition 9 | - Subtraction 10 | * Multiplication 11 | / Division 12 | // Floor division 13 | % Modulus (remainder of x / y) | use divmod(a, b) 14 | ** Exponentiation (power of) | can also use pow(x , y) instead of x**y 15 | 16 | Assignment Opperators: 17 | = Equals 18 | 19 | Number Types: 20 | int (2, 3, 458, 678) 21 | float (2.2, 3.5, 5.666675678) 22 | 23 | Build in Function: 24 | round() Rounds a numbers with the specified number of 25 | decimals i.e. round(number, decimals) 26 | lastly, Python has a handy way of making big int's easier to read 27 | 4000000000 can be written as 28 | 4_000_000_000 29 | ''' 30 | 31 | # In this example, static type hints are provided for integer, float, and complex variables. The code also demonstrates basic arithmetic 32 | # operations, working with sequences (a list of integers), iterating over the list, and generating a random number. Remember that these type 33 | # hints are optional and for documentation purposes, but they can be used by static analysis tools 34 | 35 | 36 | #The basics 37 | 5 + 2 # simple addition 38 | 8 - 2 # simple subtraction 39 | 5 * 10 # simple multiplication 40 | 41 | #Division and Modulus 42 | 12 / 3 # classic division returns a float 43 | 15 // 4 # floor division discards the fractional part 44 | 15 % 4 # the % operator returns the remainder of the division.. 45 | round(15,4) 46 | 47 | #Fancy sums 48 | 50 - 5*6 49 | (50 - 5*6) / 4 50 | 5 * 3 + 2 # floored quotient * divisor + remainder.. 51 | 52 | #Exponentiation (power of) 53 | 10 ** 2 # 5 squared 54 | 5 ** 7 # 2 to the power of 7 55 | pow(5,7) 56 | 57 | #Using variables 58 | width : int = 60 59 | height : int = 3 * 7 60 | width * height 61 | 62 | #In interactive mode, the last printed expression is assigned to the variable _. 63 | tax = 12.5 / 100 64 | price = 100.50 65 | price * tax #this is assigned to '_' and we use it in the next expression 66 | price + _ #We reference '_' but this expression is now assigned to '_' 67 | round(_, 2) 68 | 69 | 70 | num1: int = 42 71 | 72 | # Example 2: Float 73 | num2: float = 3.14 74 | 75 | # Example 3: Complex 76 | num3: complex = 2 + 3j 77 | 78 | # Example 4: Integer 79 | count: int = 100 80 | 81 | # Example 5: Float 82 | pi: float = 3.14159 83 | 84 | # Example 6: Complex 85 | imaginary_number: complex = 1j 86 | 87 | # Example 7: Integer 88 | quantity: int = 25 89 | 90 | # Example 8: Float 91 | price: float = 49.99 92 | 93 | 94 | 95 | # Example 2: Arithmetic operations with floats 96 | float1: float = 3.14 97 | float2: float = 2.5 98 | result_division: float = float1 / float2 99 | result_power: float = float1 ** 2 100 | 101 | # Example 3: Using numbers in sequences (list of integers) 102 | numbers_list: List[int] = [1, 2, 3, 4, 5] 103 | sum_of_numbers: int = sum(numbers_list) 104 | 105 | # Example 4: Iterating over a range of integers 106 | for i in range(5): 107 | print(f"Index: {i}") 108 | 109 | # Example 5: Indexing a string (sequence of characters) 110 | word: str = "Python" 111 | first_char: str = word[0] 112 | 113 | # Example 6: Random number generation 114 | import random 115 | random_number: int = random.randint(1, 100) 116 | 117 | # Example 7: Mathematical functions with the math module 118 | import math 119 | square_root: float = math.sqrt(25) 120 | sin_value: float = math.sin(math.radians(30)) 121 | 122 | -------------------------------------------------------------------------------- /10-ForLoop.py: -------------------------------------------------------------------------------- 1 | #Python "for" Loops (Definite Iteration) 2 | 3 | ''' 4 | for (int i=0;i<=10;i++) 5 | { 6 | print(i) 7 | } 8 | 0 9 | 1 10 | 2 11 | 3 12 | 4 13 | 5 14 | 6 15 | 7 16 | 8 17 | 9 18 | 10 19 | 11<=10 condition false 20 | break 21 | ''' 22 | ''' 23 | for item in sequence: 24 | execute expression 25 | 26 | 1.for starts a for loop. 27 | 2.item is an individual item during each iteration. 28 | It is given a temporary arbitary variable name. 29 | 3.in separates each item from the other(s). 30 | 4.sequence is what we want to iterate over. 31 | 5.a colon : gives the instruction to execute the body of code 32 | that follows. 33 | 6.A level of indentation. 4 spaces before writing the body of 34 | the loop, otherwise we get an IndentationError. 35 | ''' 36 | str = "Hashim" 37 | for i in str: 38 | print(i) 39 | ''' 40 | str = "Hashim" 41 | +---+---+---+---+---+---+ 42 | | H | a | s | h | i | m | 43 | +---+---+---+---+---+---+ 44 | 0 1 2 3 4 5 45 | 46 | i=0 => str[0]=H 47 | H 48 | i=1 => str[1]=a 49 | a 50 | ''' 51 | names = ['Hashim', 'Farooq', 'Hamza', 'Usman', 'Madiha'] 52 | for i in names: 53 | print(i) 54 | 55 | for i in range(len(names)): 56 | print(i,names[i],len(names[i])) 57 | 58 | #...remember range(start, stop, step) 59 | range(10) 60 | list(range(5, 10)) 61 | list(range(0, 10, 3)) 62 | list(range(-10, -100, -30)) 63 | 64 | for i in range(1,10): 65 | print(i) 66 | 67 | #Even 68 | for i in range(2,100,2): 69 | print(i) 70 | 71 | for i in range(1,10): 72 | print("*",end=' ') 73 | 74 | ##Nested Loops 75 | ''' 76 | * 77 | * * 78 | * * * 79 | * * * * 80 | * * * * * 81 | ''' 82 | rows = int(input("Enter number of rows: ")) 83 | for i in range(rows): 84 | for j in range(i+1): 85 | print("* ", end="") 86 | print("\n") 87 | 88 | ''' 89 | rows = 5 90 | step 1 for outer loop 91 | i=0 i<=5 92 | i=0 range(i+1)=> range(1) => range(0,1) 93 | 94 | Step 2 for outer loop 95 | i=1 range(1+1) => range(2) => range(0,2) 96 | step 1.1 97 | ''' 98 | ''' 99 | * 100 | ** 101 | *** 102 | **** 103 | **** 104 | ''' 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /11-WhileLoop.py: -------------------------------------------------------------------------------- 1 | #Python While Loop 2 | ''' 3 | i=1 4 | while(i<15) 5 | { 6 | statements 7 | } 8 | 1,2,3,4,5 9 | 1+4+9+16+25=55 10 | ''' 11 | #Example 12 | n=5 13 | s=1 14 | summation=0 15 | while s<=n: 16 | summation = summation + s**2 17 | s+=1 18 | print("The sum of squares is", summation) 19 | 20 | #Multiplication Table using While Loop 21 | num = 5 22 | counter = 1 23 | # we will use a while loop for iterating 10 times for the 24 | # multiplication table 25 | print("The Multiplication Table of: ", num) 26 | while counter <= 10: # specifying the condition 27 | ans = num * counter 28 | print (num, 'x', counter, '=', ans) 29 | counter += 1 # expression to increment the counter 30 | 31 | #Python While Loop Multiple Conditions 32 | num1 = 17 33 | num2 = -12 34 | 35 | while num1 > 5 and num2 < -5 : # multiple conditions in a single while loop 36 | num1 -= 2 37 | num2 += 3 38 | print( (num1, num2) ) 39 | 40 | #Multiple conditions with an OR operator 41 | num1 = 17 42 | num2 = -12 43 | 44 | while num1 > 5 or num2 < -5 : 45 | num1 -= 2 46 | num2 += 3 47 | print( (num1, num2) ) 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Introduction to Python Graphic/import.PY: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | pen = Turtle() 4 | 5 | pen.forward(100) 6 | pen.right(90) 7 | pen.forward(50) 8 | pen.right(90) 9 | pen.forward(100) 10 | pen.right(90) 11 | pen.forward(50) 12 | 13 | done() -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Introduction to Python Graphic/readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # WellCome to Python Graphic Designing Module 4 | 5 | 6 | The Python turtle module is a fantastic tool for beginners and experienced programmers alike to explore the world of graphics and animation. To navigate your learning journey effectively, here's a possible roadmap for exploring its modules: 7 | 8 | ## What it is: 9 | 10 | - A built-in Python library for creating simple graphics and animations. 11 | - Inspired by Logo, a programming language designed for education. 12 | - Offers a fun, interactive way to learn programming concepts, especially for beginners. 13 | - Based on the metaphor of a turtle: a virtual pen that moves around a screen, drawing lines as it goes. 14 | 15 | ## How it works: 16 | 17 | ### 1.Import the turtle module: 18 | 19 | ```python 20 | 21 | import turtle 22 | 23 | ``` 24 | 25 | ### 2.Create a turtle object: 26 | 27 | ```Python 28 | 29 | pen = turtle.Turtle() 30 | 31 | ``` 32 | ### 3.Issue commands to move the turtle: 33 | 34 | - Forward: pen.forward(100) ➡️ Moves 100 pixels forward. 35 | - Backward: pen.backward(50) ⬅️ Moves 50 pixels backward. 36 | - Right: pen.right(90) ↻ Turns 90 degrees clockwise. 37 | - Left: pen.left(45) ↺ Turns 45 degrees counterclockwise. 38 | - Pen up: pen.penup() ⏫ Lifts the pen, no drawing. 39 | - Pen down: pen.pendown() ⏬ Puts the pen down, starts drawing. 40 | 41 | ### 4.Customize drawings: 42 | 43 | - Colors: pen.color("red") 44 | - Shapes: pen.circle(50), pen.square(40) 45 | - Filling: pen.begin_fill(), pen.end_fill() 46 | 47 | ### Example code and output: 48 | 49 | ```python 50 | 51 | from turtle import * 52 | 53 | pen = Turtle() 54 | 55 | pen.forward(100) 56 | pen.right(90) 57 | pen.forward(50) 58 | pen.right(90) 59 | pen.forward(100) 60 | pen.right(90) 61 | pen.forward(50) 62 | 63 | done() 64 | 65 | ``` 66 | 67 | ### Output: 68 | 69 | ```python 70 | 71 | See output in your Python Environment. 72 | 73 | ``` 74 | 75 | ### Key benefits of Python Turtle Graphics: 76 | 77 | - Beginner-friendly: Easy to grasp concepts and create visual results. 78 | - Interactive: Immediate feedback encourages experimentation. 79 | - Versatile: Can create various shapes, patterns, and animations. 80 | - Educational: Builds problem-solving and computational thinking skills. 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Programming with turtle/Python Graphics for Biggners/Class01.py: -------------------------------------------------------------------------------- 1 | # type turtle module 2 | 3 | from turtle import * 4 | 5 | # ------------------------------------------ 6 | 7 | # Drawing a shap 8 | 9 | # right(90) 10 | # forward(100) 11 | # left(90) 12 | # backward(100) 13 | # ----------------- 14 | # Square 15 | 16 | # fd(100) 17 | # rt(90) 18 | # fd(100) 19 | # rt(90) 20 | # fd(100) 21 | # rt(90) 22 | # fd(100) 23 | # ----------------- 24 | # Circle 25 | 26 | # pen = Turtle() 27 | # pen.circle(50) 28 | #done() 29 | # ----------------- 30 | # Triangle 31 | 32 | # t = Turtle() 33 | # for i in range(3): 34 | # fd(100) # Move forward 100 pixels 35 | # lt(120) 36 | 37 | # ------------------------------------------ 38 | 39 | # Changing the Screen Color 40 | 41 | # bgcolor("purple") 42 | 43 | # ------------------------------------------ 44 | 45 | # Changing the Screen Title 46 | 47 | # title("Turtle in the Sunshine Meadow") 48 | 49 | # ------------------------------------------ 50 | 51 | # Changing the turtle Size 52 | 53 | # shapesize(1,5,10) 54 | # shapesize(10,5,1) 55 | # shapesize(1,10,5) 56 | # shapesize(10,1,5) 57 | 58 | # ------------------------------------------ 59 | 60 | # Changing the Pen Size 61 | 62 | # pensize(5) 63 | 64 | # # Draw the square 65 | # forward(100) 66 | # right(90) 67 | # forward(100) 68 | # right(90) 69 | # forward(100) 70 | # right(90) 71 | # forward(100) 72 | 73 | # ------------------------------------------ 74 | 75 | # Changing the Turtle and Pen Color 76 | 77 | # pencolor("green") 78 | 79 | color("yellow") 80 | 81 | # ------------------------------------------ 82 | 83 | # Filling the Image 84 | 85 | 86 | # fillcolor("blue") 87 | 88 | # # Begin filling 89 | # begin_fill() 90 | 91 | # # Draw the square 92 | # forward(100) 93 | # right(90) 94 | # forward(100) 95 | # right(90) 96 | # forward(100) 97 | # right(90) 98 | # forward(100) 99 | 100 | # # End filling 101 | # end_fill() 102 | 103 | 104 | # ------------------------------------------ 105 | 106 | # Changing the Turtle Shape 107 | 108 | # register_shape("star", "star.gif") 109 | # shape("star") 110 | # forward(100) 111 | 112 | # ------------------------------------------ 113 | 114 | # Changing the Pen Speed 115 | 116 | # # Set slow speed 117 | # speed(3) 118 | 119 | # # Draw slowly 120 | # forward(100) 121 | 122 | # # Set fast speed 123 | # speed(8) 124 | 125 | # # Draw quickly 126 | # circle(50) 127 | 128 | # ------------------------------------------ 129 | 130 | # Customizing in One Line 131 | 132 | # pen(pencolor="purple", fillcolor="orange", pensize=10, speed=9) 133 | # begin_fill() 134 | # circle(90) 135 | # end_fill() 136 | # ------------------------------------------ 137 | 138 | # Picking the Pen Up and Down 139 | 140 | # fd(100) 141 | # rt(90) 142 | # penup() 143 | # fd(100) 144 | # rt(90) 145 | # pendown() 146 | # fd(100) 147 | # rt(90) 148 | # penup() 149 | # fd(100) 150 | # pendown() 151 | 152 | # ------------------------------------------ 153 | 154 | # Undoing Change 155 | 156 | # undo() 157 | 158 | # ------------------------------------------ 159 | 160 | # Clearing the Screen 161 | 162 | # clear() 163 | 164 | # ------------------------------------------ 165 | 166 | # Resetting the Environment 167 | 168 | # reset() 169 | 170 | # ------------------------------------------ 171 | 172 | # Leaving a Stamp 173 | # stamp() 174 | 175 | # fd(100) 176 | # stamp() 177 | 178 | # fd(100) 179 | # ------------------------------------------ 180 | 181 | # Clonning your Turtle 182 | 183 | # c = clone() 184 | # color("magenta") 185 | # c.color("red") 186 | # circle(100) 187 | # c.circle(60) 188 | 189 | # ------------------------------------------ 190 | 191 | done() 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Programming with turtle/Python Graphics for Biggners/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/11_Class(Python Graphics)/Programming with turtle/Python Graphics for Biggners/image-1.png -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Programming with turtle/Python Graphics for Biggners/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/11_Class(Python Graphics)/Programming with turtle/Python Graphics for Biggners/image.png -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class01(Make a Spiral Circle)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | # Import the turtle library for 4 | # drawing the required curve 5 | from turtle import * 6 | 7 | # Set the background color as black, 8 | # pensize as 2 and speed of drawing 9 | # curve as 10(relative) 10 | Screen().bgcolor('black') 11 | pensize(2) 12 | speed(10) 13 | 14 | # Iterate six times in total 15 | for i in range(6): 16 | 17 | # Choose your color combination 18 | for color in ('red', 'magenta', 'blue', 19 | 'cyan', 'green', 'white', 20 | 'yellow'): 21 | color(color) 22 | 23 | # Draw a circle of chosen size, 100 here 24 | circle(100) 25 | 26 | # Move 10 pixels left to draw another circle 27 | left(10) 28 | 29 | # Hide the cursor(or turtle) which drew the circle 30 | hideturtle() 31 | done() 32 | ``` 33 | 34 | # Explaination: 35 | 36 | Here's a breakdown of the code's details: 37 | 38 | ## 1. Import Turtle Module: 39 | 40 | - from turtle import *: Imports the turtle graphics library, providing tools to create visual elements and animations. 41 | ## 2. Set Drawing Environment: 42 | 43 | - Screen().bgcolor('black'): Sets the background color of the drawing screen to black. 44 | - pensize(2): Sets the thickness of the lines drawn by the turtle to 2 pixels. 45 | - speed(10): Adjusts the drawing speed of the turtle to a relatively fast pace (10). 46 | ##3. Main Loop for Multiple Circles: 47 | 48 | - for i in range(6):: Iterates the code block six times, creating a total of six sets of circles. 49 | ## 4. Color Loop for Each Set: 50 | 51 | - for color in ('red', 'magenta', 'blue', 'cyan', 'green', 'white', 'yellow'):: Iterates through a list of colors, drawing a circle in each color. 52 | ##5. Drawing Circles: 53 | 54 | - color(color): Sets the current drawing color to the color specified in the loop. 55 | - circle(100): Draws a circle with a radius of 100 pixels. 56 | - left(10): Rotates the turtle 10 degrees counterclockwise, positioning it for the next circle. 57 | ## 6. Hide Turtle: 58 | 59 | - hideturtle(): Hides the turtle from the screen, leaving only the drawn circles visible. 60 | ## 7. Keep Window Open: 61 | 62 | - done(): Holds the turtle graphics window open until it's manually closed. 63 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class01(Make a Spiral Circle)/spiralcircle.py: -------------------------------------------------------------------------------- 1 | # Import the turtle library for 2 | # drawing the required curve 3 | from turtle import * 4 | 5 | # Set the background color as black, 6 | # pensize as 2 and speed of drawing 7 | # curve as 10(relative) 8 | Screen().bgcolor('black') 9 | pensize(2) 10 | speed(10) 11 | 12 | # Iterate six times in total 13 | for i in range(6): 14 | 15 | # Choose your color combination 16 | for color in ('red', 'magenta', 'blue', 17 | 'cyan', 'green', 'white', 18 | 'yellow'): 19 | color(color) 20 | 21 | # Draw a circle of chosen size, 100 here 22 | circle(100) 23 | 24 | # Move 10 pixels left to draw another circle 25 | left(10) 26 | 27 | # Hide the cursor(or turtle) which drew the circle 28 | hideturtle() 29 | done() 30 | 31 | 32 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class02(Make a Rainbow Spiral)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | 4 | import turtle 5 | from turtle import * 6 | 7 | turtle.title("rainbow spiral") 8 | speed(15) 9 | bgcolor("black") 10 | r,g,b=255,0,0 11 | 12 | for i in range(255*2): 13 | colormode(255) 14 | if i<255//3: 15 | g+=3 16 | elif i<255*2//3: 17 | r-=3 18 | elif i<255: 19 | b+=3 20 | elif i<255*4//3: 21 | g-=3 22 | elif i<255*5//3: 23 | r+=3 24 | else: 25 | b-=3 26 | fd(50+i) 27 | rt(91) 28 | pencolor(r,g,b) 29 | 30 | ``` 31 | 32 | # Explaination: 33 | 34 | ## 1. Import and Setup: 35 | 36 | - Imports the turtle module: Enables creation of graphics. 37 | - Sets window title: "rainbow spiral". 38 | - Sets drawing speed: 15 (relatively fast). 39 | - Sets background color: Black. 40 | - Initializes color variables (r, g, b): Starts with red (255, 0, 0). 41 | ## 2. Color Loop: 42 | 43 | - Iterates 255*2 times: Creates a long spiral. 44 | - Sets color mode: 255 (allows RGB values from 0-255). 45 | - Conditionally adjusts color values: 46 | - Increases green for the first 255/3 iterations. 47 | - Decreases red for the next 255/3 iterations. 48 | - Increases blue for the next 255 iterations. 49 | - Decreases green, increases red, decreases blue for the remaining iterations. 50 | - Moves turtle forward: Creates a spiral shape. 51 | - Rotates turtle right: Creates a curved path. 52 | - Sets pen color: Determines the line's color based on the current RGB values. 53 | ## 3. Completion: 54 | 55 | - Keeps the window open: Allows viewing of the spiral. 56 | ## 4. Key Points: 57 | 58 | - The code uses the turtle library to create a visual representation. 59 | - It employs a loop and conditional statements to generate a rainbow-colored spiral pattern. 60 | - It manipulates RGB color values to produce smooth color transitions. 61 | - The code adheres to safety guidelines by avoiding any harmful, unethical, or discriminatory content. 62 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class02(Make a Rainbow Spiral)/rainbowspiral.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | from turtle import * 3 | 4 | turtle.title("rainbow spiral") 5 | speed(15) 6 | bgcolor("black") 7 | r,g,b=255,0,0 8 | 9 | for i in range(255*2): 10 | colormode(255) 11 | if i<255//3: 12 | g+=3 13 | elif i<255*2//3: 14 | r-=3 15 | elif i<255: 16 | b+=3 17 | elif i<255*4//3: 18 | g-=3 19 | elif i<255*5//3: 20 | r+=3 21 | else: 22 | b-=3 23 | fd(50+i) 24 | rt(91) 25 | pencolor(r,g,b) 26 | 27 | done() 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class03(Make a Car)/Readme.md: -------------------------------------------------------------------------------- 1 | ## -Code structure 2 | 3 | ```python 4 | # from turtle import * 5 | 6 | 7 | myCar = Turtle() 8 | 9 | 10 | # code for drawing rectangular upper body 11 | myCar.color('black') 12 | myCar.fillcolor('yellow') 13 | myCar.penup() 14 | myCar.goto(0,0) 15 | myCar.pendown() 16 | myCar.begin_fill() 17 | myCar.forward(370) 18 | myCar.left(90) 19 | myCar.forward(50) 20 | myCar.left(90) 21 | myCar.forward(370) 22 | myCar.left(90) 23 | myCar.forward(50) 24 | myCar.end_fill() 25 | 26 | 27 | # code for drawing window and roof 28 | myCar.penup() 29 | myCar.goto(100, 50) 30 | myCar.pendown() 31 | myCar.setheading(45) 32 | myCar.forward(70) 33 | myCar.setheading(0) 34 | myCar.forward(100) 35 | myCar.setheading(-45) 36 | myCar.forward(70) 37 | myCar.setheading(90) 38 | myCar.penup() 39 | myCar.goto(200, 50) 40 | myCar.pendown() 41 | myCar.forward(49.50) 42 | 43 | 44 | # code for drawing two tyres 45 | myCar.penup() 46 | myCar.goto(100, -10) 47 | myCar.pendown() 48 | myCar.color('black') 49 | myCar.fillcolor('black') 50 | myCar.begin_fill() 51 | myCar.circle(20) 52 | myCar.end_fill() 53 | myCar.penup() 54 | myCar.goto(300, -10) 55 | myCar.pendown() 56 | myCar.color('black') 57 | myCar.fillcolor('black') 58 | myCar.begin_fill() 59 | myCar.circle(20) 60 | myCar.end_fill() 61 | 62 | 63 | myCar.hideturtle() 64 | 65 | done() 66 | ``` 67 | 68 | Explaination : 69 | 70 | ## 1. Import Turtle Module: 71 | 72 | - from turtle import *: Imports the turtle graphics library for drawing shapes and animations. 73 | ## 2. Create Turtle Object: 74 | 75 | - myCar = Turtle(): Creates a turtle object named myCar, which will act as the "pen" to draw the car. 76 | ## 3. Draw Rectangular Upper Body: 77 | 78 | ### Set colors: 79 | - myCar.color('black'): Sets the outline color of the car to black. 80 | - myCar.fillcolor('yellow'): Sets the fill color of the car to yellow. 81 | ### Position the turtle: 82 | - myCar.penup(): Lifts the pen so it doesn't draw while moving. 83 | - myCar.goto(0, 0): Moves the turtle to the starting position (bottom-left corner of the car). 84 | m- yCar.pendown(): Puts the pen down to start drawing. 85 | ### Draw the rectangle: 86 | - myCar.begin_fill(): Starts filling the shape with the chosen fill color. 87 | - myCar.forward(370), myCar.left(90), myCar.forward(50), etc.: These commands draw the four sides of the rectangle. 88 | - myCar.end_fill(): Finishes filling the shape. 89 | ## 4. Draw Window and Roof: 90 | 91 | ### Position the turtle: 92 | - myCar.penup(), myCar.goto(100, 50), myCar.pendown(), etc.: These commands move the turtle to the appropriate starting position for the window and roof. 93 | ### Draw the window and roof: 94 | - myCar.setheading(45), myCar.forward(70), etc.: These commands draw the slanted lines for the window and the top of the roof. 95 | - myCar.forward(49.50): Draws the horizontal line dividing the window. 96 | ## 5. Draw Tyres: 97 | 98 | ### Position the turtle and set colors: 99 | - myCar.penup(), myCar.goto(100, -10), myCar.pendown(), etc.: Move the turtle to the positions for the two tyres. 100 | - myCar.color('black'), myCar.fillcolor('black'): Set both outline and fill color to black for the tyres. 101 | ### Draw the tyres: 102 | - myCar.begin_fill(), myCar.circle(20), myCar.end_fill(): These commands create two filled black circles for the tyres. 103 | ## 6. Hide Turtle and Keep Window Open: 104 | 105 | - myCar.hideturtle(): Hides the turtle so it's not visible in the final drawing. 106 | - done(): Keeps the turtle graphics window open until it's manually closed. 107 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class03(Make a Car)/car.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | 4 | myCar = Turtle() 5 | 6 | 7 | # code for drawing rectangular upper body 8 | myCar.color('black') 9 | myCar.fillcolor('yellow') 10 | myCar.penup() 11 | myCar.goto(0,0) 12 | myCar.pendown() 13 | myCar.begin_fill() 14 | myCar.forward(370) 15 | myCar.left(90) 16 | myCar.forward(50) 17 | myCar.left(90) 18 | myCar.forward(370) 19 | myCar.left(90) 20 | myCar.forward(50) 21 | myCar.end_fill() 22 | 23 | 24 | # code for drawing window and roof 25 | myCar.penup() 26 | myCar.goto(100, 50) 27 | myCar.pendown() 28 | myCar.setheading(45) 29 | myCar.forward(70) 30 | myCar.setheading(0) 31 | myCar.forward(100) 32 | myCar.setheading(-45) 33 | myCar.forward(70) 34 | myCar.setheading(90) 35 | myCar.penup() 36 | myCar.goto(200, 50) 37 | myCar.pendown() 38 | myCar.forward(49.50) 39 | 40 | 41 | # code for drawing two tyres 42 | myCar.penup() 43 | myCar.goto(100, -10) 44 | myCar.pendown() 45 | myCar.color('black') 46 | myCar.fillcolor('black') 47 | myCar.begin_fill() 48 | myCar.circle(20) 49 | myCar.end_fill() 50 | myCar.penup() 51 | myCar.goto(300, -10) 52 | myCar.pendown() 53 | myCar.color('black') 54 | myCar.fillcolor('black') 55 | myCar.begin_fill() 56 | myCar.circle(20) 57 | myCar.end_fill() 58 | 59 | 60 | myCar.hideturtle() 61 | 62 | done() 63 | 64 | 65 | 66 | 67 | 68 | # ###### readme 69 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class04(Make a Heart)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | wn = Screen() 5 | wn.setup(width=400, height=400) 6 | red = Turtle() 7 | 8 | def curve(): 9 | for i in range(200): 10 | red.right(1) 11 | red.forward(1) 12 | 13 | def heart(): 14 | red.fillcolor('red') 15 | red.begin_fill() 16 | red.left(140) 17 | red.forward(113) 18 | curve() 19 | red.left(120) 20 | curve() 21 | red.forward(112) 22 | red.end_fill() 23 | 24 | heart() 25 | red.ht() 26 | done() 27 | 28 | 29 | ``` 30 | 31 | # Explaination: 32 | 33 | ## 1. Import and Setup: 34 | 35 | - Imports the turtle module: from turtle import * 36 | - Creates a screen object: wn = Screen() 37 | - Sets screen dimensions: wn.setup(width=400, height=400) 38 | - Creates a turtle object: red = Turtle() 39 | ## 2. Curve Function: 40 | 41 | - Defines a function curve() to create a curved path: 42 | - Loop for 200 steps: for i in range(200): 43 | - Turn right by 1 degree: red.right(1) 44 | - Move forward by 1 unit: red.forward(1) 45 | ## 3. Heart Function: 46 | 47 | ### Defines a function heart() to draw a heart shape: 48 | - Set fill color to red: red.fillcolor('red') 49 | - Start filling: red.begin_fill() 50 | - Turn left by 140 degrees: red.left(140) 51 | - Move forward by 113 units: red.forward(113) 52 | ### Call the curve() function to create the first curve: curve() 53 | ### Turn left by 120 degrees: red.left(120) 54 | ### Call curve() again for the second curve: curve() 55 | ### Move forward by 112 units: red.forward(112) 56 | ### End filling: red.end_fill() 57 | ## 4. Main Execution: 58 | 59 | - Calls the heart() function to draw the heart: heart() 60 | - Hides the turtle: red.ht() 61 | - Keeps the window open until closed manually: done() 62 | ## In summary, the code uses the turtle library to create a red heart shape on a 400x400 window. It does this by: 63 | 64 | - Defining functions for drawing curves and the heart shape. 65 | - Using basic turtle commands (forward, left, right, fillcolor, begin_fill, end_fill) to create the shape. 66 | - Employing a loop to create smooth curves. 67 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class04(Make a Heart)/heart.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | wn = Screen() 3 | wn.setup(width=400, height=400) 4 | red = Turtle() 5 | 6 | def curve(): 7 | for i in range(200): 8 | red.right(1) 9 | red.forward(1) 10 | 11 | def heart(): 12 | red.fillcolor('red') 13 | red.begin_fill() 14 | red.left(140) 15 | red.forward(113) 16 | curve() 17 | red.left(120) 18 | curve() 19 | red.forward(112) 20 | red.end_fill() 21 | 22 | heart() 23 | red.ht() 24 | done() 25 | 26 | 27 | 28 | 29 | #### readme 30 | 31 | 32 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class05(Make a Tree)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | 4 | from turtle import * 5 | 6 | speed(0) 7 | 8 | # Blue Background 9 | penup() 10 | goto(0, -250) 11 | pendown() 12 | color("lightskyblue") 13 | begin_fill() 14 | circle(250) 15 | end_fill() 16 | 17 | # Tree Trunk 18 | penup() 19 | goto(-15, -50) 20 | pendown() 21 | color("brown") 22 | begin_fill() 23 | for i in range(2): 24 | forward(30) 25 | right(90) 26 | forward(40) 27 | right(90) 28 | end_fill() 29 | 30 | # Set the start position and the inital tree width 31 | y = -50 32 | width = 240 33 | height = 25 34 | 35 | # Green section of tree (add in the greater than symbol next to the 20 - YouTube doesn't allow me to put in pointy brackets). 36 | while width > 20: 37 | width = width - 30 # Make the tree get smaller as it goes up in height 38 | x = 0 - width / 2 # Set the starting x-value of each level of the tree 39 | color("green") 40 | penup() 41 | goto(x, y) 42 | pendown() 43 | begin_fill() 44 | for i in range(2): 45 | forward(width) 46 | left(90) 47 | forward(height) 48 | left(90) 49 | end_fill() 50 | 51 | y = y + height # Keep drawing the levels of the tree higher than the previous 52 | 53 | # Star 54 | penup() 55 | goto(-15, 150) 56 | pendown() 57 | color("yellow") 58 | begin_fill() 59 | for i in range(5): 60 | forward(30) 61 | right(144) 62 | end_fill() 63 | 64 | # Message 65 | penup() 66 | goto(-130, -150) 67 | color("red") 68 | write("MERRY CHRISTMAS", font=("Arial", 20, "bold")) 69 | 70 | hideturtle() 71 | done() 72 | ``` 73 | 74 | # Explaination: 75 | 76 | 77 | ## 1. Import and Setup: 78 | 79 | - Imports the turtle module: from turtle import * for drawing graphics. 80 | - Sets drawing speed: speed(0), fastest possible for a smoother experience. 81 | ## 2. Blue Background: 82 | 83 | - Moves the turtle to position: penup(), goto(0, -250). 84 | - Sets color: color("lightskyblue"). 85 | - Fills a circle as the background: begin_fill(), circle(250), end_fill(). 86 | - Image of light blue circular backgroundOpens in a new window 87 | - light blue circular background 88 | ## 3. Tree Trunk: 89 | 90 | - Moves to trunk position: penup(), goto(-15, -50). 91 | - Sets color: color("brown"). 92 | - Draws a filled rectangle as the trunk: begin_fill(), forward(30), right(90), forward(40), right(90), end_fill(). 93 | - Image of brown rectangular trunk on the blue backgroundOpens in a new window 94 | 95 | ## 4. Green Tree Sections: 96 | 97 | - Sets initial position and width: y = -50, width = 240, height = 25. 98 | - Loop for multiple tree sections: while width > 20: 99 | Reduce width for each level: width = width - 30. 100 | Calculate starting x-position: x = 0 - width / 2. 101 | - Set color: color("green"). 102 | - Move to starting position: penup(), goto(x, y). 103 | - Draw a filled rectangle: begin_fill(), forward(width), left(90), forward(height), left(90), end_fill(). 104 | - Increment y-position for next level: y = y + height. 105 | ## 5. Star: 106 | 107 | - Move to star position: penup(), goto(-15, 150). 108 | - Set color: color("yellow"). 109 | - Draw a filled star: begin_fill(), for i in range(5): forward(30), right(144), end_fill(). 110 | - Image of yellow star on top of the treeOpens in a new window 111 | ## 6. Message: 112 | 113 | - Move to message position: penup(), goto(-130, -150). 114 | - Set color: color("red"). 115 | - Write the message: write("MERRY CHRISTMAS", font=("Arial", 20, "bold")). 116 | - Image of text MERRY CHRISTMAS written in red below the treeOpens in a new window 117 | ## 7. Hide Turtle and Keep Window Open: 118 | 119 | - Hide the turtle: hideturtle(). 120 | - Keep the window open until clicked: done(). 121 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class05(Make a Tree)/tree.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | speed(0) 4 | 5 | # Blue Background 6 | penup() 7 | goto(0, -250) 8 | pendown() 9 | color("lightskyblue") 10 | begin_fill() 11 | circle(250) 12 | end_fill() 13 | 14 | # Tree Trunk 15 | penup() 16 | goto(-15, -50) 17 | pendown() 18 | color("brown") 19 | begin_fill() 20 | for i in range(2): 21 | forward(30) 22 | right(90) 23 | forward(40) 24 | right(90) 25 | end_fill() 26 | 27 | # Set the start position and the inital tree width 28 | y = -50 29 | width = 240 30 | height = 25 31 | 32 | # Green section of tree (add in the greater than symbol next to the 20 - YouTube doesn't allow me to put in pointy brackets). 33 | while width > 20: 34 | width = width - 30 # Make the tree get smaller as it goes up in height 35 | x = 0 - width / 2 # Set the starting x-value of each level of the tree 36 | color("green") 37 | penup() 38 | goto(x, y) 39 | pendown() 40 | begin_fill() 41 | for i in range(2): 42 | forward(width) 43 | left(90) 44 | forward(height) 45 | left(90) 46 | end_fill() 47 | 48 | y = y + height # Keep drawing the levels of the tree higher than the previous 49 | 50 | # Star 51 | penup() 52 | goto(-15, 150) 53 | pendown() 54 | color("yellow") 55 | begin_fill() 56 | for i in range(5): 57 | forward(30) 58 | right(144) 59 | end_fill() 60 | 61 | # Message 62 | penup() 63 | goto(-130, -150) 64 | color("red") 65 | write("MERRY CHRISTMAS", font=("Arial", 20, "bold")) 66 | 67 | hideturtle() 68 | done() 69 | 70 | 71 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class06(Make a Flower)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | 4 | from turtle import * 5 | title('Sixteen Petals Flower') 6 | setworldcoordinates(-2000,-2000,2000,2000) 7 | 8 | def draw_flower(x,y,tilt,radius): 9 | up() 10 | goto(x,y) 11 | down() 12 | seth(tilt-45) 13 | circle(radius,90) 14 | left(90) 15 | circle(radius,90) 16 | 17 | for tilt in range(0,360,30): 18 | draw_flower(0,0,tilt,1000) 19 | 20 | done() 21 | 22 | ``` 23 | 24 | # Explaination: 25 | 26 | ## 1. Import and Setup: 27 | 28 | - Imports the turtle module: from turtle import * 29 | - Sets the title of the drawing window: title('Sixteen Petals Flower') 30 | - Sets the world coordinates to a larger range: setworldcoordinates(-2000,-2000,2000,2000) This allows for more space to draw the flower. 31 | ## 2. Flower Drawing Function: 32 | 33 | - Defines a function draw_flower(x, y, tilt, radius): 34 | Moves the turtle to position (x, y): up(), goto(x, y), down() 35 | Sets the heading based on tilt: seth(tilt - 45) 36 | - Draws two connected quarter circles to create a petal: circle(radius, 90), left(90), circle(radius, 90) 37 | ## 3. Drawing Loop: 38 | 39 | - Loops through tilt values from 0 to 355 with a step of 30: for tilt in range(0, 360, 30): 40 | - Calls the draw_flower function with appropriate arguments for each petal: draw_flower(0, 0, tilt, 1000) 41 | ## 4. Keeps Window Open: 42 | 43 | - Keeps the drawing window open until it's manually closed: done() 44 | 45 | 46 | ## In summary: 47 | 48 | The code uses the turtle library to create a 16-petal flower. 49 | It defines a function to draw a single petal with a specific tilt and radius. 50 | It uses a loop to create 16 petals, each with a different tilt, resulting in a circular pattern. 51 | The world coordinates are set to a larger range to accommodate the flower's size. 52 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class06(Make a Flower)/flower.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | title('Sixteen Petals Flower') 3 | setworldcoordinates(-2000,-2000,2000,2000) 4 | 5 | def draw_flower(x,y,tilt,radius): 6 | up() 7 | goto(x,y) 8 | down() 9 | seth(tilt-45) 10 | circle(radius,90) 11 | left(90) 12 | circle(radius,90) 13 | 14 | for tilt in range(0,360,30): 15 | draw_flower(0,0,tilt,1000) 16 | 17 | done() 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class07(Make a Google Logo)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | #get the instance of turtle 5 | t=Turtle() 6 | #select color 7 | t.color('#4285F4','#4285F4') ## RBG value of color 8 | #change the pen size 9 | t.pensize(5) 10 | #change the drawing speed 11 | t.speed(3) 12 | 13 | t.forward(120) 14 | t.right(90) 15 | t.circle(-150,50) ## first circle for red color 16 | t.color('#0F9D58') 17 | t.circle(-150,100) 18 | t.color('#F4B400') 19 | t.circle(-150,60) 20 | t.color('#DB4437','#DB4437') 21 | 22 | t.begin_fill() 23 | t.circle(-150,100) 24 | t.right(90) 25 | t.forward(50) 26 | t.right(90) 27 | t.circle(100,100) 28 | t.right(90) 29 | t.forward(50) 30 | t.end_fill() 31 | 32 | t.begin_fill() 33 | 34 | ## second circle for yellow color 35 | 36 | t.color("#F4B400","#F4B400") 37 | t.right(180) 38 | t.forward(50) 39 | t.right(90) 40 | 41 | t.circle(100,60) 42 | t.right(90) 43 | t.forward(50) 44 | t.right(90) 45 | t.circle(-150,60) 46 | t.end_fill() 47 | 48 | 49 | # third circle of green color 50 | t.right(90) 51 | t.forward(50) 52 | t.right(90) 53 | t.circle(100,60) 54 | t.color('#0F9D58','#0F9D58') 55 | t.begin_fill() 56 | t.circle(100,100) 57 | t.right(90) 58 | t.forward(50) 59 | t.right(90) 60 | t.circle(-150,100) 61 | t.right(90) 62 | t.forward(50) 63 | t.end_fill() 64 | 65 | 66 | ##Draw last circle 67 | 68 | t.right(90) 69 | t.circle(100,100) 70 | t.color('#4285F4','#4285F4') 71 | t.begin_fill() 72 | t.circle(100,25) 73 | t.left(115) 74 | t.forward(65) 75 | t.right(90) 76 | t.forward(42) 77 | t.right(90) 78 | t.forward(124) 79 | t.right(90) 80 | t.circle(-150,50) 81 | t.right(90) 82 | t.forward(50) 83 | 84 | t.end_fill() 85 | t.penup() 86 | ``` 87 | 88 | # Explaination: 89 | 90 | 91 | ## 1. Import and Setup: 92 | 93 | - Imports the turtle module: from turtle import * 94 | - Creates a turtle object: t = Turtle() 95 | - Sets initial color to blue: t.color('#4285F4', '#4285F4') 96 | - Adjusts pen size: t.pensize(5) 97 | - Sets drawing speed: t.speed(3) 98 | ## 2. Drawing the Shape: 99 | 100 | - Forward and turn: t.forward(120), t.right(90) 101 | - First circle (red): t.circle(-150, 50) 102 | - Second circle (green): t.color('#0F9D58'), t.circle(-150, 100) 103 | - Third circle (yellow): t.color('#F4B400'), t.circle(-150, 60) 104 | ## 3. Filled red section: 105 | - t.color('#DB4437', '#DB4437') 106 | - t.begin_fill() 107 | - t.circle(-150, 100), t.right(90), t.forward(50), t.right(90), t.circle(100, 100), t.right(90), t.forward(50) 108 | - t.end_fill() 109 | ## 4. Filled yellow section: 110 | - t.begin_fill() 111 | - t.color('#F4B400', '#F4B400') 112 | - t.right(180), t.forward(50), t.right(90), t.circle(100, 60), t.right(90), t.forward(50), t.right(90), t.circle(-150, 60) 113 | - t.end_fill() 114 | ## 5. Filled green section: 115 | - t.right(90), t.forward(50), t.right(90), t.circle(100, 60) 116 | - t.color('#0F9D58', '#0F9D58') 117 | - t.begin_fill() 118 | - t.circle(100, 100), t.right(90), t.forward(50), t.right(90), t.circle(-150, 100), t.right(90), t.forward(50) 119 | - t.end_fill() 120 | ## 6. Filled blue section: 121 | - t.right(90), t.circle(100, 100) 122 | - t.color('#4285F4', '#4285F4') 123 | - t.begin_fill() 124 | - t.circle(100, 25), t.left(115), t.forward(65), t.right(90), t.forward(42), t.right(90), t.forward(124), t.right(90), t.circle(-150, 50), t.right(90), t.forward(50) 125 | - t.end_fill() 126 | End drawing: t.penup() 127 | 128 | ## 7. Key Points: 129 | 130 | The code uses the turtle library to create a visually interesting shape composed of multiple colored circles and filled sections. 131 | It demonstrates the use of colors, pen size, drawing speed, and fill commands. 132 | The shape is created by carefully positioning the turtle and drawing circles and lines in a specific sequence. 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class07(Make a Google Logo)/google.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | #get the instance of turtle 3 | t=Turtle() 4 | #select color 5 | t.color('#4285F4','#4285F4') ## RBG value of color 6 | #change the pen size 7 | t.pensize(5) 8 | #change the drawing speed 9 | t.speed(3) 10 | 11 | t.forward(120) 12 | t.right(90) 13 | t.circle(-150,50) ## first circle for red color 14 | t.color('#0F9D58') 15 | t.circle(-150,100) 16 | t.color('#F4B400') 17 | t.circle(-150,60) 18 | t.color('#DB4437','#DB4437') 19 | 20 | t.begin_fill() 21 | t.circle(-150,100) 22 | t.right(90) 23 | t.forward(50) 24 | t.right(90) 25 | t.circle(100,100) 26 | t.right(90) 27 | t.forward(50) 28 | t.end_fill() 29 | 30 | t.begin_fill() 31 | 32 | ## second circle for yellow color 33 | 34 | t.color("#F4B400","#F4B400") 35 | t.right(180) 36 | t.forward(50) 37 | t.right(90) 38 | 39 | t.circle(100,60) 40 | t.right(90) 41 | t.forward(50) 42 | t.right(90) 43 | t.circle(-150,60) 44 | t.end_fill() 45 | 46 | 47 | # third circle of green color 48 | t.right(90) 49 | t.forward(50) 50 | t.right(90) 51 | t.circle(100,60) 52 | t.color('#0F9D58','#0F9D58') 53 | t.begin_fill() 54 | t.circle(100,100) 55 | t.right(90) 56 | t.forward(50) 57 | t.right(90) 58 | t.circle(-150,100) 59 | t.right(90) 60 | t.forward(50) 61 | t.end_fill() 62 | 63 | 64 | ##Draw last circle 65 | 66 | t.right(90) 67 | t.circle(100,100) 68 | t.color('#4285F4','#4285F4') 69 | t.begin_fill() 70 | t.circle(100,25) 71 | t.left(115) 72 | t.forward(65) 73 | t.right(90) 74 | t.forward(42) 75 | t.right(90) 76 | t.forward(124) 77 | t.right(90) 78 | t.circle(-150,50) 79 | t.right(90) 80 | t.forward(50) 81 | 82 | t.end_fill() 83 | t.penup() 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class08(Make a Batman logo)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | 5 | bat = Turtle() 6 | 7 | 8 | bat.turtlesize(1, 1, 1) 9 | bat.pensize(3) 10 | 11 | 12 | wn = Screen() 13 | wn.bgcolor("white") 14 | wn.title("BATMAN") 15 | 16 | 17 | bat.color("yellow", "black") 18 | 19 | 20 | bat.begin_fill() 21 | 22 | bat.left(90) 23 | bat.circle(50, 85) 24 | bat.circle(15, 110) 25 | bat.right(180) 26 | 27 | bat.circle(30, 150) 28 | bat.right(5) 29 | bat.forward(10) #draw forward line of 10 units 30 | 31 | bat.right(90) 32 | bat.circle(-70, 140) 33 | bat.forward(40) 34 | bat.right(110) 35 | 36 | bat.circle(100, 30) 37 | bat.circle(30, 100) 38 | bat.left(50) 39 | bat.forward(50) 40 | bat.right(145) 41 | 42 | bat.forward(30) 43 | bat.left(55) 44 | bat.forward(10) 45 | 46 | 47 | bat.forward(10) 48 | bat.left(55) 49 | bat.forward(30) 50 | 51 | 52 | bat.right(145) 53 | bat.forward(50) 54 | bat.left(50) 55 | bat.circle(30, 100) 56 | bat.circle(100, 30) 57 | 58 | bat.right(90) 59 | bat.right(20) 60 | bat.forward(40) 61 | bat.circle(-70, 140) 62 | 63 | bat.right(90) 64 | bat.forward(10) 65 | bat.right(5) 66 | bat.circle(30, 150) 67 | 68 | bat.left(180) 69 | bat.circle(15, 110) 70 | bat.circle(50, 85) 71 | 72 | bat.end_fill() 73 | 74 | done() 75 | ``` 76 | # Explaination: 77 | 78 | 79 | ## 1. Import and Setup: 80 | 81 | Imports the turtle module: from turtle import * 82 | Creates a turtle object: bat = Turtle() 83 | Sets turtle size and pen size: bat.turtlesize(1, 1, 1), bat.pensize(3) 84 | Creates and customizes the screen: wn = Screen(), wn.bgcolor("white"), wn.title("BATMAN") 85 | Sets turtle color: bat.color("yellow", "black") (outline: yellow, fill: black) 86 | ## 2. Drawing the Batman Logo: 87 | 88 | Begins fill: bat.begin_fill() 89 | Turn 1: 90 | Rotates left 90 degrees: bat.left(90) 91 | Draws two circles: bat.circle(50, 85), bat.circle(15, 110) 92 | Rotates right 180 degrees: bat.right(180) 93 | Turn 2: 94 | Draws a circle and moves forward: bat.circle(30, 150), bat.right(5), bat.forward(10) 95 | Turn 3: 96 | Draws a circle and moves forward: bat.right(90), bat.circle(-70, 140), bat.forward(40) 97 | Rotates right 110 degrees: bat.right(110) 98 | Turn 4: 99 | Draws two circles, moves forward, and rotates: bat.circle(100, 30), bat.circle(30, 100), bat.left(50), bat.forward(50), bat.right(145) 100 | Turn 5: 101 | Moves forward and turns: bat.forward(30), bat.left(55), bat.forward(10) 102 | Reverse (repeating steps for symmetry): 103 | ... (same commands as Turn 4 and Turn 5, but in reverse order) 104 | End fill: bat.end_fill() 105 | Keeps the window open: done() 106 | ## 3.Key Points: 107 | 108 | - The code leverages the turtle library for simple visual drawing. 109 | - It uses basic turtle commands like forward, left, right, and circle to create shapes. 110 | - The begin_fill() and end_fill() functions enable filling shapes with color. 111 | - The code carefully coordinates turns and movements to construct the Batman logo's recognizable shape. 112 | - By reversing the steps, it ensures symmetry in the final drawing. -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class08(Make a Batman logo)/bat.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | #initialize method 4 | bat = Turtle() 5 | 6 | #size of pointer and pen 7 | bat.turtlesize(1, 1, 1) 8 | bat.pensize(3) 9 | 10 | #screen info 11 | wn = Screen() 12 | wn.bgcolor("white") 13 | wn.title("BATMAN") 14 | 15 | #colour 16 | bat.color("yellow", "black") 17 | 18 | 19 | #begin filling color 20 | bat.begin_fill() 21 | 22 | #turn1 23 | bat.left(90) # turn pointer direction to left of 90' 24 | bat.circle(50, 85) #draw circle of radius = 50 and 85' 25 | bat.circle(15, 110) 26 | bat.right(180) 27 | 28 | #turn 2 29 | bat.circle(30, 150) 30 | bat.right(5) 31 | bat.forward(10) #draw forward line of 10 units 32 | 33 | #turn 3 34 | bat.right(90) 35 | bat.circle(-70, 140) 36 | bat.forward(40) 37 | bat.right(110) 38 | 39 | #turn 4 40 | bat.circle(100, 30) 41 | bat.circle(30, 100) 42 | bat.left(50) 43 | bat.forward(50) 44 | bat.right(145) 45 | 46 | #turn5 47 | bat.forward(30) 48 | bat.left(55) 49 | bat.forward(10) 50 | 51 | #reverse 52 | 53 | #turn 5 54 | bat.forward(10) 55 | bat.left(55) 56 | bat.forward(30) 57 | 58 | #turn 4 59 | 60 | bat.right(145) 61 | bat.forward(50) 62 | bat.left(50) 63 | bat.circle(30, 100) 64 | bat.circle(100, 30) 65 | 66 | #turn 3 67 | bat.right(90) 68 | bat.right(20) 69 | bat.forward(40) 70 | bat.circle(-70, 140) 71 | 72 | #turn 2 73 | bat.right(90) 74 | bat.forward(10) 75 | bat.right(5) 76 | bat.circle(30, 150) 77 | 78 | #turn 1 79 | bat.left(180) 80 | bat.circle(15, 110) 81 | bat.circle(50, 85) 82 | 83 | #end color filling 84 | bat.end_fill() 85 | 86 | #end the turtle method 87 | done() 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class09(Make a Ironman Face)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | 5 | canvas1 = [[(-40, 120), (-70, 260), (-130, 230), (-170, 200), (-170, 100), (-160, 40), (-170, 10), (-150, -10), (-140, 10), 6 | (-40, -20), (0, -20)], 7 | [(0, -20), (40, -20), (140, 10), (150, -10), (170, 10), (160, 40), (170, 100), (170, 200), (130, 230), (70, 260), 8 | (40, 120), (0, 120)]] 9 | canvas2 = [[(-40, -30), (-50, -40), (-100, -46), (-130, -40), (-176, 0), (-186, -30), (-186, -40), (-120, -170), (-110, -210), 10 | (-80, -230), (-64, -210), (0, -210)], 11 | [(0, -210), (64, -210), (80, -230), (110, -210), (120, -170), (186, -40), (186, -30), (176, 0), (130, -40), 12 | (100, -46), (50, -40), (40, -30), (0, -30)]] 13 | canvas3 = [[(-60, -220), (-80, -240), (-110, -220), (-120, -250), (-90, -280), (-60, -260), (-30, -260), (-20, -250), 14 | (0, -250)], 15 | [(0, -250), (20, -250), (30, -260), (60, -260), (90, -280), (120, -250), (110, -220), (80, -240), (60, -220), 16 | (0, -220)]] 17 | 18 | hideturtle() 19 | bgcolor('#ba161e') # Dark Red 20 | setup(500, 600) 21 | title("I AM IRONMAN") 22 | canvas1Goto = (0, 120) 23 | canvas2Goto = (0, -30) 24 | canvas3Goto = (0, -220) 25 | speed(2) 26 | 27 | 28 | def logo(a, b): 29 | penup() 30 | goto(b) 31 | pendown() 32 | color('#fab104') # Light Yellow 33 | begin_fill() 34 | 35 | for i in range(len(a[0])): 36 | x, y = a[0][i] 37 | goto(x, y) 38 | 39 | for i in range(len(a[1])): 40 | x, y = a[1][i] 41 | goto(x, y) 42 | end_fill() 43 | 44 | 45 | logo(canvas1, canvas1Goto) 46 | logo(canvas2, canvas2Goto) 47 | logo(canvas3, canvas3Goto) 48 | hideturtle() 49 | done() 50 | 51 | 52 | 53 | 54 | 55 | ``` 56 | 57 | # Explaination: 58 | 59 | ## 1. Import: 60 | 61 | - nImports the turtle module for drawing graphics. 62 | - Defines lists of coordinates (canvas1, canvas2, canvas3) representing shapes to be drawn. 63 | ## 2. Sets up the drawing environment: 64 | - Hides the turtle cursor (hideturtle()). 65 | - Sets background color to dark red (bgcolor('#ba161e')). 66 | - Creates a 500x600 pixel window (setup(500, 600)). 67 | - Sets the window title to "I AM IRONMAN" (title("I AM IRONMAN")). 68 | - Defines starting positions for each shape (canvas1Goto, canvas2Goto, canvas3Goto). 69 | - Sets turtle drawing speed to 2 (speed(2)). 70 | ## 3. Logo Drawing Function: 71 | 72 | ## 3. logo(a, b): 73 | - Takes a list of coordinates (a) and a starting position (b) as input. 74 | - Moves the turtle to the starting position without drawing (penup(), goto(b), pendown()). 75 | - Sets the drawing color to light yellow (color('#fab104')). 76 | - Begins filling the shape (begin_fill()). 77 | - Iterates through the coordinates in a[0] and a[1], moving the turtle to each point (goto(x, y)). 78 | - Ends filling the shape (end_fill()). 79 | ## 4. Main Execution: 80 | 81 | - Calls the logo function to draw each shape: logo(canvas1, canvas1Goto), logo(canvas2, canvas2Goto), logo(canvas3, canvas3Goto). 82 | - Hides the turtle cursor again (hideturtle()). 83 | - Keeps the drawing window open until clicked (done()). 84 | ## 5. Key Points: 85 | 86 | The code uses lists of coordinates to define shapes, making it easier to modify their appearance. 87 | It employs a function (logo) to reuse the drawing logic for different shapes, promoting code organization. 88 | The turtle library's basic commands (penup, pendown, goto, color, begin_fill, end_fill) are used to create and fill the shapes. 89 | The code sets up a custom background color and title for the drawing window 90 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class09(Make a Ironman Face)/ironman.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | canvas1 = [[(-40, 120), (-70, 260), (-130, 230), (-170, 200), (-170, 100), (-160, 40), (-170, 10), (-150, -10), (-140, 10), 4 | (-40, -20), (0, -20)], 5 | [(0, -20), (40, -20), (140, 10), (150, -10), (170, 10), (160, 40), (170, 100), (170, 200), (130, 230), (70, 260), 6 | (40, 120), (0, 120)]] 7 | canvas2 = [[(-40, -30), (-50, -40), (-100, -46), (-130, -40), (-176, 0), (-186, -30), (-186, -40), (-120, -170), (-110, -210), 8 | (-80, -230), (-64, -210), (0, -210)], 9 | [(0, -210), (64, -210), (80, -230), (110, -210), (120, -170), (186, -40), (186, -30), (176, 0), (130, -40), 10 | (100, -46), (50, -40), (40, -30), (0, -30)]] 11 | canvas3 = [[(-60, -220), (-80, -240), (-110, -220), (-120, -250), (-90, -280), (-60, -260), (-30, -260), (-20, -250), 12 | (0, -250)], 13 | [(0, -250), (20, -250), (30, -260), (60, -260), (90, -280), (120, -250), (110, -220), (80, -240), (60, -220), 14 | (0, -220)]] 15 | 16 | hideturtle() 17 | bgcolor('#ba161e') # Dark Red 18 | setup(500, 600) 19 | title("I AM IRONMAN") 20 | canvas1Goto = (0, 120) 21 | canvas2Goto = (0, -30) 22 | canvas3Goto = (0, -220) 23 | speed(2) 24 | 25 | 26 | def logo(a, b): 27 | penup() 28 | goto(b) 29 | pendown() 30 | color('#fab104') # Light Yellow 31 | begin_fill() 32 | 33 | for i in range(len(a[0])): 34 | x, y = a[0][i] 35 | goto(x, y) 36 | 37 | for i in range(len(a[1])): 38 | x, y = a[1][i] 39 | goto(x, y) 40 | end_fill() 41 | 42 | 43 | logo(canvas1, canvas1Goto) 44 | logo(canvas2, canvas2Goto) 45 | logo(canvas3, canvas3Goto) 46 | hideturtle() 47 | done() 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class10(Make a Python logo)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | 5 | t = Turtle() 6 | s = Screen() 7 | s.bgcolor("black") 8 | t.speed(10) 9 | t.pensize(2) 10 | t.pencolor("white") 11 | 12 | 13 | 14 | def s_curve(): 15 | for i in range(90): 16 | t.left(1) 17 | t.forward(1) 18 | 19 | def r_curve(): 20 | for i in range(90): 21 | t.right(1) 22 | t.forward(1) 23 | 24 | def l_curve(): 25 | s_curve() 26 | t.forward(80) 27 | s_curve() 28 | 29 | def l_curve1(): 30 | s_curve() 31 | t.forward(90) 32 | s_curve() 33 | 34 | def half(): 35 | t.forward(50) 36 | s_curve() 37 | t.forward(90) 38 | l_curve() 39 | t.forward(40) 40 | t.left(90) 41 | t.forward(80) 42 | t.right(90) 43 | t.forward(10) 44 | t.right(90) 45 | t.forward(120) #on test 46 | l_curve1() 47 | t.forward(30) 48 | t.left(90) 49 | t.forward(50) 50 | r_curve() 51 | t.forward(40) 52 | t.end_fill() 53 | 54 | def get_pos(): 55 | t.penup() 56 | t.forward(20) 57 | t.right(90) 58 | t.forward(10) 59 | t.right(90) 60 | t.pendown() 61 | 62 | def eye(): 63 | t.penup() 64 | t.right(90) 65 | t.forward(160) 66 | t.left(90) 67 | t.forward(70) 68 | t.pencolor("black") 69 | t.dot(35) 70 | 71 | def sec_dot(): 72 | t.left(90) 73 | t.penup() 74 | t.forward(310) 75 | t.left(90) 76 | t.forward(120) 77 | t.pendown() 78 | 79 | t.dot(35) 80 | 81 | 82 | 83 | 84 | t.fillcolor("#306998") 85 | t.begin_fill() 86 | half() 87 | t.end_fill() 88 | get_pos() 89 | t.fillcolor("#FFD43B") 90 | t.begin_fill() 91 | half() 92 | t.end_fill() 93 | 94 | eye() 95 | sec_dot() 96 | 97 | 98 | 99 | def pause(): 100 | t.speed(2) 101 | for i in range(100): 102 | t.left(90) 103 | pause() 104 | 105 | 106 | 107 | ``` 108 | 109 | # Explaination: 110 | 111 | Here's a breakdown of the code's details: 112 | 113 | Import and Setup: 114 | 115 | Imports the turtle module: from turtle import * 116 | Creates a turtle object and screen: t = Turtle(), s = Screen() 117 | Sets background color to black: s.bgcolor("black") 118 | Adjusts turtle speed and pen properties: t.speed(10), t.pensize(2), t.pencolor("white") 119 | Curve Functions: 120 | 121 | s_curve(): Creates a left-turning curve using a loop of small turns and forward steps. 122 | r_curve(): Creates a right-turning curve using a similar loop. 123 | l_curve(), l_curve1(): Combine s_curve() with forward movement for longer curves. 124 | Half-Shape Drawing: 125 | 126 | half(): Draws one half of the overall shape using s_curve(), l_curve(), forward movements, and turns. 127 | Positioning and Filling: 128 | 129 | get_pos(): Moves the turtle to the starting position for drawing the second half. 130 | t.fillcolor("#306998"): Sets fill color to blue for the first half. 131 | t.begin_fill(), half(), t.end_fill(): Draws and fills the first half. 132 | t.fillcolor("#FFD43B"): Sets fill color to yellow for the second half. 133 | t.begin_fill(), half(), t.end_fill(): Draws and fills the second half. 134 | Eye and Dot: 135 | 136 | eye(): Positions the turtle and draws a black dot as the eye. 137 | sec_dot(): Positions the turtle and draws another black dot at a different location. 138 | Pause: 139 | 140 | pause(): Creates a visually appealing animation by repeatedly turning the turtle. 141 | Key Points: 142 | 143 | The code uses functions to create reusable blocks of code, making it more organized and readable. 144 | It employs the turtle library's basic drawing commands and fill functions to create the shape. 145 | It breaks down complex shapes into smaller, simpler curves for easier drawing. 146 | It demonstrates basic animation techniques with the pause() function. 147 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class10(Make a Python logo)/pythonlogo.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | t = Turtle() 4 | s = Screen() 5 | s.bgcolor("black") 6 | t.speed(10) 7 | t.pensize(2) 8 | t.pencolor("white") 9 | 10 | 11 | 12 | def s_curve(): 13 | for i in range(90): 14 | t.left(1) 15 | t.forward(1) 16 | 17 | def r_curve(): 18 | for i in range(90): 19 | t.right(1) 20 | t.forward(1) 21 | 22 | def l_curve(): 23 | s_curve() 24 | t.forward(80) 25 | s_curve() 26 | 27 | def l_curve1(): 28 | s_curve() 29 | t.forward(90) 30 | s_curve() 31 | 32 | def half(): 33 | t.forward(50) 34 | s_curve() 35 | t.forward(90) 36 | l_curve() 37 | t.forward(40) 38 | t.left(90) 39 | t.forward(80) 40 | t.right(90) 41 | t.forward(10) 42 | t.right(90) 43 | t.forward(120) #on test 44 | l_curve1() 45 | t.forward(30) 46 | t.left(90) 47 | t.forward(50) 48 | r_curve() 49 | t.forward(40) 50 | t.end_fill() 51 | 52 | def get_pos(): 53 | t.penup() 54 | t.forward(20) 55 | t.right(90) 56 | t.forward(10) 57 | t.right(90) 58 | t.pendown() 59 | 60 | def eye(): 61 | t.penup() 62 | t.right(90) 63 | t.forward(160) 64 | t.left(90) 65 | t.forward(70) 66 | t.pencolor("black") 67 | t.dot(35) 68 | 69 | def sec_dot(): 70 | t.left(90) 71 | t.penup() 72 | t.forward(310) 73 | t.left(90) 74 | t.forward(120) 75 | t.pendown() 76 | 77 | t.dot(35) 78 | 79 | 80 | 81 | 82 | t.fillcolor("#306998") 83 | t.begin_fill() 84 | half() 85 | t.end_fill() 86 | get_pos() 87 | t.fillcolor("#FFD43B") 88 | t.begin_fill() 89 | half() 90 | t.end_fill() 91 | 92 | eye() 93 | sec_dot() 94 | 95 | 96 | 97 | def pause(): 98 | t.speed(2) 99 | for i in range(100): 100 | t.left(90) 101 | pause() 102 | 103 | 104 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class11(Make a Spiderman logo)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | 4 | from time import * 5 | from turtle import * 6 | bgcolor('red') 7 | pensize(10) 8 | fillcolor('black') 9 | begin_fill() 10 | circle(20) 11 | end_fill() 12 | penup() 13 | right(90) 14 | forward(5) 15 | pendown() 16 | fillcolor('black') 17 | begin_fill() 18 | right(60) 19 | for i in range(6): 20 | forward(50) 21 | left(60) 22 | end_fill() 23 | penup() 24 | left(150) 25 | forward(39) 26 | left(90) 27 | forward(9) 28 | pendown() 29 | forward(25) 30 | right(60) 31 | forward(15) 32 | left(60) 33 | forward(25) 34 | penup() 35 | backward(25) 36 | right(60) 37 | back(15) 38 | left(60) 39 | backward(25) 40 | left(60) 41 | pendown() 42 | backward(35) 43 | left(120) 44 | forward(80) 45 | penup() 46 | left(40) 47 | forward(30) 48 | left(140) 49 | pendown() 50 | forward(110) 51 | left(60) 52 | forward(40) 53 | right(60) 54 | forward(7) 55 | right(60) 56 | forward(20) 57 | left(60) 58 | forward(40) 59 | penup() 60 | goto(0,0) 61 | left(90) 62 | forward(39) 63 | right(90) 64 | forward(9) 65 | pendown() 66 | forward(25) 67 | left(60) 68 | forward(15) 69 | right(60) 70 | forward(25) 71 | penup() 72 | backward(25) 73 | left(60) 74 | back(15) 75 | right(60) 76 | backward(25) 77 | right(60) 78 | pendown() 79 | backward(35) 80 | right(120) 81 | forward(80) 82 | penup() 83 | right(40) 84 | forward(30) 85 | right(140) 86 | pendown() 87 | forward(110) 88 | right(60) 89 | forward(40) 90 | left(60) 91 | forward(7) 92 | left(60) 93 | forward(20) 94 | right(60) 95 | forward(40) 96 | sleep(30) 97 | done() 98 | 99 | 100 | 101 | 102 | 103 | 104 | ``` 105 | 106 | # Explaination: 107 | 108 | ## 1. Imports: 109 | 110 | - from time import *: Imports the time module for pausing the execution later. 111 | - from turtle import *: Imports the turtle module for drawing graphics. 112 | ## 2. Background and Head: 113 | 114 | - bgcolor('red'): Sets the background color to red. 115 | - pensize(10): Sets the pen thickness to 10 pixels. 116 | - fillcolor('black'): Sets the fill color to black. 117 | - begin_fill(): Starts a filled shape. 118 | - circle(20): Draws a black circle with a radius of 20 pixels (the head). 119 | - end_fill(): Ends the filled shape. 120 | ## 3. Body: 121 | 122 | - penup(): Lifts the pen to move without drawing. 123 | - right(90), forward(5): Moves the turtle slightly to the right and up. 124 | - pendown(): Puts the pen down to start drawing again. 125 | - fillcolor('black'): Sets the fill color to black again. 126 | - begin_fill(): Starts another filled shape. 127 | - right(60): Turns the turtle 60 degrees right. 128 | - for i in range(6): ...: Repeats the following code 6 times: 129 | - forward(50): Draws a side of the body. 130 | - left(60): Turns 60 degrees left to prepare for the next side. 131 | - end_fill(): Ends the filled shape, completing the hexagonal body. 132 | ## 4. Left Arm: 133 | 134 | - penup(), left(150), forward(39), left(90), forward(9): Positions the turtle for drawing the left arm. 135 | - pendown(): Starts drawing. 136 | A series of forward, right, left, and backward movements create the arm's shape. 137 | ## 5. Left Hand: 138 | 139 | - More movements draw the fingers and hand. 140 | ## 6. Right Arm and Hand: 141 | 142 | Similar code blocks, positioned differently, create the right arm and hand. 143 | ## 7. Pause and Exit: 144 | 145 | - sleep(30): Pauses the execution for 30 seconds. 146 | - done(): Keeps the turtle graphics window open until it's closed manually. 147 | ## 8. Key Points: 148 | 149 | - The code uses basic turtle commands to draw a simple robot with a head, body, and arms. 150 | - It employs the fill function to create solid shapes. 151 | - The sleep() function pauses the drawing for a visual effect. 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class11(Make a Spiderman logo)/spidermanlogo.py: -------------------------------------------------------------------------------- 1 | 2 | from time import * 3 | from turtle import * 4 | bgcolor('red') 5 | pensize(10) 6 | fillcolor('black') 7 | begin_fill() 8 | circle(20) 9 | end_fill() 10 | penup() 11 | right(90) 12 | forward(5) 13 | pendown() 14 | fillcolor('black') 15 | begin_fill() 16 | right(60) 17 | for i in range(6): 18 | forward(50) 19 | left(60) 20 | end_fill() 21 | penup() 22 | left(150) 23 | forward(39) 24 | left(90) 25 | forward(9) 26 | pendown() 27 | forward(25) 28 | right(60) 29 | forward(15) 30 | left(60) 31 | forward(25) 32 | penup() 33 | backward(25) 34 | right(60) 35 | back(15) 36 | left(60) 37 | backward(25) 38 | left(60) 39 | pendown() 40 | backward(35) 41 | left(120) 42 | forward(80) 43 | penup() 44 | left(40) 45 | forward(30) 46 | left(140) 47 | pendown() 48 | forward(110) 49 | left(60) 50 | forward(40) 51 | right(60) 52 | forward(7) 53 | right(60) 54 | forward(20) 55 | left(60) 56 | forward(40) 57 | penup() 58 | goto(0,0) 59 | left(90) 60 | forward(39) 61 | right(90) 62 | forward(9) 63 | pendown() 64 | forward(25) 65 | left(60) 66 | forward(15) 67 | right(60) 68 | forward(25) 69 | penup() 70 | backward(25) 71 | left(60) 72 | back(15) 73 | right(60) 74 | backward(25) 75 | right(60) 76 | pendown() 77 | backward(35) 78 | right(120) 79 | forward(80) 80 | penup() 81 | right(40) 82 | forward(30) 83 | right(140) 84 | pendown() 85 | forward(110) 86 | right(60) 87 | forward(40) 88 | left(60) 89 | forward(7) 90 | left(60) 91 | forward(20) 92 | right(60) 93 | forward(40) 94 | sleep(30) 95 | done() 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class12(Make a Rainbow)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | from colorsys import * 5 | 6 | def draw_one_color_arc(x,y,r,pensize,color): 7 | up() 8 | goto(x+r,y) 9 | down() 10 | seth(90) 11 | pensize(pensize) 12 | pencolor(color) 13 | circle(r,180) 14 | 15 | 16 | speed(0) 17 | hideturtle() 18 | bgcolor('light blue') 19 | title('Rainbow In Python Turtle') 20 | setup(700,700) 21 | num_colors = 49 22 | 23 | radius = 300 24 | penwidth = 20*7/num_colors 25 | hue = 0 26 | 27 | for i in range(num_colors): 28 | (r,g,b) = hsv_to_rgb(hue,1,1) 29 | draw_one_color_arc(0,-100,radius,penwidth,(r,g,b)) 30 | radius -= (penwidth-1) 31 | hue += 0.9/num_colors 32 | 33 | done() 34 | 35 | 36 | 37 | ``` 38 | 39 | # Explaination: 40 | 41 | ## 1. Import Modules: 42 | 43 | - from turtle import *: Imports the turtle library for graphics. 44 | - from colorsys import *: Imports the colorsys library for color conversions. 45 | ## 2. Define a Function to Draw Arcs: 46 | 47 | - draw_one_color_arc(x, y, r, pensize, color): 48 | - Moves the turtle to position (x + r, y). 49 | - Sets the heading to 90 degrees (upwards). 50 | - Sets the pen size and color. 51 | - Draws a semicircle with radius r and angle 180 degrees. 52 | ## 3. Set Up Turtle Canvas: 53 | 54 | - speed(0): Sets the turtle's drawing speed to fastest. 55 | - hideturtle(): Hides the turtle cursor. 56 | - bgcolor('light blue'): Sets the background color. 57 | - title('Rainbow In Python Turtle'): Sets the window title. 58 | - setup(700, 700): Sets the window size to 700 pixels by 700 pixels. 59 | ## 4. Initialize Variables: 60 | 61 | - num_colors = 49: Specifies the number of colors in the rainbow. 62 | - radius = 300: Initializes the starting radius of the arcs. 63 | - penwidth = 20 * 7 / num_colors: Calculates the pen width for each arc. 64 | - hue = 0: Initializes the hue value for color generation. 65 | ## 5. Draw Rainbow Arcs: 66 | 67 | - for i in range(num_colors):: Loops through each color. 68 | - (r, g, b) = hsv_to_rgb(hue, 1, 1): Converts HSV color (hue, saturation, value) to RGB (red, green, blue). 69 | - draw_one_color_arc(0, -100, radius, penwidth, (r, g, b)): Draws an arc with the calculated color. 70 | - radius -= (penwidth - 1): Decrements the radius for the next arc. 71 | - hue += 0.9 / num_colors: Increments the hue for the next color. 72 | ## 6. Keep Window Open: 73 | 74 | - done(): 75 | Keeps the turtle graphics window open until manually closed. 76 | ## 7. Key Points: 77 | 78 | - The code utilizes a function to create modular and reusable code for drawing arcs. 79 | - It employs the colorsys library to generate a smooth spectrum of colors based on hue values. 80 | - It adjusts the radius and pen width for each arc to create the overlapping rainbow effect. 81 | - The turtle library provides the fundamental graphics commands for drawing shapes and setting colors. 82 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class12(Make a Rainbow)/rainbow.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | from colorsys import * 3 | 4 | def draw_one_color_arc(x,y,r,pensize,color): 5 | up() 6 | goto(x+r,y) 7 | down() 8 | seth(90) 9 | pensize(pensize) 10 | pencolor(color) 11 | circle(r,180) 12 | 13 | 14 | speed(0) 15 | hideturtle() 16 | bgcolor('light blue') 17 | title('Rainbow In Python Turtle') 18 | setup(700,700) 19 | num_colors = 49 20 | 21 | radius = 300 22 | penwidth = 20*7/num_colors 23 | hue = 0 24 | 25 | for i in range(num_colors): 26 | (r,g,b) = hsv_to_rgb(hue,1,1) 27 | draw_one_color_arc(0,-100,radius,penwidth,(r,g,b)) 28 | radius -= (penwidth-1) 29 | hue += 0.9/num_colors 30 | 31 | done() 32 | 33 | 34 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class14(Make Among us)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | 3 | ```python 4 | from turtle import * 5 | 6 | BODY_COLOR = 'red' 7 | BODY_SHADOW = '' 8 | GLASS_COLOR = 'grey' 9 | GLASS_SHADOW = '' 10 | 11 | s = getscreen() 12 | tur = Turtle() 13 | 14 | tur.speed(10) 15 | 16 | def body(): 17 | tur.pensize(20) 18 | tur.fillcolor(BODY_COLOR) 19 | tur.begin_fill() 20 | 21 | tur.right(90) 22 | tur.forward(50) 23 | tur.right(180) 24 | tur.circle(40, -180) 25 | tur.right(180) 26 | tur.forward(200) 27 | tur.right(180) 28 | tur.circle(100, -180) 29 | tur.backward(20) 30 | tur.left(15) 31 | tur.circle(500, -20) 32 | tur.backward(20) 33 | tur.circle(40, -180) 34 | tur.left(7) 35 | tur.backward(50) 36 | 37 | tur.up() 38 | tur.left(90) 39 | tur.forward(10) 40 | tur.right(90) 41 | tur.down() 42 | tur.right(240) 43 | tur.circle(50, -70) 44 | 45 | tur.end_fill() 46 | 47 | def glass(): 48 | tur.up() 49 | tur.right(230) 50 | tur.forward(100) 51 | tur.left(90) 52 | tur.forward(20) 53 | tur.right(90) 54 | tur.down() 55 | 56 | tur.fillcolor(GLASS_COLOR) 57 | tur.begin_fill() 58 | 59 | tur.right(150) 60 | tur.circle(90, -55) 61 | tur.right(180) 62 | tur.forward(1) 63 | tur.right(180) 64 | tur.circle(10, -65) 65 | tur.right(180) 66 | tur.forward(110) 67 | tur.right(180) 68 | tur.circle(50, -190) 69 | tur.right(170) 70 | tur.forward(80) 71 | tur.right(180) 72 | tur.circle(45, -30) 73 | 74 | tur.end_fill() 75 | 76 | def backpack(): 77 | tur.up() 78 | tur.right(60) 79 | tur.forward(100) 80 | tur.right(90) 81 | tur.forward(75) 82 | 83 | tur.fillcolor(BODY_COLOR) 84 | tur.begin_fill() 85 | 86 | tur.down() 87 | tur.forward(30) 88 | tur.right(255) 89 | tur.circle(300, -30) 90 | tur.right(260) 91 | tur.forward(30) 92 | 93 | tur.end_fill() 94 | 95 | body() 96 | glass() 97 | backpack() 98 | tur.screen.exitonclick() 99 | ``` 100 | ## 1.Import and Setup: 101 | 102 | - from turtle import *: Brings in all functions from the turtle library for drawing graphics. 103 | 104 | ## 2. Constants: 105 | 106 | - BODY_COLOR: Set to 'red', defines the color of the robot's body and backpack. 107 | - BODY_SHADOW: Unused in this code, could potentially be used for shadows. 108 | - GLASS_COLOR: Set to 'grey', defines the color of the robot's glass. 109 | - GLASS_SHADOW: Unused in this code. 110 | ## 3.Screen and Turtle: 111 | - s = getscreen(): Creates a screen object to display the graphics. 112 | - tur = Turtle(): Creates a turtle object, the "pen" that will draw shapes. 113 | - tur.speed(10): Sets the turtle's drawing speed to 10 (medium speed). 114 | ## 4.Functions for Drawing Parts: 115 | 116 | ### body(): 117 | - Sets the pen size and fill color for the body. 118 | - Moves the turtle to draw the main body using turns, forward/backward movements, and circles. 119 | - Draws the head using a similar approach. 120 | - Finishes filling the body shape with the specified color. 121 | ### glass(): 122 | - Moves the turtle to the appropriate position for drawing the glass. 123 | - Sets the fill color for the glass. 124 | - Draws the glass shape using turns, circles, and forward movements. 125 | - Finishes filling the glass with the specified color. 126 | ### backpack(): 127 | - Moves the turtle to the position for drawing the backpack. 128 | - Sets the fill color for the backpack (using the same color as the body). 129 | - Draws the backpack shape using forward and curved movements. 130 | - Finishes filling the backpack. 131 | ## 5.Main Execution: 132 | 133 | Calls the functions: The code calls body(), glass(), and backpack() in that order to draw the robot's parts sequentially. 134 | Keeps the screen open: tur.screen.exitonclick() prevents the screen from closing immediately, allowing you to view the drawn robot until you click on the window. 135 | ## 6.Key Points: 136 | 137 | - The code uses the turtle library's basic drawing commands and fill functions to create the robot's parts. 138 | - It breaks down the drawing process into separate functions for better organization and modularity. 139 | - It utilizes constants for colors, making it easier to modify the robot's appearance. 140 | - The tur.speed(10) setting adjusts the turtle's drawing speed. 141 | - While unused in this code, the BODY_SHADOW and GLASS_SHADOW constants suggest the potential for adding shadows to the robot's design. 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class14(Make Among us)/amongus.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | BODY_COLOR = 'red' 4 | BODY_SHADOW = '' 5 | GLASS_COLOR = 'grey' 6 | GLASS_SHADOW = '' 7 | 8 | s = getscreen() 9 | tur = Turtle() 10 | 11 | tur.speed(10) 12 | 13 | def body(): 14 | tur.pensize(20) 15 | tur.fillcolor(BODY_COLOR) 16 | tur.begin_fill() 17 | 18 | tur.right(90) 19 | tur.forward(50) 20 | tur.right(180) 21 | tur.circle(40, -180) 22 | tur.right(180) 23 | tur.forward(200) 24 | tur.right(180) 25 | tur.circle(100, -180) 26 | tur.backward(20) 27 | tur.left(15) 28 | tur.circle(500, -20) 29 | tur.backward(20) 30 | tur.circle(40, -180) 31 | tur.left(7) 32 | tur.backward(50) 33 | 34 | tur.up() 35 | tur.left(90) 36 | tur.forward(10) 37 | tur.right(90) 38 | tur.down() 39 | tur.right(240) 40 | tur.circle(50, -70) 41 | 42 | tur.end_fill() 43 | 44 | def glass(): 45 | tur.up() 46 | tur.right(230) 47 | tur.forward(100) 48 | tur.left(90) 49 | tur.forward(20) 50 | tur.right(90) 51 | tur.down() 52 | 53 | tur.fillcolor(GLASS_COLOR) 54 | tur.begin_fill() 55 | 56 | tur.right(150) 57 | tur.circle(90, -55) 58 | tur.right(180) 59 | tur.forward(1) 60 | tur.right(180) 61 | tur.circle(10, -65) 62 | tur.right(180) 63 | tur.forward(110) 64 | tur.right(180) 65 | tur.circle(50, -190) 66 | tur.right(170) 67 | tur.forward(80) 68 | tur.right(180) 69 | tur.circle(45, -30) 70 | 71 | tur.end_fill() 72 | 73 | def backpack(): 74 | tur.up() 75 | tur.right(60) 76 | tur.forward(100) 77 | tur.right(90) 78 | tur.forward(75) 79 | 80 | tur.fillcolor(BODY_COLOR) 81 | tur.begin_fill() 82 | 83 | tur.down() 84 | tur.forward(30) 85 | tur.right(255) 86 | tur.circle(300, -30) 87 | tur.right(260) 88 | tur.forward(30) 89 | 90 | tur.end_fill() 91 | 92 | body() 93 | glass() 94 | backpack() 95 | tur.screen.exitonclick() 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class15(Make a Spiderman)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | 5 | speed(13) # Painting speed control 6 | bgcolor("#990000") 7 | pensize(10) 8 | penup() 9 | goto(0,50) 10 | pendown() 11 | circle(-120) 12 | penup() 13 | circle(-120,-60) 14 | pendown() 15 | pensize(5) 16 | right(50) 17 | circle(70,55) 18 | right(85) 19 | circle(75,58) 20 | right(90) 21 | circle(70,55) 22 | right(90) 23 | circle(70,58) 24 | 25 | # body 26 | penup() 27 | pensize(10) 28 | goto(80,15) 29 | pendown() 30 | seth(92) 31 | fd(135) 32 | seth(125) 33 | circle(30,135) 34 | seth(190) 35 | fd(50) 36 | seth(125) 37 | circle(30,135) 38 | seth(275) 39 | fd(90) 40 | 41 | # Arm 1 42 | penup() 43 | pensize(10) 44 | goto(92,-150) 45 | seth(240) 46 | pendown() 47 | fd(80) 48 | left(10) 49 | circle(-28,185) 50 | 51 | # Arm 2 52 | penup() 53 | goto(0,50) 54 | seth(0) 55 | pensize(10) 56 | circle(-120,-60) 57 | seth(200) 58 | pendown() 59 | fd(72) 60 | left(20) 61 | circle(30,150) 62 | left(20) 63 | fd(20) 64 | right(15) 65 | fd(10) 66 | pensize(5) 67 | fillcolor("#3366cc") 68 | begin_fill() 69 | seth(92) 70 | circle(-120,31) 71 | seth(200) 72 | fd(45) 73 | left(90) 74 | fd(52) 75 | end_fill() 76 | fd(-12) 77 | right(90) 78 | fd(40) 79 | penup() 80 | right(90) 81 | fd(18) 82 | pendown() 83 | right(86) 84 | fd(40) 85 | penup() 86 | goto(-152,-86) 87 | pendown() 88 | left(40) 89 | circle(35,90) 90 | # Body coloring 91 | penup() 92 | goto(-80,116) 93 | seth(10) 94 | pensize(5) 95 | pendown() 96 | begin_fill() 97 | fillcolor("#3366cc") 98 | fd(155) 99 | seth(-88) 100 | fd(37) 101 | seth(195) 102 | fd(156) 103 | end_fill() 104 | penup() 105 | goto(-75,38) 106 | seth(15) 107 | pendown() 108 | begin_fill() 109 | fd(158) 110 | seth(-88) 111 | fd(55) 112 | seth(140) 113 | circle(120,78) 114 | end_fill() 115 | # Arm 1 To color 116 | penup() 117 | fillcolor("#3366cc") 118 | pensize(5) 119 | goto(75,-170) 120 | pendown() 121 | begin_fill() 122 | seth(240) 123 | fd(30) 124 | right(90) 125 | fd(17) 126 | end_fill() 127 | fd(10) 128 | left(80) 129 | fd(55) 130 | penup() 131 | left(90) 132 | fd(15) 133 | pendown() 134 | left(85) 135 | fd(55) 136 | penup() 137 | goto(43,-225) 138 | left(84) 139 | pendown() 140 | circle(60,51) 141 | speed(0) 142 | 143 | # Body vertical lines 144 | for i in range(3): 145 | penup() 146 | goto(-70+i*15,135) 147 | seth(-90) 148 | pendown() 149 | pensize(5) 150 | fd(15-2*i) 151 | 152 | for i in range(3): 153 | penup() 154 | goto(36 + i * 15, 156) 155 | seth(-90) 156 | pendown() 157 | pensize(5) 158 | fd(15 - 2 * i) 159 | a = -60 160 | b = 70 161 | 162 | for i in range(4): 163 | penup() 164 | goto(a,b) 165 | a=a+40 166 | b=b+10 167 | seth(-90) 168 | pendown() 169 | pensize(5) 170 | fd(26) 171 | 172 | def oo (li,jing): 173 | penup() 174 | goto(0,50) 175 | seth(0) 176 | circle(-120, li) 177 | pendown() 178 | right(jing) 179 | pensize(5) 180 | oo(-60,110) 181 | fd(130) 182 | oo(-28,96) 183 | fd(140) 184 | oo(9,89) 185 | fd(144) 186 | oo(42,70) 187 | fd(160) 188 | oo(80,60) 189 | fd(130) 190 | penup() 191 | goto(-80,-40) 192 | right(160) 193 | pendown() 194 | right(50) 195 | circle(70,45) 196 | right(75) 197 | circle(70,38) 198 | right(50) 199 | circle(70,45) 200 | right(90) 201 | circle(70,48) 202 | penup() 203 | goto(-53,-70) 204 | pendown() 205 | left(40) 206 | circle(70,30) 207 | right(50) 208 | circle(70,20) 209 | right(50) 210 | circle(70,38) 211 | right(70) 212 | circle(70,24) 213 | penup() 214 | goto(-19,-105) 215 | left(72) 216 | pendown() 217 | fd(22) 218 | right(60) 219 | fd(22) 220 | oo(-140,80) 221 | circle(-90,120) 222 | penup() 223 | oo(140,100) 224 | circle(90,13) 225 | pendown() 226 | 227 | 228 | right(-50) 229 | circle(70,45) 230 | right(75) 231 | circle(70,38) 232 | right(50) 233 | circle(70,36) 234 | penup() 235 | goto(22,-185) 236 | right(70) 237 | pendown() 238 | fd(72) 239 | penup() 240 | goto(-40,-182) 241 | right(38) 242 | pendown() 243 | fd(70) 244 | speed(10) 245 | # The left eye 246 | penup() 247 | pensize(7) 248 | goto(-15,-110) 249 | seth(0) 250 | pendown() 251 | pensize(10) 252 | begin_fill() 253 | left(130) 254 | fd(110) 255 | right(250) 256 | circle(90,60) 257 | circle(40,120) 258 | fillcolor("#F5FFFA") 259 | end_fill() 260 | 261 | # Right eye 262 | penup() 263 | goto(5,-110) 264 | pendown() 265 | begin_fill() 266 | right(30) 267 | fd(110) 268 | right(-250) 269 | circle(-90,60) 270 | circle(-40,120) 271 | end_fill() 272 | done() 273 | 274 | 275 | ``` 276 | 277 | # Explaination: 278 | 279 | ## 1. Initialization: 280 | 281 | - Imports the turtle library for drawing. 282 | - Sets the turtle's speed to 13 for a moderate drawing pace. 283 | - Sets the background color to "#990000" (a dark red). 284 | - Sets the pen size to 10 for thicker lines. 285 | ## 2. Head Drawing: 286 | 287 | - Positions the turtle and draws a large circle for the head. 288 | - Uses smaller circles and curves to create facial features (eyes, mouth). 289 | ## 3. Body Drawing: 290 | 291 | - Moves the turtle and draws the body with curves and straight lines. 292 | - Fills in the body with the color "#3366cc" (a light blue). 293 | ## 4. Arm Drawing: 294 | 295 | - Draws two arms using lines and curves. 296 | - Fills in the first arm with the same blue color. 297 | ## 5. Body Details: 298 | 299 | - Adds vertical lines to the body for texture. 300 | - Draws a series of smaller circles and shapes for additional accents. 301 | ## 6. Feet Drawing: 302 | 303 | - Uses a function named oo to create multiple curved shapes for the feet. 304 | - Draws additional lines and shapes to complete the feet. 305 | ## 7. Eye Drawing: 306 | 307 | - Positions the turtle and draws the left eye using a filled shape. 308 | - Draws the right eye in a similar fashion. 309 | ## 8. Finalization: 310 | 311 | - Sets the turtle's speed to 10 to slow down the drawing process (likely for visibility). 312 | - Keeps the window open until the user clicks on it using done(). 313 | ## 9. Key Points: 314 | 315 | - The code heavily relies on the turtle library's functions for drawing and movement. 316 | - It uses a custom function oo to simplify the drawing of repetitive shapes. 317 | - It employs various techniques like filling, pen size adjustments, and positioning to create the desired visual elements. 318 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class15(Make a Spiderman)/spiderman.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/11_Class(Python Graphics)/Python Graphic projects/Class15(Make a Spiderman)/spiderman.py -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class16(Make a Doraemon)/Readme.md: -------------------------------------------------------------------------------- 1 | ## Code structure 2 | ```python 3 | from turtle import * 4 | 5 | 6 | # Doraemon with Python Turtle 7 | def ankle(x, y): 8 | penup() 9 | goto(x, y) 10 | pendown() 11 | 12 | 13 | def eyes(): 14 | fillcolor("#ffffff") 15 | begin_fill() 16 | 17 | tracer(False) 18 | a = 2.5 19 | for i in range(120): 20 | if 0 <= i < 30 or 60 <= i < 90: 21 | a -= 0.05 22 | lt(3) 23 | fd(a) 24 | else: 25 | a += 0.05 26 | lt(3) 27 | fd(a) 28 | tracer(True) 29 | end_fill() 30 | 31 | 32 | def daari(): 33 | ankle(-32, 135) 34 | seth(165) 35 | fd(60) 36 | 37 | ankle(-32, 125) 38 | seth(180) 39 | fd(60) 40 | 41 | ankle(-32, 115) 42 | seth(193) 43 | fd(60) 44 | 45 | ankle(37, 135) 46 | seth(15) 47 | fd(60) 48 | 49 | ankle(37, 125) 50 | seth(0) 51 | fd(60) 52 | 53 | ankle(37, 115) 54 | seth(-13) 55 | fd(60) 56 | 57 | 58 | def mukh(): 59 | ankle(5, 148) 60 | seth(270) 61 | fd(100) 62 | seth(0) 63 | circle(120, 50) 64 | seth(230) 65 | circle(-120, 100) 66 | 67 | 68 | def scarf(): 69 | fillcolor('#e70010') 70 | begin_fill() 71 | seth(0) 72 | fd(200) 73 | circle(-5, 90) 74 | fd(10) 75 | circle(-5, 90) 76 | fd(207) 77 | circle(-5, 90) 78 | fd(10) 79 | circle(-5, 90) 80 | end_fill() 81 | 82 | 83 | def nose(): 84 | ankle(-10, 158) 85 | seth(315) 86 | fillcolor('#e70010') 87 | begin_fill() 88 | circle(20) 89 | end_fill() 90 | 91 | 92 | def black_eyes(): 93 | seth(0) 94 | ankle(-20, 195) 95 | fillcolor('#000000') 96 | begin_fill() 97 | circle(13) 98 | end_fill() 99 | 100 | pensize(6) 101 | ankle(20, 205) 102 | seth(75) 103 | circle(-10, 150) 104 | pensize(3) 105 | 106 | ankle(-17, 200) 107 | seth(0) 108 | fillcolor('#ffffff') 109 | begin_fill() 110 | circle(5) 111 | end_fill() 112 | ankle(0, 0) 113 | 114 | 115 | def face(): 116 | fd(183) 117 | lt(45) 118 | fillcolor('#ffffff') 119 | begin_fill() 120 | circle(120, 100) 121 | seth(180) 122 | # print(pos()) 123 | fd(121) 124 | pendown() 125 | seth(215) 126 | circle(120, 100) 127 | end_fill() 128 | ankle(63.56, 218.24) 129 | seth(90) 130 | eyes() 131 | seth(180) 132 | penup() 133 | fd(60) 134 | pendown() 135 | seth(90) 136 | eyes() 137 | penup() 138 | seth(180) 139 | fd(64) 140 | 141 | 142 | def taauko(): 143 | penup() 144 | circle(150, 40) 145 | pendown() 146 | fillcolor('#00a0de') 147 | begin_fill() 148 | circle(150, 280) 149 | end_fill() 150 | 151 | 152 | def Doraemon(): 153 | taauko() 154 | 155 | scarf() 156 | 157 | face() 158 | 159 | nose() 160 | 161 | mukh() 162 | 163 | daari() 164 | 165 | ankle(0, 0) 166 | 167 | seth(0) 168 | penup() 169 | circle(150, 50) 170 | pendown() 171 | seth(30) 172 | fd(40) 173 | seth(70) 174 | circle(-30, 270) 175 | 176 | fillcolor('#00a0de') 177 | begin_fill() 178 | 179 | seth(230) 180 | fd(80) 181 | seth(90) 182 | circle(1000, 1) 183 | seth(-89) 184 | circle(-1000, 10) 185 | 186 | # print(pos()) 187 | 188 | seth(180) 189 | fd(70) 190 | seth(90) 191 | circle(30, 180) 192 | seth(180) 193 | fd(70) 194 | 195 | # print(pos()) 196 | seth(100) 197 | circle(-1000, 9) 198 | 199 | seth(-86) 200 | circle(1000, 2) 201 | seth(230) 202 | fd(40) 203 | 204 | # print(pos()) 205 | 206 | circle(-30, 230) 207 | seth(45) 208 | fd(81) 209 | seth(0) 210 | fd(203) 211 | circle(5, 90) 212 | fd(10) 213 | circle(5, 90) 214 | fd(7) 215 | seth(40) 216 | circle(150, 10) 217 | seth(30) 218 | fd(40) 219 | end_fill() 220 | 221 | seth(70) 222 | fillcolor('#ffffff') 223 | begin_fill() 224 | circle(-30) 225 | end_fill() 226 | 227 | ankle(103.74, -182.59) 228 | seth(0) 229 | fillcolor('#ffffff') 230 | begin_fill() 231 | fd(15) 232 | circle(-15, 180) 233 | fd(90) 234 | circle(-15, 180) 235 | fd(10) 236 | end_fill() 237 | 238 | ankle(-96.26, -182.59) 239 | seth(180) 240 | fillcolor('#ffffff') 241 | begin_fill() 242 | fd(15) 243 | circle(15, 180) 244 | fd(90) 245 | circle(15, 180) 246 | fd(10) 247 | end_fill() 248 | 249 | ankle(-133.97, -91.81) 250 | seth(50) 251 | fillcolor('#ffffff') 252 | begin_fill() 253 | circle(30) 254 | end_fill() 255 | # Doraemon with Python Turtle 256 | 257 | ankle(-103.42, 15.09) 258 | seth(0) 259 | fd(38) 260 | seth(230) 261 | begin_fill() 262 | circle(90, 260) 263 | end_fill() 264 | 265 | ankle(5, -40) 266 | seth(0) 267 | fd(70) 268 | seth(-90) 269 | circle(-70, 180) 270 | seth(0) 271 | fd(70) 272 | 273 | ankle(-103.42, 15.09) 274 | fd(90) 275 | seth(70) 276 | fillcolor('#ffd200') 277 | # print(pos()) 278 | begin_fill() 279 | circle(-20) 280 | end_fill() 281 | seth(170) 282 | fillcolor('#ffd200') 283 | begin_fill() 284 | circle(-2, 180) 285 | seth(10) 286 | circle(-100, 22) 287 | circle(-2, 180) 288 | seth(180 - 10) 289 | circle(100, 22) 290 | end_fill() 291 | goto(-13.42, 15.09) 292 | seth(250) 293 | circle(20, 110) 294 | seth(90) 295 | fd(15) 296 | dot(10) 297 | ankle(0, -150) 298 | 299 | black_eyes() 300 | 301 | 302 | if __name__ == '__main__': 303 | screensize(800, 600, "#f0f0f0") 304 | pensize(3) 305 | speed(9) 306 | Doraemon() 307 | ankle(100, -300) 308 | mainloop() 309 | 310 | done() 311 | ``` 312 | 313 | Explaination: 314 | 315 | ## 1. Import and Setup: 316 | 317 | - Imports the turtle module: from turtle import * 318 | - Sets screen size and background color: screensize(800, 600, "#f0f0f0") 319 | - Sets pen size and speed: pensize(3), speed(9) 320 | ## 2. Helper Functions: 321 | 322 | - ankle(x, y): Moves the turtle to the specified coordinates without drawing. 323 | - eyes(): Draws Doraemon's eyes using a loop to create smooth curves. 324 | - daari(): Draws the whiskers on Doraemon's face. 325 | - mukh(): Draws the mouth. 326 | - scarf(): Draws the red scarf. 327 | - nose(): Draws the red nose. 328 | - black_eyes(): Draws the black pupils and highlights in the eyes. 329 | - face(): Draws the face, including the white fur and eyes. 330 | - taauko(): Draws the blue head. 331 | ## 3. Main Drawing Function: 332 | 333 | - Doraemon(): Calls the helper functions in a specific order to create the complete Doraemon drawing. 334 | ## 4. Main Execution: 335 | 336 | - Calls the Doraemon() function: Doraemon() 337 | - Positions the turtle for future drawings: ankle(100, -300) 338 | - Keeps the drawing window open: mainloop() 339 | - Prevents the window from closing immediately: done() 340 | ## 5.Key Points: 341 | 342 | - The code uses the turtle library to create graphics by moving a virtual "turtle" around the screen. 343 | - It breaks down the drawing process into modular functions for better organization. 344 | - It employs various turtle commands like forward(), backward(), left(), right(), circle(), fillcolor(), and begin_fill() to create shapes and colors. 345 | - The speed() function controls the drawing speed, and tracer(False) temporarily disables screen updates for smoother eye drawing. 346 | -------------------------------------------------------------------------------- /11_Class(Python Graphics)/Python Graphic projects/Class16(Make a Doraemon)/doremon.py: -------------------------------------------------------------------------------- 1 | from turtle import * 2 | 3 | 4 | # Doraemon with Python Turtle 5 | def ankle(x, y): 6 | penup() 7 | goto(x, y) 8 | pendown() 9 | 10 | 11 | def eyes(): 12 | fillcolor("#ffffff") 13 | begin_fill() 14 | 15 | tracer(False) 16 | a = 2.5 17 | for i in range(120): 18 | if 0 <= i < 30 or 60 <= i < 90: 19 | a -= 0.05 20 | lt(3) 21 | fd(a) 22 | else: 23 | a += 0.05 24 | lt(3) 25 | fd(a) 26 | tracer(True) 27 | end_fill() 28 | 29 | 30 | def daari(): 31 | ankle(-32, 135) 32 | seth(165) 33 | fd(60) 34 | 35 | ankle(-32, 125) 36 | seth(180) 37 | fd(60) 38 | 39 | ankle(-32, 115) 40 | seth(193) 41 | fd(60) 42 | 43 | ankle(37, 135) 44 | seth(15) 45 | fd(60) 46 | 47 | ankle(37, 125) 48 | seth(0) 49 | fd(60) 50 | 51 | ankle(37, 115) 52 | seth(-13) 53 | fd(60) 54 | 55 | 56 | def mukh(): 57 | ankle(5, 148) 58 | seth(270) 59 | fd(100) 60 | seth(0) 61 | circle(120, 50) 62 | seth(230) 63 | circle(-120, 100) 64 | 65 | 66 | def scarf(): 67 | fillcolor('#e70010') 68 | begin_fill() 69 | seth(0) 70 | fd(200) 71 | circle(-5, 90) 72 | fd(10) 73 | circle(-5, 90) 74 | fd(207) 75 | circle(-5, 90) 76 | fd(10) 77 | circle(-5, 90) 78 | end_fill() 79 | 80 | 81 | def nose(): 82 | ankle(-10, 158) 83 | seth(315) 84 | fillcolor('#e70010') 85 | begin_fill() 86 | circle(20) 87 | end_fill() 88 | 89 | 90 | def black_eyes(): 91 | seth(0) 92 | ankle(-20, 195) 93 | fillcolor('#000000') 94 | begin_fill() 95 | circle(13) 96 | end_fill() 97 | 98 | pensize(6) 99 | ankle(20, 205) 100 | seth(75) 101 | circle(-10, 150) 102 | pensize(3) 103 | 104 | ankle(-17, 200) 105 | seth(0) 106 | fillcolor('#ffffff') 107 | begin_fill() 108 | circle(5) 109 | end_fill() 110 | ankle(0, 0) 111 | 112 | 113 | def face(): 114 | fd(183) 115 | lt(45) 116 | fillcolor('#ffffff') 117 | begin_fill() 118 | circle(120, 100) 119 | seth(180) 120 | # print(pos()) 121 | fd(121) 122 | pendown() 123 | seth(215) 124 | circle(120, 100) 125 | end_fill() 126 | ankle(63.56, 218.24) 127 | seth(90) 128 | eyes() 129 | seth(180) 130 | penup() 131 | fd(60) 132 | pendown() 133 | seth(90) 134 | eyes() 135 | penup() 136 | seth(180) 137 | fd(64) 138 | 139 | 140 | def taauko(): 141 | penup() 142 | circle(150, 40) 143 | pendown() 144 | fillcolor('#00a0de') 145 | begin_fill() 146 | circle(150, 280) 147 | end_fill() 148 | 149 | 150 | def Doraemon(): 151 | taauko() 152 | 153 | scarf() 154 | 155 | face() 156 | 157 | nose() 158 | 159 | mukh() 160 | 161 | daari() 162 | 163 | ankle(0, 0) 164 | 165 | seth(0) 166 | penup() 167 | circle(150, 50) 168 | pendown() 169 | seth(30) 170 | fd(40) 171 | seth(70) 172 | circle(-30, 270) 173 | 174 | fillcolor('#00a0de') 175 | begin_fill() 176 | 177 | seth(230) 178 | fd(80) 179 | seth(90) 180 | circle(1000, 1) 181 | seth(-89) 182 | circle(-1000, 10) 183 | 184 | # print(pos()) 185 | 186 | seth(180) 187 | fd(70) 188 | seth(90) 189 | circle(30, 180) 190 | seth(180) 191 | fd(70) 192 | 193 | # print(pos()) 194 | seth(100) 195 | circle(-1000, 9) 196 | 197 | seth(-86) 198 | circle(1000, 2) 199 | seth(230) 200 | fd(40) 201 | 202 | # print(pos()) 203 | 204 | circle(-30, 230) 205 | seth(45) 206 | fd(81) 207 | seth(0) 208 | fd(203) 209 | circle(5, 90) 210 | fd(10) 211 | circle(5, 90) 212 | fd(7) 213 | seth(40) 214 | circle(150, 10) 215 | seth(30) 216 | fd(40) 217 | end_fill() 218 | 219 | seth(70) 220 | fillcolor('#ffffff') 221 | begin_fill() 222 | circle(-30) 223 | end_fill() 224 | 225 | ankle(103.74, -182.59) 226 | seth(0) 227 | fillcolor('#ffffff') 228 | begin_fill() 229 | fd(15) 230 | circle(-15, 180) 231 | fd(90) 232 | circle(-15, 180) 233 | fd(10) 234 | end_fill() 235 | 236 | ankle(-96.26, -182.59) 237 | seth(180) 238 | fillcolor('#ffffff') 239 | begin_fill() 240 | fd(15) 241 | circle(15, 180) 242 | fd(90) 243 | circle(15, 180) 244 | fd(10) 245 | end_fill() 246 | 247 | ankle(-133.97, -91.81) 248 | seth(50) 249 | fillcolor('#ffffff') 250 | begin_fill() 251 | circle(30) 252 | end_fill() 253 | # Doraemon with Python Turtle 254 | 255 | ankle(-103.42, 15.09) 256 | seth(0) 257 | fd(38) 258 | seth(230) 259 | begin_fill() 260 | circle(90, 260) 261 | end_fill() 262 | 263 | ankle(5, -40) 264 | seth(0) 265 | fd(70) 266 | seth(-90) 267 | circle(-70, 180) 268 | seth(0) 269 | fd(70) 270 | 271 | ankle(-103.42, 15.09) 272 | fd(90) 273 | seth(70) 274 | fillcolor('#ffd200') 275 | # print(pos()) 276 | begin_fill() 277 | circle(-20) 278 | end_fill() 279 | seth(170) 280 | fillcolor('#ffd200') 281 | begin_fill() 282 | circle(-2, 180) 283 | seth(10) 284 | circle(-100, 22) 285 | circle(-2, 180) 286 | seth(180 - 10) 287 | circle(100, 22) 288 | end_fill() 289 | goto(-13.42, 15.09) 290 | seth(250) 291 | circle(20, 110) 292 | seth(90) 293 | fd(15) 294 | dot(10) 295 | ankle(0, -150) 296 | 297 | black_eyes() 298 | 299 | 300 | if __name__ == '__main__': 301 | screensize(800, 600, "#f0f0f0") 302 | pensize(3) 303 | speed(9) 304 | Doraemon() 305 | ankle(100, -300) 306 | mainloop() 307 | 308 | done() 309 | 310 | 311 | 312 | 313 | -------------------------------------------------------------------------------- /12-ContinueBreakPass.py: -------------------------------------------------------------------------------- 1 | #Use of Continue, Break, Pass 2 | ''' 3 | terminate the current "iteration" or even the "whole loop" without 4 | checking test expression. 5 | ''' 6 | #Continue 7 | #The continue statement is used to skip current iteration 8 | # Program to show the use of continue statement inside loops 9 | #Example1 10 | for val in "string": 11 | if val == "i": 12 | continue 13 | print(val) 14 | 15 | ''' 16 | s 17 | t 18 | r 19 | n 20 | g 21 | ''' 22 | #Example2 23 | for i in range(1, 11): 24 | if i == 5: 25 | continue 26 | print( i," ",end="" ) 27 | ''' 28 | 1 2 3 4 6 7 8 9 10 29 | ''' 30 | #Break 31 | ''' 32 | The break statement terminates the loop containing it. 33 | If the break statement is inside a nested loop, 34 | the break statement will terminate the innermost loop. 35 | ''' 36 | # Use of break statement inside the loop 37 | #Example1 38 | for val in "string": 39 | if val == "i": 40 | break 41 | print(val) 42 | ''' 43 | s 44 | t 45 | r 46 | ''' 47 | 48 | #Example2 49 | n=2 50 | while 1: 51 | i=1; 52 | while i<=10: 53 | print("%d X %d = %d\n"%(n,i,n*i)) 54 | i = i+1; 55 | choice = int(input("Do you want to continue printing the table, press 0 for no?")) 56 | if choice == 0: 57 | break 58 | n=n+1 59 | ''' 60 | 2 X 1 = 2 61 | 2 X 2 = 4 62 | 2 X 3 = 6 63 | 2 X 4 = 8 64 | 2 X 5 = 10 65 | 2 X 6 = 12 66 | 2 X 7 = 14 67 | 2 X 8 = 16 68 | 2 X 9 = 18 69 | 2 X 10 = 20 70 | Do you want to continue printing the table, press 0 for no? 71 | ''' 72 | #Pass Statement 73 | ''' 74 | In Python programming, the pass statement is a null statement. 75 | The difference between a "comment" and a pass statement in 76 | Python is that while the interpreter ignores a comment entirely, 77 | "pass" is not ignored. 78 | 79 | However, nothing happens when the pass is executed. 80 | It results in no operation 81 | ''' 82 | sequence = {'p', 'a', 's', 's'} 83 | for val in sequence: 84 | pass 85 | -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part1.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part2.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part3.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Garbage Collection/Circular References/Circular References Part4.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Garbage Collection/main.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import gc 3 | 4 | 5 | def getrefcount(address): 6 | return ctypes.c_long.from_address(address).value 7 | 8 | 9 | def object_by_id(object_id): 10 | for obj in gc.get_objects(): 11 | if id(obj) == object_id: 12 | return "Object Exists" 13 | else: 14 | return "Object Does Not Exists" 15 | 16 | 17 | class A: 18 | def __init__(self): 19 | self.b = B(self) 20 | print(f'A : Self {hex(id(self))} b: {hex(id(self.b))}') 21 | 22 | 23 | class B: 24 | def __init__(self, a): 25 | self.a = a 26 | print(f'B : Self {hex(id(self))} a: {hex(id(self.a))}') 27 | 28 | 29 | gc.disable() 30 | print('---------------------------------') 31 | my_var = A() 32 | print('---------------------------------') 33 | print('------------------') 34 | print(hex(id(my_var))) 35 | print(hex(id(my_var.b))) 36 | print(hex(id(my_var.b.a))) 37 | print('------------------') 38 | id_a = id(my_var) 39 | id_b = id(my_var.b) 40 | print(hex((id_a))) 41 | print(hex((id_b))) 42 | print('------------------') 43 | print(getrefcount(id_a)) 44 | print(getrefcount(id_b)) 45 | print('------------------') 46 | print(object_by_id(id_a)) 47 | print('------------------') 48 | print(object_by_id(id_b)) 49 | print('------------------') 50 | my_var = None 51 | print(getrefcount(id_a)) 52 | print('------------------') 53 | print(getrefcount(id_b)) 54 | print('------------------') 55 | print(object_by_id(id_a)) 56 | print('------------------') 57 | print(object_by_id(id_b)) 58 | print('------------------') 59 | gc.collect() 60 | print('------------------') 61 | print(object_by_id(id_a)) 62 | print('------------------') 63 | print(object_by_id(id_b)) 64 | print('------------------') 65 | -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Garbage Collection/readme.md: -------------------------------------------------------------------------------- 1 | # Circular References in Garbage Collection 2 | -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/main.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import sys 3 | a = [1, 2, 3] 4 | print(f'Address of A = {id(a)}') 5 | # print(f'Reference of A = {sys.getrefcount(a)}') 6 | 7 | # b = a 8 | # print(f'Address of A = {id(a)}') 9 | # print(f'Reference of A = {sys.getrefcount(a)}') 10 | 11 | a = [1, 2, 3] 12 | 13 | 14 | def getrefcount(address: int) -> int: 15 | return ctypes.c_long.from_address(address).value 16 | 17 | 18 | print(f'Reference count of a is {getrefcount(id(a))}') 19 | b = a 20 | print('b = a') 21 | print(f'Address of B = {id(b)}') 22 | print(f'Reference count of a is {getrefcount(id(a))}') 23 | c = a 24 | print('c = a') 25 | print(f'Address of C = {id(c)}') 26 | print(f'Reference count of a is {getrefcount(id(a))}') 27 | c = 12 28 | print('c = 12') 29 | print(f'Address of C = {id(c)}') 30 | print(f'Reference count of a is {getrefcount(id(a))}') 31 | b = None 32 | print('b = None') 33 | print(f'Address of B = {id(b)}') 34 | print(f'id of b {id(b)}') 35 | print(f'Reference count of a is {getrefcount(id(a))}') 36 | a_id = id(a) 37 | a = None 38 | print(f'Reference count of a_id is {getrefcount(id(a_id))}') 39 | -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/readme.md: -------------------------------------------------------------------------------- 1 | # Reference Counting 2 | -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part1.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part2.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part3.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part4.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part5.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part6.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part7.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/12_Class(Python Garbage Collector)/Reference Counting/refcount/Reference Count Part8.png -------------------------------------------------------------------------------- /12_Class(Python Garbage Collector)/readme.md: -------------------------------------------------------------------------------- 1 | # Garbage Collector and Reference Count 2 | 3 | ## Reference Link 4 | [ReferenceLink](https://devguide.python.org/internals/garbage-collector/index.html) -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/images/Uncorrect way of copying ex1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/images/Uncorrect way of copying ex1.png -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/images/Uncorrect way of copying ex2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/images/Uncorrect way of copying ex2.png -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/images/Uncorrect way of copying ex3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/images/Uncorrect way of copying ex3.png -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/main.py: -------------------------------------------------------------------------------- 1 | # Define a list of nested lists 2 | l1 = [['Hashim', 'Tahir', 24], [1, 2, 3], ['x', True, 97.5]] 3 | 4 | print('List 1') 5 | print(f'Address of List 1 = {hex(id(l1))}') 6 | print(f'Address of List 1[0] index = {hex(id(l1[0]))}') 7 | print(f'Address of List 1[0] index item[0] = {hex(id(l1[0][0]))}') 8 | print(f'Address of List 1[0] index item[1] = {hex(id(l1[0][1]))}') 9 | print(f'Address of List 1[0] index item[2] = {hex(id(l1[0][2]))}') 10 | print('-----------------------------------------------------------') 11 | print(f'Address of List 1[1] index = {hex(id(l1[1]))}') 12 | print(f'Address of List 1[1] index item[0] = {hex(id(l1[1][0]))}') 13 | print(f'Address of List 1[1] index item[1] = {hex(id(l1[1][1]))}') 14 | print(f'Address of List 1[1] index item[2] = {hex(id(l1[1][2]))}') 15 | print('-----------------------------------------------------------') 16 | print(f'Address of List 1[2] index = {hex(id(l1[2]))}') 17 | print(f'Address of List 1[2] index item[0] = {hex(id(l1[2][0]))}') 18 | print(f'Address of List 1[2] index item[1] = {hex(id(l1[2][1]))}') 19 | print(f'Address of List 1[2] index item[2] = {hex(id(l1[2][2]))}') 20 | print('-----------------------------------------------------------') 21 | print('End of the first list') 22 | 23 | l2 = l1 24 | print('List 2') 25 | print(f'Address of List 2 = {hex(id(l2))}') 26 | print(f'Address of List 2[0] index = {hex(id(l2[0]))}') 27 | print(f'Address of List 2[0] index item[0] = {hex(id(l2[0][0]))}') 28 | print(f'Address of List 2[0] index item[1] = {hex(id(l2[0][1]))}') 29 | print(f'Address of List 2[0] index item[2] = {hex(id(l2[0][2]))}') 30 | print('-----------------------------------------------------------') 31 | print(f'Address of List 2[1] index = {hex(id(l2[1]))}') 32 | print(f'Address of List 2[1] index item[0] = {hex(id(l2[1][0]))}') 33 | print(f'Address of List 2[1] index item[1] = {hex(id(l2[1][1]))}') 34 | print(f'Address of List 2[1] index item[2] = {hex(id(l2[1][2]))}') 35 | print('-----------------------------------------------------------') 36 | print(f'Address of List 2[2] index = {hex(id(l2[2]))}') 37 | print(f'Address of List 2[2] index item[0] = {hex(id(l2[2][0]))}') 38 | print(f'Address of List 2[2] index item[1] = {hex(id(l2[2][1]))}') 39 | print(f'Address of List 2[2] index item[2] = {hex(id(l2[2][2]))}') 40 | print('-----------------------------------------------------------') 41 | print('End of the Second list') 42 | -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class01(Uncorrect way of copying)/readme.md: -------------------------------------------------------------------------------- 1 | # Uncorrect way of copying thing -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class02(Shallow Copy)/Shallow Copy Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/13_Class(Deep and Shallow Copy)/Class02(Shallow Copy)/Shallow Copy Example.png -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class02(Shallow Copy)/main.py: -------------------------------------------------------------------------------- 1 | import copy 2 | l1 = [['Hashim', 24], [1, 3]] 3 | 4 | print('List 1') 5 | print(f'Address of List 1 = {hex(id(l1))}') 6 | print(f'Address of List 1[0] index = {hex(id(l1[0]))}') 7 | print(f'Address of List 1[0] index item[0] = {hex(id(l1[0][0]))}') 8 | print(f'Address of List 1[0] index item[1] = {hex(id(l1[0][1]))}') 9 | print('-----------------------------------------------------------') 10 | print(f'Address of List 1[1] index = {hex(id(l1[1]))}') 11 | print(f'Address of List 1[1] index item[0] = {hex(id(l1[1][0]))}') 12 | print(f'Address of List 1[1] index item[1] = {hex(id(l1[1][1]))}') 13 | print('-----------------------------------------------------------') 14 | print('End of the first list') 15 | 16 | l2 = copy.copy(l1) 17 | print('List 2') 18 | print(f'Address of List 2 = {hex(id(l2))}') 19 | print(f'Address of List 2[0] index = {hex(id(l2[0]))}') 20 | print(f'Address of List 2[0] index item[0] = {hex(id(l2[0][0]))}') 21 | print(f'Address of List 2[0] index item[1] = {hex(id(l2[0][1]))}') 22 | print('-----------------------------------------------------------') 23 | print(f'Address of List 2[1] index = {hex(id(l2[1]))}') 24 | print(f'Address of List 2[1] index item[0] = {hex(id(l2[1][0]))}') 25 | print(f'Address of List 2[1] index item[1] = {hex(id(l2[1][1]))}') 26 | print('-----------------------------------------------------------') 27 | print('End of the Second list') 28 | -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class02(Shallow Copy)/readme.md: -------------------------------------------------------------------------------- 1 | # Shallow Copy in Python 2 | 3 | ## What is Shallow Copy? 4 | 5 | A shallow copy in Python creates a new object, but does not recursively copy the objects that are nested within the original object. Instead, it creates references to the same nested objects in the original object. This means that changes to nested objects in the copied structure can affect the original object and vice versa. 6 | 7 | In Python, shallow copying can be achieved using several approaches, such as: 8 | - Using the `copy()` method on built-in collections like lists and dictionaries. 9 | - Using the `copy` module's `copy()` function. 10 | - Slicing a list using `[:]`. 11 | 12 | ## Why Use Shallow Copy? 13 | 14 | Shallow copy is useful when you want to duplicate a data structure but are fine with nested objects remaining shared. It is particularly useful in these scenarios: 15 | 16 | - **Efficiency**: Shallow copying is generally faster than deep copying because it does not create new instances for nested objects. 17 | - **Use Cases**: When you want to create a new object with a similar structure but do not need to duplicate all underlying data. For example, when dealing with large lists of complex objects, creating deep copies could consume significant memory and processing time. 18 | 19 | ## Advantages of Shallow Copy 20 | 21 | Shallow copy offers several advantages: 22 | 23 | - **Speed**: Because shallow copy only duplicates the outer structure and creates references to nested objects, it is faster than deep copy, which recursively duplicates everything. 24 | - **Memory Efficiency**: Since shallow copy does not create new instances for nested objects, it uses less memory than deep copy. 25 | - **Less Complexity**: Shallow copy is useful when you know that changes to nested objects should be reflected across copies. 26 | 27 | ### Important Note 28 | 29 | While shallow copying has its advantages, it comes with a caveat: changes to nested objects in the original or copied structure can affect the other. This can lead to unintended side effects if not managed carefully. If you need a complete and independent copy, consider using deep copy, which creates entirely new instances for all nested objects. 30 | 31 | 32 | ## Example Usage 33 | Here's an example demonstrating the use of deep copy in Python: 34 | 35 | ```python 36 | import copy 37 | 38 | original = [['Hashim', 'Tahir', 24], [1, 2, 3], ['x', True, 97.5]] 39 | 40 | # Create a deep copy of the original list 41 | shallow_copy = copy.copy(original) 42 | 43 | # Modify the deep copy 44 | shallow_copy[0][0] = 'Ali' 45 | 46 | print("Original:", original) # Output: [['Ali', 'Tahir', 24], [1, 2, 3], ['x', True, '97.5']] 47 | print("Shallow Copy:", shallow_copy) # Output: [['Ali', 'Tahir', 24], [1, 2, 3], ['x', True, '97.5']] 48 | -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class03(Deep Copy)/main.py: -------------------------------------------------------------------------------- 1 | import copy 2 | l1 = [['Hashim', 24], [1, 3]] 3 | 4 | print('List 1') 5 | print(f'Address of List 1 = {hex(id(l1))}') 6 | print(f'Address of List 1[0] index = {hex(id(l1[0]))}') 7 | print(f'Address of List 1[0] index item[0] = {hex(id(l1[0][0]))}') 8 | print(f'Address of List 1[0] index item[1] = {hex(id(l1[0][1]))}') 9 | print('-----------------------------------------------------------') 10 | print(f'Address of List 1[1] index = {hex(id(l1[1]))}') 11 | print(f'Address of List 1[1] index item[0] = {hex(id(l1[1][0]))}') 12 | print(f'Address of List 1[1] index item[1] = {hex(id(l1[1][1]))}') 13 | print('-----------------------------------------------------------') 14 | print('End of the first list') 15 | 16 | l2 = copy.deepcopy(l1) 17 | print('List 2') 18 | print(f'Address of List 2 = {hex(id(l2))}') 19 | print(f'Address of List 2[0] index = {hex(id(l2[0]))}') 20 | print(f'Address of List 2[0] index item[0] = {hex(id(l2[0][0]))}') 21 | print(f'Address of List 2[0] index item[1] = {hex(id(l2[0][1]))}') 22 | print('-----------------------------------------------------------') 23 | print(f'Address of List 2[1] index = {hex(id(l2[1]))}') 24 | print(f'Address of List 2[1] index item[0] = {hex(id(l2[1][0]))}') 25 | print(f'Address of List 2[1] index item[1] = {hex(id(l2[1][1]))}') 26 | print('-----------------------------------------------------------') 27 | print('End of the Second list') 28 | 29 | print(l1) 30 | print(l2) 31 | l2[0] = 'a' 32 | print(l2) 33 | print(l1) 34 | -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/Class03(Deep Copy)/readme.md: -------------------------------------------------------------------------------- 1 | # Deep Copy in Python 2 | 3 | ## What is Deep Copy in Python? 4 | Deep copy is a concept in Python that refers to copying an object and all its nested objects, ensuring that the copy is completely independent from the original. This means that changes made to the copied object will not affect the original object, and vice versa. 5 | 6 | Python provides a way to perform deep copying through the `copy` module. The `deepcopy()` function from this module creates a new object with the same contents as the original, but with its own memory addresses for all nested objects. 7 | 8 | ## Why Use Deep Copy in Python? 9 | Deep copy is useful when you need to create a copy of an object with complex internal structures, such as nested lists, dictionaries, or custom objects, and you want to avoid unintended modifications between the original and the copied objects. 10 | 11 | Here are some common scenarios where deep copy is beneficial: 12 | 13 | - **Cloning complex objects**: When you want to create a new instance of an object with the same data without altering the original instance. 14 | - **Preserving original data**: When you need to work on a copy of the data while keeping the original intact for future reference or undoing changes. 15 | - **Creating backup copies**: In cases where you need a backup of an object before making significant modifications. 16 | 17 | ## Advantages of Deep Copy in Python 18 | The key advantage of deep copy is its isolation between the original and copied objects. This provides the following benefits: 19 | 20 | 1. **No Side Effects**: Changes made to the deep copy do not affect the original object, preventing unintended side effects in shared data structures. 21 | 2. **Safer Modifications**: You can safely modify a deep copy without risking changes to the original object, which is useful in complex applications. 22 | 3. **Better Data Integrity**: Deep copy helps maintain data integrity by ensuring that original data remains unchanged, even when its copy is manipulated. 23 | 24 | ## Example Usage 25 | Here's an example demonstrating the use of deep copy in Python: 26 | 27 | ```python 28 | import copy 29 | 30 | original = [['Hashim', 'Tahir', 24], [1, 2, 3], ['x', True, 97.5]] 31 | 32 | # Create a deep copy of the original list 33 | deep_copy = copy.deepcopy(original) 34 | 35 | # Modify the deep copy 36 | deep_copy[0][0] = 'Ali' 37 | 38 | print("Original:", original) # Output: [['Hashim', 'Tahir', 24], [1, 2, 3], ['x', True, '97.5']] 39 | print("Deep Copy:", deep_copy) # Output: [['Ali', 'Tahir', 24], [1, 2, 3], ['x', True, '97.5']] 40 | -------------------------------------------------------------------------------- /13_Class(Deep and Shallow Copy)/readme.md: -------------------------------------------------------------------------------- 1 | # No Copy with Assignment Operators 2 | 3 | This project demonstrates best practices for avoiding data copying when using assignment operators. This is useful in contexts where deep copying or shallow copying can lead to performance issues or unintended side effects. 4 | 5 | ## Table of Contents 6 | - [Introduction](#introduction) 7 | - [Assignment Operators](#assignment-operators) 8 | - [Avoiding Copies](#avoiding-copies) 9 | - [Example Use Cases](#example-use-cases) 10 | - [Best Practices](#best-practices) 11 | - [Contributing](#contributing) 12 | 13 | ## Introduction 14 | When working with data structures in many programming languages, copying can occur when you assign one variable to another. This can result in unexpected behavior, especially in large-scale applications or systems with stringent performance requirements. 15 | 16 | This project demonstrates methods and best practices to avoid these issues by preventing data copying with assignment operators. 17 | 18 | ## Assignment Operators 19 | Assignment operators are used to set a variable equal to a value, another variable, or a structure. The most common is the equal sign `=`. When using assignment operators, it's important to understand if the data is being copied or if a reference to the original data is being created. 20 | 21 | ## Avoiding Copies 22 | To avoid copying data unintentionally, follow these guidelines: 23 | 24 | 1. **Use References Instead of Copies**: When assigning values, ensure you're creating a reference rather than a new copy. This approach minimizes memory usage and avoids accidental duplication. 25 | 26 | 2. **Immutable Data Structures**: In some languages, immutable data structures prevent data copying, as they create new objects instead of modifying existing ones. 27 | 28 | 3. **Use Functional Programming Techniques**: Functional programming often relies on references and immutable data, reducing the risk of copying when assigning values. 29 | 30 | ## Example Use Cases 31 | - **Linked Lists and Trees**: When manipulating linked lists or tree structures, avoid copying entire sub-trees. Use references to update specific nodes. 32 | - **Large Arrays and Collections**: When working with large data sets, ensure you're referencing data rather than creating new instances. 33 | - **Concurrent Programming**: In multi-threaded environments, use references to shared resources rather than copying data to avoid race conditions. 34 | 35 | ## Best Practices 36 | - **Use Copy-On-Write (COW)**: Some languages support COW, where copying occurs only if data is modified. This approach reduces unnecessary duplication. 37 | - **Utilize Smart Pointers**: In languages like C++, smart pointers help manage memory without copying data unnecessarily. 38 | - **Leverage Framework Features**: Use built-in features of frameworks or libraries to manage data references and avoid copying. 39 | 40 | ## Contributing 41 | Contributions are welcome! If you have suggestions for improvements, additional examples, or bug fixes, please open an issue or submit a pull request. 42 | 43 | 44 | -------------------------------------------------------------------------------- /15-Tuple.py: -------------------------------------------------------------------------------- 1 | #Using python to manipulate tuples 2 | ''' 3 | Python Tuple is used to store the sequence of immutable Python 4 | objects. 5 | 6 | Tuples are written as a list of "comma-separated" 7 | values (items) between parentheses. () 8 | 9 | Tuples are immutable - this means that items can not be changed. 10 | However,a tuple can contain mutable objects. 11 | 12 | Tuple has 2 methods available. 13 | count() Returns the number of elements with the specified value 14 | index() Returns the index of the first element with the specified value 15 | ''' 16 | 17 | #The basics - tuple packing 18 | t = 12345, 54321, 'hello!' 19 | t[0] 20 | t 21 | type(t) 22 | 23 | T1 = (101, "Peter", 22) 24 | T2 = ("Apple", "Banana", "Orange") 25 | T3 = 10,20,30,40,50 26 | 27 | print(type(T1)) 28 | print(type(T2)) 29 | print(type(T3)) # Class Tuple 30 | 31 | #The tuple which is created without using parentheses 32 | # is also known as tuple packing. 33 | a = 'abc', 2, 4, 'd' 34 | print(type(a)) # Class Tuple 35 | 36 | #An empty tuple can be created as follows. 37 | T4 = () 38 | 39 | #Creating a tuple with single element is slightly different. 40 | # We will need to put comma after the element to declare the tuple 41 | tup1 = ("JavaTpoint") #String 42 | print(type(tup1)) 43 | #Creating a tuple with single element 44 | tup2 = ("JavaTpoint",) #Tuple 45 | print(type(tup2)) 46 | ''' 47 | Output 48 | 49 | 50 | ''' 51 | #Example 1 52 | tuple1 = (10, 20, 30, 40, 50, 60) 53 | print(tuple1) 54 | count = 0 55 | for i in tuple1: 56 | print("tuple1[%d] = %d"%(count, i)) 57 | count = count+1 58 | 59 | ''' 60 | (10, 20, 30, 40, 50, 60) 61 | tuple1[0] = 10 62 | tuple1[1] = 20 63 | tuple1[2] = 30 64 | tuple1[3] = 40 65 | tuple1[4] = 50 66 | tuple1[5] = 60 67 | ''' 68 | 69 | #Example 2 70 | tuple1 = tuple(input("Enter the tuple elements ...")) 71 | print(tuple1) 72 | count = 0 73 | for i in tuple1: 74 | print("tuple1[%d] = %s"%(count, i)) 75 | count = count+1 76 | ''' 77 | Output 78 | Enter the tuple elements ...123456 79 | ('1', '2', '3', '4', '5', '6') 80 | tuple1[0] = 1 81 | tuple1[1] = 2 82 | tuple1[2] = 3 83 | tuple1[3] = 4 84 | tuple1[4] = 5 85 | tuple1[5] = 6 86 | ''' 87 | #indexing 88 | tuple = (1,2,3,4,5,6,7) 89 | #element 1 to end 90 | print(tuple[1:]) 91 | #element 0 to 3 element 92 | print(tuple[:4]) 93 | #element 1 to 4 element 94 | print(tuple[1:5]) 95 | # element 0 to 6 and take step of 2 96 | print(tuple[0:6:2]) 97 | ''' 98 | Output 99 | (2, 3, 4, 5, 6, 7) 100 | (1, 2, 3, 4) 101 | (1, 2, 3, 4) 102 | (1, 3, 5) 103 | ''' 104 | 105 | #Negative Indexing 106 | tuple1 = (1, 2, 3, 4, 5) 107 | print(tuple1[-1]) 108 | print(tuple1[-4]) 109 | print(tuple1[-3:-1]) 110 | print(tuple1[:-1]) 111 | print(tuple1[-2:]) 112 | ''' 113 | Output 114 | 5 115 | 2 116 | (3, 4) 117 | (1, 2, 3, 4) 118 | (4, 5) 119 | ''' 120 | #Deleting Tuple 121 | ''' 122 | Unlike lists, the tuple items cannot be deleted by using the del keyword 123 | as tuples are immutable. To delete an entire tuple, we can use the del 124 | keyword with the tuple name. 125 | ''' 126 | tuple1 = (1, 2, 3, 4, 5, 6) 127 | print(tuple1) 128 | del tuple1[0] 129 | print(tuple1) 130 | del tuple1 131 | print(tuple1) 132 | ''' 133 | Output 134 | (1, 2, 3, 4, 5, 6) 135 | Traceback (most recent call last): 136 | File "tuple.py", line 4, in 137 | print(tuple1) 138 | NameError: name 'tuple1' is not defined 139 | ''' 140 | #Python Tuple inbuilt functions 141 | ''' 142 | SN Function Description 143 | 1 cmp(tuple1, tuple2) It compares two tuples and returns true 144 | if tuple1 is greater than tuple2 otherwise false. 145 | 2 len(tuple) It calculates the length of the tuple. 146 | 3 max(tuple) It returns the maximum element of the tuple 147 | 4 min(tuple) It returns the minimum element of the tuple. 148 | 5 tuple(seq) It converts the specified sequence to the tuple. 149 | ''' 150 | 151 | #Where use tuple? 152 | ''' 153 | 1. Using tuple instead of list gives us a clear idea that tuple data 154 | is constant and must not be changed. 155 | 2. Tuple can simulate a dictionary without keys. Consider the following 156 | nested structure, which can be used as a dictionary. 157 | [(101, "John", 22), (102, "Mike", 28), (103, "Dustin", 30)] 158 | ''' 159 | # Tuples may be nested: 160 | v = ([1, 2, 3], [3, 2, 1]) 161 | u = v, (1, 2, 3, 4, 5) 162 | u 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /17-Dictionary.py: -------------------------------------------------------------------------------- 1 | #Using python to manipulate dictionary 2 | ''' 3 | Python Dictionary is used to store the data in a "key-value" pair 4 | format.The dictionary is the data type in Python, which can 5 | simulate the real-life data arrangement where some specific 6 | value exists for some particular key. It is the mutable 7 | data-structure. The dictionary is defined into element 8 | "Keys" and "values". 9 | 10 | 1.Keys must be a single element 11 | 2.Value can be any type such as list, tuple, integer, etc. 12 | 13 | In other words, we can say that a dictionary is the collection of key-value 14 | pairs where the value can be any Python object. In contrast, the keys are 15 | the immutable Python object, i.e., Numbers, string, or tuple. 16 | 17 | Dictionaries are used to store data values in key:value pairs. 18 | 19 | some_dict = { 20 | 'a_key': 'a_value', 21 | 'a_key_2': 'a_value_2', 22 | 'a_key_3': ['a_list', 'as', 'a value'], 23 | 'a_key_4': {'a_dict': 'as a value'} 24 | } 25 | 26 | Dictionaries are mutable - this means that item values can be changed 27 | 28 | Dictionaries have a bunch of methods available. 29 | clear() Removes all the elements from the dictionary 30 | copy() Returns a copy of the dictionary 31 | fromkeys() Returns a dictionary with the specified keys and value 32 | get() Returns the value of the specified key 33 | items() Returns a list containing a tuple for each key value pair 34 | keys() Returns a list containing the dictionary's keys 35 | pop() Removes the element with the specified key 36 | popitem() Removes the last inserted key-value pair 37 | setdefault() Returns the value of the specified key. If the key does not exist: 38 | insert the key, with the specified value 39 | update() Updates the dictionary with the specified key-value pairs 40 | values() Returns a list of all the values in the dictionary 41 | ''' 42 | 43 | #The basics 44 | some_dict = { 45 | 'a_key': 'a_value', 46 | 'a_key_2': 'a_value_2', 47 | 'a_key_3': ['a_list', 'as', 'a value'], 48 | 'a_key_4': {'a_dict': 'as a value'} 49 | } 50 | some_dict 51 | 52 | 53 | some_dict[0] # this will return an error as you need to ref the key by name 54 | some_dict['a_key'] 55 | some_dict['a_key_4'] 56 | 57 | #Basic 58 | Employee = {"Name": "Hamza", "Age": 20, "salary":250000,"Company":"GOOGLE"} 59 | print(type(Employee)) 60 | print("printing Employee data .... ") 61 | print(Employee) 62 | 63 | #Accessing the dictionary values 64 | ''' 65 | the values can be accessed in the dictionary by using the keys as 66 | keys are unique in the dictionary. 67 | ''' 68 | Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 69 | print(type(Employee)) 70 | print("printing Employee data .... ") 71 | print("Name : %s" %Employee["Name"]) 72 | print("Age : %d" %Employee["Age"]) 73 | print("Salary : %d" %Employee["salary"]) 74 | print("Company : %s" %Employee["Company"]) 75 | 76 | ''' 77 | Output 78 | 79 | printing Employee data .... 80 | Name : John 81 | Age : 29 82 | Salary : 25000 83 | Company : GOOGLE 84 | ''' 85 | #Adding dictionary values 86 | ''' 87 | he value can be updated along with key Dict[key] = value. The update() 88 | method is also used to update an existing value. 89 | ''' 90 | # Creating an empty Dictionary 91 | Dict = {} 92 | print("Empty Dictionary: ") 93 | print(Dict) 94 | 95 | #example 1 96 | # Adding elements to dictionary one at a time 97 | Dict[0] = 'Peter' 98 | Dict[2] = 'Joseph' 99 | Dict[3] = 'Ricky' 100 | print("\nDictionary after adding 3 elements: ") 101 | print(Dict) 102 | # Adding set of values 103 | # with a single Key 104 | # The Emp_ages doesn't exist to dictionary 105 | Dict['Emp_ages'] = 20, 33, 24 106 | print("\nDictionary after adding 3 elements: ") 107 | print(Dict) 108 | # Updating existing Key's Value 109 | Dict[3] = 'JavaTpoint' 110 | print("\nUpdated key value: ") 111 | print(Dict) 112 | 113 | ''' 114 | Output 115 | Empty Dictionary: 116 | {} 117 | 118 | Dictionary after adding 3 elements: 119 | {0: 'Peter', 2: 'Joseph', 3: 'Ricky'} 120 | 121 | Dictionary after adding 3 elements: 122 | {0: 'Peter', 2: 'Joseph', 3: 'Ricky', 'Emp_ages': (20, 33, 24)} 123 | 124 | Updated key value: 125 | {0: 'Peter', 2: 'Joseph', 3: 'JavaTpoint', 'Emp_ages': (20, 33, 24) 126 | ''' 127 | #Example 2 128 | Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 129 | print(type(Employee)) 130 | print("printing Employee data .... ") 131 | print(Employee) 132 | print("Enter the details of the new employee...."); 133 | Employee["Name"] = input("Name: "); 134 | Employee["Age"] = int(input("Age: ")); 135 | Employee["salary"] = int(input("Salary: ")); 136 | Employee["Company"] = input("Company:"); 137 | print("printing the new data"); 138 | print(Employee) 139 | 140 | ''' 141 | 142 | {'Name': 'John', 'Age': 29, 'salary': 25000, 'Company': 'GOOGLE'} 143 | Enter the details of the new employee.... 144 | Name: Muhammad Hashim 145 | Age: 22 146 | Salary: 50000 147 | Company:Google 148 | printing the new data 149 | {'Name': 'Muhammad Hashim', 'Age': 22, 'salary': 50000, 'Company': 'Google'} 150 | ''' 151 | 152 | #Deleting elements using del keyword 153 | Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 154 | print(type(Employee)) 155 | print("printing Employee data .... ") 156 | print(Employee) 157 | print("Deleting some of the employee data") 158 | del Employee["Name"] 159 | del Employee["Company"] 160 | print("printing the modified information ") 161 | print(Employee) 162 | print("Deleting the dictionary: Employee"); 163 | del Employee 164 | print("Lets try to print it again "); 165 | print(Employee) 166 | 167 | ''' 168 | Output 169 | 170 | printing Employee data .... 171 | {'Name': 'John', 'Age': 29, 'salary': 25000, 'Company': 'GOOGLE'} 172 | Deleting some of the employee data 173 | printing the modified information 174 | {'Age': 29, 'salary': 25000} 175 | Deleting the dictionary: Employee 176 | Lets try to print it again 177 | NameError: name 'Employee' is not defined 178 | ''' 179 | #Iterating Dictionary using for loop 180 | Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 181 | for x in Employee: 182 | print(x) 183 | ''' 184 | Output 185 | Name 186 | Age 187 | salary 188 | Company 189 | ''' 190 | 191 | #for loop to print all the values of the dictionary 192 | Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 193 | for x in Employee: 194 | print(Employee[x]) 195 | ''' 196 | Output 197 | John 198 | 29 199 | 25000 200 | GOOGLE 201 | ''' 202 | 203 | #for loop to print the items of the dictionary by using items() method. 204 | Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 205 | for x in Employee.items(): 206 | print(x) 207 | ''' 208 | Output 209 | ('Name', 'John') 210 | ('Age', 29) 211 | ('salary', 25000) 212 | ('Company', 'GOOGLE') 213 | ''' 214 | 215 | 216 | #show all keys and values 217 | some_dict.keys() 218 | some_dict.values() 219 | 220 | 221 | #Dict comprehension 222 | {x: x**2 for x in (2, 4, 6)} 223 | 224 | #built-in function dict() 225 | x = dict(a=1, b=2, c=3, d=4)# creates a dictionary object 226 | x -------------------------------------------------------------------------------- /19-LambdaFunction.py: -------------------------------------------------------------------------------- 1 | #Python Lambda Functions 2 | ''' 3 | Lambda Functions in Python are anonymous functions, 4 | implying they don't have a name. The def keyword is needed to create 5 | a typical function in Python, as we already know. We can also use 6 | the "lambda" keyword in Python to define an unnamed function. 7 | 8 | Syntax of Python Lambda Function 9 | lambda arguments: expression 10 | ''' 11 | #Example1 12 | # Code to demonstrate how we can use a lambda function 13 | add = lambda num: num + 4 14 | print( add(6) ) 15 | ''' 16 | Output 17 | 10 18 | ''' 19 | #Example2 20 | def reciprocal( num ): 21 | return 1 / num 22 | lambda_reciprocal = lambda num: 1 / num 23 | print( "Lambda keyword: ", lambda_reciprocal(6) ) 24 | print( "Def keyword: ", reciprocal(6) ) 25 | ''' 26 | Output 27 | Def keyword: 0.16666666666666666 28 | Lambda keyword: 0.16666666666666666 29 | ''' 30 | #Example3 Lambda Function with filter() 31 | # Code to filter odd numbers from a given list 32 | list_ = [34, 12, 64, 55, 75, 13, 63] 33 | odd_list = list(filter( lambda num: (num % 2 != 0) , list_ )) 34 | print(odd_list) 35 | ''' 36 | Output 37 | [55, 75, 13, 63] 38 | ''' 39 | #Example4 Lambda Function with map() 40 | #Code to calculate the square of each number of a list using the map() 41 | # function 42 | numbers_list = [2, 4, 5, 1, 3, 7, 8, 9, 10] 43 | squared_list = list(map( lambda num: num ** 2 , numbers_list )) 44 | print( squared_list ) 45 | ''' 46 | Output 47 | [4, 16, 25, 1, 9, 49, 64, 81, 100] 48 | ''' 49 | 50 | #Example5 Lambda Function with List Comprehension and For Loop 51 | #Code to calculate square of each number of list using list comprehension 52 | squares = [lambda num = num: num ** 2 for num in range(0, 11)] 53 | for square in squares: 54 | print( square(), end = " ") 55 | ''' 56 | Output 57 | 0 1 4 9 16 25 36 49 64 81 100 58 | ''' 59 | 60 | #Example6 Lambda Function with if-else 61 | Minimum = lambda x, y : x if (x < y) else y 62 | print(Minimum( 35, 74 )) 63 | ''' 64 | Output 65 | 35 66 | ''' 67 | -------------------------------------------------------------------------------- /2-python-comments.py: -------------------------------------------------------------------------------- 1 | #Single-Line Comments 2 | ''' 3 | This code is to show an example of a single-line comment 4 | ''' 5 | print( 'This statement does not have a hashtag before it' ) 6 | #Multi-Line Comments 7 | ''' 8 | #use multi #tags 9 | ''' 10 | # it is a 11 | # comment 12 | # extending to multiple lines 13 | 14 | #Using String Literals 15 | ''' 16 | Because Python overlooks string expressions that aren't 17 | allocated to a variable, we can utilize them as comments. 18 | ''' 19 | 'it is a comment extending to multiple lines' 20 | 21 | #Python Docstring 22 | ''' 23 | he strings enclosed in triple quotes that come immediately 24 | after the defined function are called Python docstring. 25 | It's designed to link documentation developed for Python modules, 26 | methods, classes, and functions together. It's placed just beneath 27 | the function, module, or class to explain what they perform. 28 | The docstring is then readily accessible in Python 29 | using the __doc__ attribute 30 | ''' 31 | def add(x, y): 32 | """This function adds the values of x and y""" 33 | return x + y 34 | 35 | # Displaying the docstring of the add function 36 | print( add.__doc__ ) -------------------------------------------------------------------------------- /20-Modules.py: -------------------------------------------------------------------------------- 1 | #Python Modules 2 | ''' 3 | In Python we are able to write a long program and save as a module. 4 | This is known as creating a script. We are able to import modules 5 | across modulesand into the Python interpreter. This negates the 6 | need to keep repeating ourselves. 7 | DRY!....Don't repeat yourself 8 | ''' 9 | import ModuleExample 10 | ModuleExample.add(4,5.5) 11 | 12 | #We can import a module by renaming it as follows: 13 | # import module by renaming it 14 | 15 | import ModuleExample as m 16 | print("The addition is ",m.add(4,5.5)) 17 | 18 | #Python import statement 19 | # import statement example 20 | # to import standard module math 21 | import math 22 | print("The value of pi is", math.pi) 23 | 24 | #Python from...import statement 25 | # import only pi from math module 26 | from math import pi 27 | print("The value of pi is", pi) 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /24-Getting Started mysql with python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/24-Getting Started mysql with python.pdf -------------------------------------------------------------------------------- /25.What is OOP.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/25.What is OOP.pdf -------------------------------------------------------------------------------- /26-Types of Inheritance.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/26-Types of Inheritance.pdf -------------------------------------------------------------------------------- /3-PythonLiterals.py: -------------------------------------------------------------------------------- 1 | #Python Literals 2 | ''' 3 | Two Types of Literals: 4 | 1.String Literals 5 | 2.Boolean Literals 6 | ''' 7 | 8 | #1. String literals: 9 | ''' 10 | String literals can be formed by enclosing a text in the quotes. 11 | We can use both single as well as double quotes to create a string. 12 | ''' 13 | #Example: 14 | "Aman" , '12345' 15 | #Types of Strings: 16 | #There are two types of Strings supported in Python: 17 | ''' 18 | a) Single-line String- Strings that are terminated within a single-line 19 | are known as Single line Strings. 20 | ''' 21 | text1='hello' 22 | 23 | #a) Multi-line String - 24 | ''' 25 | A piece of text that is written in multiple lines is known as multiple lines string. 26 | There are two ways to create multiline strings: 27 | ''' 28 | #b)1.1 Adding black slash at the end of each line. 29 | text1 = ' hello\ user ' 30 | print(text1) 31 | 32 | #b)1.2 Using triple quotation marks:- 33 | str2='''''welcome 34 | to 35 | SSSIT''' 36 | print(str2) 37 | 38 | #2Boolean literals: 39 | ''' 40 | A Boolean literal can have any of the two values: True or False. 41 | ''' 42 | x = (1 == True) 43 | y = (2 == False) 44 | z = (3 == True) 45 | a = True + 10 46 | b = False + 10 47 | 48 | print("x is", x) 49 | print("y is", y) 50 | print("z is", z) 51 | print("a:", a) 52 | print("b:", b) 53 | -------------------------------------------------------------------------------- /4-PythonVariables.py: -------------------------------------------------------------------------------- 1 | #Variables are containers for storing data values. 2 | ''' 3 | Python has no command for declaring a variable. 4 | A variable is created the moment you first assign a value to it. 5 | ''' 6 | #Variable Assignment 7 | n = 300 8 | id(n) 9 | print(n) 10 | 11 | #Example 12 | m = n 13 | print("Value of m ",m) 14 | print("id of m ",id(m)) 15 | print("Value of n ",n) 16 | print("id of n ",id(n)) 17 | 18 | m=400 19 | print("Value of m ",m) 20 | print("id of m ",id(m)) 21 | print("Value of n ",n) 22 | print("id of n ",id(n)) 23 | 24 | n = "Hello" 25 | print("Value of m ",m) 26 | print("id of m ",id(m)) 27 | print("Value of n ",n) 28 | print("id of n ",id(n)) 29 | 30 | #TYPE of Variable 31 | a = 2 32 | type(a) 33 | 34 | #Same id to these objects 35 | n = 10 36 | m = n 37 | print("n = :",id(n)) 38 | print("m = :",id(m)) 39 | 40 | ''' 41 | Camel case nOfStudent = "Hamza" 42 | Pascal case NOfStudent = "Subhan" 43 | Snake case name_of_student = "Zeeshan" 44 | ''' 45 | 46 | #Types of Variable data 47 | #int 48 | a = 10 49 | b = -10 50 | #float 51 | a = 10.1 52 | b = -10.1 53 | #string 54 | name = " Farooq " 55 | #bool 56 | a = True 57 | #---------------------------------------------------------------- 58 | #using Print() 59 | name = "Hashim" 60 | age = 23 61 | print('Age is ',age) 62 | print('name is '+name) 63 | #----------------------------------------------------------------- 64 | #F-Strings (Formatted String Literals) 65 | print(f'Age is {age} and Name is {name}') 66 | #----------------------------------------------------------------- 67 | #str.format() Method 68 | print('Name : {} Age : {}'.format(name,age)) 69 | #----------------------------------------------------------------- 70 | #Using % Formatting: 71 | print('Age is %d and Name is %s'%(age,name)) 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /5-PythonOperators.py: -------------------------------------------------------------------------------- 1 | #Python Operators 2 | ''' 3 | The operator can be defined as a symbol which is responsible 4 | for a particular operation between two operands. 5 | ''' 6 | #Arithmetic operators 7 | ''' 8 | #Operator Description 9 | + (Addition) It is used to add two operands. For example, if a = 20, b = 10 => a+b = 30 10 | - (Subtraction) It is used to subtract the second operand from the first operand. If the first operand is less than the second operand, the value results negative. For example, if a = 20, b = 10 => a - b = 10 11 | / (divide) It returns the quotient after dividing the first operand by the second operand. For example, if a = 20, b = 10 => a/b = 2.0 12 | * (Multiplication) It is used to multiply one operand with the other. For example, if a = 20, b = 10 => a * b = 200 13 | % (reminder) It returns the reminder after dividing the first operand by the second operand. For example, if a = 20, b = 10 => a%b = 0 14 | ** (Exponent) It is an exponent operator represented as it calculates the first operand power to the second operand. 15 | // (Floor division) It gives the floor value of the quotient produced by dividing the two operands. 16 | ''' 17 | # Comparison operators 18 | ''' 19 | Operator Description 20 | == If the value of two operands is equal, then the condition becomes true. 21 | != If the value of two operands is not equal, then the condition becomes true. 22 | = If the first operand is less than or equal to the second operand, then the condition becomes true. 23 | >= If the first operand is greater than or equal to the second operand, then the condition becomes true. 24 | > If the first operand is greater than the second operand, then the condition becomes true. 25 | < If the first operand is less than the second operand, then the condition becomes true. 26 | ''' 27 | # Assignment Operators 28 | ''' 29 | Operator Description 30 | = It assigns the value of the right expression to the left operand. 31 | += It increases the value of the left operand by the value of the right operand and assigns the modified value back to left operand. For example, if a = 10, b = 20 => a+ = b will be equal to a = a+ b and therefore, a = 30. 32 | -= It decreases the value of the left operand by the value of the right operand and assigns the modified value back to left operand. For example, if a = 20, b = 10 => a- = b will be equal to a = a- b and therefore, a = 10. 33 | *= It multiplies the value of the left operand by the value of the right operand and assigns the modified value back to then the left operand. For example, if a = 10, b = 20 => a* = b will be equal to a = a* b and therefore, a = 200. 34 | %= It divides the value of the left operand by the value of the right operand and assigns the reminder back to the left operand. For example, if a = 20, b = 10 => a % = b will be equal to a = a % b and therefore, a = 0. 35 | *= a**=b will be equal to a=a**b, for example, if a = 4, b =2, a**=b will assign 4**2 = 16 to a. 36 | //= A//=b will be equal to a = a// b, for example, if a = 4, b = 3, a//=b will assign 4//3 = 1 to a. 37 | ''' 38 | # Logical Operators 39 | ''' 40 | Operator Description 41 | and If both the expression are true, then the condition will be true. If a and b are the two expressions, a → true, b → true => a and b → true. 42 | or If one of the expressions is true, then the condition will be true. If a and b are the two expressions, a → true, b → false => a or b → true. 43 | not If an expression a is true, then not (a) will be false and vice versa 44 | ''' 45 | # Bitwise Operators 46 | ''' 47 | Operator Description 48 | & (binary and) If both the bits at the same place in two operands are 1, then 1 is copied to the result. Otherwise, 0 is copied. 49 | | (binary or) The resulting bit will be 0 if both the bits are zero; otherwise, the resulting bit will be 1. 50 | ^ (binary xor) The resulting bit will be 1 if both the bits are different; otherwise, the resulting bit will be 0. 51 | ~ (negation) It calculates the negation of each bit of the operand, i.e., if the bit is 0, the resulting bit will be 1 and vice versa. 52 | << (left shift) The left operand value is moved left by the number of bits present in the right operand. 53 | >> (right shift) The left operand is moved right by the number of bits present in the right operand. 54 | ''' 55 | # Membership Operators 56 | ''' 57 | Python membership operators are used to check 58 | the membership of value inside a Python data structure. 59 | If the value is present in the data structure, 60 | then the resulting value is true otherwise it returns false. 61 | Operator Description 62 | in It is evaluated to be true if the first operand is found in the second operand (list, tuple, or dictionary). 63 | not in It is evaluated to be true if the first operand is not found in the second operand (list, tuple, or dictionary). 64 | ''' 65 | # Identity Operators 66 | ''' 67 | The identity operators are used to decide whether an element certain class or type. 68 | Operator Description 69 | is It is evaluated to be true if the reference present at both sides point to the same object. 70 | is not It is evaluated to be true if the reference present at both sides do not point to the same object. 71 | ''' 72 | #Operator Precedence 73 | ''' 74 | Operator Description 75 | ** The exponent operator is given priority over all the others used in the expression. 76 | ~ + - The negation, unary plus, and minus. 77 | * / % // The multiplication, divide, modules, reminder, and floor division. 78 | + - Binary plus, and minus 79 | >> << Left shift. and right shift 80 | & Binary and. 81 | ^ | Binary xor, and or 82 | <= < > >= Comparison operators (less than, less than equal to, greater than, greater then equal to). 83 | <> == != Equality operators. 84 | = %= /= //= -= +=#*= **= Assignment operators 85 | is is not Identity operators 86 | in not in Membership operators 87 | not or and Logical operators 88 | ''' -------------------------------------------------------------------------------- /6-UserInput.py: -------------------------------------------------------------------------------- 1 | #Python User Input 2 | ''' 3 | Python allows for user input. 4 | 5 | That means we are able to ask the user for input. 6 | 7 | The method is a bit different in Python 3.6 than Python 2.7. 8 | 9 | Python 3.6 uses the input() method. 10 | 11 | ''' 12 | username = input("Enter username:") 13 | print("Username is:" + username) 14 | 15 | #Example 16 | name = input("Enter Your name:") 17 | age = int(input("Enter your age")) 18 | print("Your name is :",name,"Your age is",age) 19 | -------------------------------------------------------------------------------- /7-EscapeCharacters.py: -------------------------------------------------------------------------------- 1 | #Python Escape Characters 2 | ''' 3 | You will get an error if you use double quotes inside a string 4 | that is surrounded by double quotes: 5 | ''' 6 | txt = "We are the so-called "Vikings" from the north." 7 | 8 | ''' 9 | The escape character allows you to use double quotes 10 | when you normally would not be allowed: 11 | ''' 12 | txt = "We are the so-called \"Vikings\" from the north." 13 | 14 | ''' 15 | ESCAPE SEQUENCE MEANING 16 | Code Result 17 | \' Single Quote 18 | \\ Backslash 19 | \n New Line 20 | \" Double Quote 21 | \t Tab 22 | ''' 23 | #Single Qoute 24 | txt = 'It\'s alright.' 25 | print(txt) 26 | #Double Quote 27 | txt = 'It\"s alright.' 28 | print(txt) 29 | #Backslash 30 | txt = "This will insert one \\ (backslash)." 31 | print(txt) 32 | #Newline 33 | txt = "Hello\nWorld!" 34 | print(txt) 35 | #Tab 36 | txt = "Hello\tWorld!" 37 | print(txt) 38 | -------------------------------------------------------------------------------- /8-DecisionStatemets.py: -------------------------------------------------------------------------------- 1 | #Python control flows 2 | ''' 3 | Python uses the usual flow control statements known 4 | from other languages, with some twists. 5 | Perhaps the most well-known statement type is the 6 | ''' 7 | #if statement. 8 | ''' 9 | Think of an if statement as a way to check to see if 10 | conditions are met! 11 | ''' 12 | num = int(input("enter the number?")) 13 | if num%2 == 0: 14 | print("Number is even") 15 | 16 | 17 | #if else 18 | ''' 19 | If a condition is met, do something... 20 | else do something different! 21 | ''' 22 | age = int (input("Enter your age? ")) 23 | if age>=18: 24 | print("You are eligible to vote !!"); 25 | else: 26 | print("Sorry! you have to wait !!"); 27 | 28 | 29 | #elif 'elif' stands for 'else if' 30 | ''' 31 | both elif and else are optional! 32 | ''' 33 | number = int(input("Enter the number?")) 34 | if number == 10: 35 | print("number is equals to 10") 36 | elif number == 50: 37 | print("number is equal to 50"); 38 | elif number == 100: 39 | print("number is equal to 100"); 40 | else: 41 | print("number is not equal to 10, 50 or 100"); 42 | 43 | #Match statement 44 | 45 | ''' 46 | Hot off the press in Python 3.10 47 | 48 | A match statement takes an expression and compares 49 | its value to successive patterns given as one or 50 | more case blocks. 51 | 52 | Note: We have a class in this demo. Don't get too caught 53 | up in how it 54 | works! We have a class video in this course :) 55 | ''' 56 | 57 | #basics 58 | def http_error(status): 59 | match status: 60 | case 400: 61 | return "Bad request" 62 | case 404: 63 | return "Not found" 64 | case 418: 65 | return "I'm a teapot" 66 | case _: 67 | return "Something's wrong with the internet" 68 | 69 | def http_error(status): 70 | match status: 71 | case 400 | 401 | 403 | 404: 72 | return "Not allowed" 73 | case 418: 74 | return "I'm a teapot" 75 | case _: 76 | return "Something's wrong with the internet" 77 | 78 | #Practise 79 | #when to know everything about tuple and class 80 | #Patterns can look like unpacking assignments, and can be used to bind variables: 81 | # point is an (x, y) tuple 82 | def http_error(point): 83 | match point: 84 | case (0, 0): 85 | print("Origin") 86 | case (0, y): 87 | print(f"Y={y}") 88 | case (x, 0): 89 | print(f"X={x}") 90 | case (x, y): 91 | print(f"X={x}, Y={y}") 92 | case _: 93 | raise ValueError("Not a point") 94 | 95 | point_tuple = (0,0) 96 | point_tuple = (0,123) 97 | point_tuple = (123,0) 98 | point_tuple = (123,456) 99 | 100 | #Match class 101 | from dataclasses import dataclass 102 | @dataclass 103 | class Point: 104 | x: int 105 | y: int 106 | 107 | def where_is(point): 108 | match point: 109 | case Point(x=0, y=0): 110 | print("Origin") 111 | case Point(x=0, y=y): 112 | print(f"Y={y}") 113 | case Point(x=x, y=0): 114 | print(f"X={x}") 115 | case Point(): 116 | print("Somewhere else") 117 | case _: 118 | print("Not a point") 119 | 120 | where_is(Point(0, 0)) 121 | where_is(Point(0, 10)) 122 | where_is(Point(10, 0)) 123 | where_is(Point(10, 10)) -------------------------------------------------------------------------------- /9-Iterations.py: -------------------------------------------------------------------------------- 1 | #Python control flows - Loops 2 | ''' 3 | Python’s for statement iterates over the items of any sequence 4 | (a list or a string), in the order that they appear in the 5 | sequence. 6 | 7 | The built-in Range function 'range()' comes in handy 8 | if you do need 9 | to iterate over a sequence of numbers. 10 | It generates arithmetic 11 | progressions: 12 | 13 | range(start, stop, step) 14 | start 15 | The value of the start parameter (or 0 if the parameter was not supplied) 16 | stop 17 | The value of the stop parameter 18 | step 19 | The value of the step parameter (or 1 if the parameter was not supplied) 20 | 21 | The following sorts of loops are available 22 | in the Python programming language. 23 | Sr.No. Name of the loop Loop Type & Description 24 | 1 While loop Repeats a statement or 25 | group of statements while a 26 | given condition is TRUE. 27 | It tests the condition 28 | before executing the loop body. 29 | 2 For loop This type of loop executes a 30 | code block multiple times and 31 | abbreviates the code that 32 | manages the loop variable. 33 | 3 Nested loops We can iterate a loop inside 34 | another loop. 35 | 36 | Loop Control Statements 37 | Statements used to control loops and change the course of iteration are 38 | called control statements. All the objects produced within the local 39 | scope of the loop are deleted when execution is completed. 40 | 41 | Sr.No. Name of the control statement Description 42 | 1 Break statement This command terminates 43 | the loop's execution and 44 | transfers the program's 45 | control to the statement 46 | next to the loop. 47 | 2 Continue statement This command skips the 48 | current iteration of the 49 | loop. The statements 50 | following the continue 51 | statement are not 52 | executed once the 53 | Python interpreter 54 | reaches the continue 55 | statement. 56 | 3 Pass statement The pass statement is 57 | used when a statement 58 | is syntactically 59 | necessary, but no code 60 | is to be executed 61 | ''' 62 | 63 | #The range() Function 64 | ''' 65 | With the help of the range() function, we may produce a series of numbers. 66 | range(10) will produce values between 0 and 9. (10 numbers). 67 | We can give specific start, stop, and step size values in the manner 68 | range(start, stop, step size). If the step size is not specified, 69 | it defaults to 1. 70 | Since it doesn't create every value it "contains" after we construct 71 | it,the range object can be characterized as being "slow." 72 | It does provide 73 | in, len, and __getitem__ actions, but it is not an iterator. 74 | ''' 75 | #The example that follows will make this clear. 76 | print(range(15)) 77 | print(list(range(15))) 78 | print(list(range(4, 9))) 79 | print(list(range(5, 25, 4))) 80 | -------------------------------------------------------------------------------- /Assests/Modules/ModulesPractice/dict.py: -------------------------------------------------------------------------------- 1 | Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"} 2 | -------------------------------------------------------------------------------- /Assests/Modules/ModulesPractice/functions.py: -------------------------------------------------------------------------------- 1 | def length( string ): 2 | "This prints the value of length of string" 3 | return len(string) 4 | 5 | def number_play(x): 6 | if x < 0: 7 | x = 0 8 | print('Negative changed to zero') 9 | elif x == 0: 10 | print('Zero') 11 | elif x == 1: 12 | print('Single') 13 | else: 14 | print('More') 15 | 16 | -------------------------------------------------------------------------------- /Assests/Modules/ModulesPractice/list.py: -------------------------------------------------------------------------------- 1 | student = ["Hamza", 21, "Spartan300"] 2 | Field1 = ["Wp full stack",1] 3 | Field2 = ["Mern Stack",2] 4 | HOD_Field1 = [10,"Sr. Farooq"] 5 | HOD_Field2 = [11, "Mr. Hamza"] -------------------------------------------------------------------------------- /Assests/Modules/Python Modules.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/Modules/Python Modules.pdf -------------------------------------------------------------------------------- /Assests/pakages/SMS/Admin/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/Admin/__init__.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/Admin/dashboard.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/Admin/dashboard.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/Admin/logout.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/Admin/logout.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/Admin/product.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/Admin/product.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/Admin/service.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/Admin/service.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/Tech/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/Tech/__init__.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/Tech/logout.py: -------------------------------------------------------------------------------- 1 | logout = "You are Logout" -------------------------------------------------------------------------------- /Assests/pakages/SMS/Tech/profile.py: -------------------------------------------------------------------------------- 1 | profile = "Welcome Muhammad Hashim!" -------------------------------------------------------------------------------- /Assests/pakages/SMS/Tech/work.py: -------------------------------------------------------------------------------- 1 | dist = { 2 | "name":"Muhammad", 3 | "age":23, 4 | "Career":"DevOps", 5 | "Expert":"Gen Ai, NextJs, Modern JamStack" 6 | } 7 | -------------------------------------------------------------------------------- /Assests/pakages/SMS/User/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/User/__init__.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/User/logout.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/User/logout.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/User/profile.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/User/profile.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/User/request.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/User/request.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HashimThePassionate/Python-For-Absolute-Beginners/a2425aa8b9b0a51ad2bfbae9905c256b9fd8cb2d/Assests/pakages/SMS/__init__.py -------------------------------------------------------------------------------- /Assests/pakages/SMS/main.py: -------------------------------------------------------------------------------- 1 | import Tech.logout as l, Tech.profile as p, Tech.work as w 2 | print(f'Hello! {p.profile}') 3 | for i in w.dist: 4 | print(i) 5 | print(f'Hello! {l.logout}') 6 | -------------------------------------------------------------------------------- /ModuleExample.py: -------------------------------------------------------------------------------- 1 | # Python program to show how to create a module. 2 | # defining a function in the module to reuse it 3 | # Python Module example 4 | def add(a, b): 5 | """This program adds two 6 | numbers and return the result""" 7 | result = a + b 8 | return result 9 | 10 | -------------------------------------------------------------------------------- /NewFile.txt: -------------------------------------------------------------------------------- 1 | Python is the modern day language. It makes things so simple. 2 | It is the fastest-growing programing language 3 | Python has an easy syntax and user-friendly interaction. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-For-Absolute-Beginners 2 | ## Get your own copy of this repository 3 | 1. Navigate to your development directory on you machine 4 | 2. Open a Git terminal 5 | 3. Use the following commands to clone this repo: 6 | ``` 7 | git clone https://github.com/HashimThePassionate/ 8 | Python-For-Absolute-Beginners.git 9 | ``` 10 | 11 | ## What is python? 12 | - The World Fastest growing programming language not just for 13 | 1. Software Engineers 14 | 2. Mathematicians 15 | 3. Data Analysts 16 | 4. Accountants 17 | 5. Scientists 18 | 6. Network Engineers 19 | 7. or Even kids 🤣 20 | 21 | - We can say python is a first ideal programming language we must learn first 22 | - here is sixth reasons 23 | 1. Solve complex problems in less time with fewer lines of code. 24 | 2. Python is multi purpose langauages 25 | * Data Analysis 26 | * AI \ ML 27 | * Automation 28 | * Web Apps 29 | * Mobile Apps 30 | * Desktop Apps 31 | * Software Testing 32 | * Hacking 33 | 3. High-Level 34 | 4. Huge Community 35 | 5. Cross-platform 36 | 6. Large Ecosystem 37 | 38 | 39 | ## Click on this link to download python version 40 | [Download-Python](https://www.python.org/downloads/) 41 | 42 | 1. Now download the latest version 43 | 2. After download click to install python 44 | 3. make sure to check "Add python to PATH" 45 | 4. Click on "INSTALL NOW" 46 | 5. After installtion on windows open command propmt 47 | 6. Type python, python interpreter activated 48 | 7. for exit type "Ctrl+z' 49 | 50 | ## Its time to getting started with python 51 | 1. Open command prompt and type python --version to python version 52 | 2. also type py or python to activate python 53 | 3. Now python is activate run these commands 54 | ``` 55 | 2+2 56 | 2 > 1 57 | 2 == 1 58 | 2 > 59 | ``` 60 | 4. To skip python interpreter 61 | 5. Simply on windows type "Crtl + z" or use exit() 62 | 63 | ## Its time to run python programming fast 64 | 1. Use Vs Code editor for editor 65 | 2. Convert VS code to IDE Indegrated Development Invironment 66 | 3. Install python extension in vs code 67 | 4. Install autopep8 extension in vs code 68 | 5. setup autopep8 settings 69 | 6. Install mypy package for python type hinting errors 70 | pip install mypy 71 | 72 | ## Run your first python program in vs code 73 | 1. Create folder name "Python" 74 | 2. Open Folder and right click to open in vs code 75 | 3. create file main.py and type 76 | ``` 77 | print('Welcome to Python Programming Fun 🤣') 78 | print("*"*5) 79 | ``` 80 | 81 | 82 | 83 | ## More references Websites to Learn about Python
84 |
LEARN PYTHON 85 |

86 | 87 | #### [W3School](https://www.w3schools.com/python/) 88 | #### [Javatpoint](https://www.w3schools.com/python/) 89 | #### [Realpython](https://www.w3schools.com/python/) 90 | #### [Pythonguides](https://www.w3schools.com/python/) 91 | #### [Codeacademy](https://www.w3schools.com/python/) 92 | 93 |

94 |
95 | 96 | ## Some Images which I used are: 97 | ![variableExample1](https://user-images.githubusercontent.com/89855559/190901181-bdcbbf78-86e2-44e0-98b5-c44331ce4c74.png)

98 | # 99 | ![VariableExample2](https://user-images.githubusercontent.com/89855559/190901183-7bd3c675-e83d-4257-ae73-ebdd42ff7b87.png)

100 | # 101 | ![VariableExample3](https://user-images.githubusercontent.com/89855559/190901184-5d80c57c-439a-4d8e-87f5-264c2ad2b5c2.png)

102 | # 103 | ![VariableExample4](https://user-images.githubusercontent.com/89855559/190901185-b3157050-e189-40d5-814f-3514d06a6848.png)

104 | # 105 | ![LoopsFlowChart](https://user-images.githubusercontent.com/89855559/190632773-1b1713a0-f1a5-46c3-9e34-91a8c7bf2958.png)

106 | # 107 | ![continue-statement-flowchart](https://user-images.githubusercontent.com/89855559/190384969-746d90a0-b717-4866-93dc-0f856bfb75e3.png)

108 | # 109 | ![flowchart-break-statement](https://user-images.githubusercontent.com/89855559/190384978-2bf3cd40-4865-495c-b92b-7ef5451adfb8.png)

110 | # 111 | ![exception types](https://user-images.githubusercontent.com/89855559/190900645-1f7a278c-1429-47c2-815d-bc5ddd6689a7.png)

112 | # 113 | ![RaiseException](https://user-images.githubusercontent.com/89855559/190900646-d78def3c-b89e-49e1-856d-4c451c0b3960.png)

114 | # 115 | ![The AssertionError Exception](https://user-images.githubusercontent.com/89855559/190900648-7e323bf6-dcec-4bbf-8037-dc8a01f495be.png)

116 | # 117 | ![TryExcept](https://user-images.githubusercontent.com/89855559/190900650-7f0f95f3-4dd9-4e35-ace2-e198c2045a4e.png)

118 | # 119 | ![TryExceptElse](https://user-images.githubusercontent.com/89855559/190900651-d9a02745-7baa-4b6b-b8aa-7581e3232e8e.png)

120 | # 121 | ![TryExceptElseFinally](https://user-images.githubusercontent.com/89855559/190900655-527e6552-5f60-48bd-9c45-70641ef6c0f7.png)

122 | # 123 | ![ProcedureVsOOP](https://user-images.githubusercontent.com/89855559/192138194-0d693a61-9c16-4044-8c9a-c8bc1c254d0e.PNG)

124 | # 125 | ![ClassMethodVsStaticMethodVsInstanceMethod](https://user-images.githubusercontent.com/89855559/192138187-271ad767-721f-4a4e-8266-fbc6ea545be3.png)

126 | # 127 | ![InstanceMethod](https://user-images.githubusercontent.com/89855559/192138189-9d5c0ca8-c671-464a-84b2-90a51617d670.png)

128 | # 129 | ![ClassMethod](https://user-images.githubusercontent.com/89855559/192138186-b60ff5f5-6410-4021-8037-59c1b7202f09.png)

130 | # 131 | ![PythonInheritance](https://user-images.githubusercontent.com/89855559/192138197-00f5e6f5-5bae-4529-955f-6375cee0d701.png)

132 | # 133 | ![MultiLevelinheritance](https://user-images.githubusercontent.com/89855559/192138536-e74f33bb-48f7-45e7-9fcb-3a71346b60b7.png)

134 | # 135 | ![PythonMultiInheritance](https://user-images.githubusercontent.com/89855559/192138227-5c99413a-2457-454c-8465-0c1f1a597cac.png)

136 | 137 | 138 | #### Modules and Pakages: 139 | [Python Modules and Pakage.pdf](https://github.com/HashimThePassionate/python-course-for-beginner/blob/main/Assests/Modules/Python%20Modules.pdf) 140 | 141 | ###### Join Our Spartan Community: 142 | [Wp Spartan 300 Community](https://www.facebook.com/groups/wordpressspartans300). 143 | # 144 | ###### Regards 145 | ``` 146 | Muhammad Hashim 147 | ``` 148 | 149 | "# Python-for-absolute-biggners" 150 | --------------------------------------------------------------------------------