1. Calculate Average of Three Numbers This section demonstrates how to get three numbers from the user, calculate their sum, and then find their average. # Get input from the user num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) num3 = float(input("Enter third number: ")) # Calculate the sum sum_numbers = num1 + num2 + num3 # Calculate the average average = sum_numbers / 3 # Print the result print("The average is:", average) Input: Uses input() to get values as strings, then float() to convert them to floating-point numbers for accurate calculations. Calculation: Sums the three numbers and divides by 3. Output: Prints the calculated average. 2. Calculate Total Marks and Percentage This program takes marks for five subjects, calculates the total marks obtained, and then determines the percentage. # Get marks for five subjects sub1 = float(input("Enter marks for Subject 1: ")) sub2 = float(input("Enter marks for Subject 2: ")) sub3 = float(input("Enter marks for Subject 3: ")) sub4 = float(input("Enter marks for Subject 4: ")) sub5 = float(input("Enter marks for Subject 5: ")) # Assume maximum marks for each subject (e.g., 100) max_marks_per_subject = 100 total_max_marks = 5 * max_marks_per_subject # Calculate total marks obtained total_obtained_marks = sub1 + sub2 + sub3 + sub4 + sub5 # Calculate percentage percentage = (total_obtained_marks / total_max_marks) * 100 # Print the results print("Total Marks Obtained:", total_obtained_marks) print("Percentage:", percentage, "%") Input: Prompts the user to enter marks for five different subjects. Max Marks: Assumes a maximum of 100 marks per subject, making the total maximum marks 500. This can be adjusted. Calculations: Total Marks: Sum of all subject marks. Percentage: $( \frac{\text{Total Obtained Marks}}{\text{Total Maximum Marks}} ) \times 100$. Output: Displays both the total marks and the calculated percentage. 3. Swap Two Numbers This section shows different methods to swap the values of two variables in Python. Method 1: Using a Temporary Variable # Initial numbers a = 5 b = 10 print("Before swap (Method 1):") print("a =", a, ", b =", b) # Using a temporary variable temp = a a = b b = temp print("After swap (Method 1):") print("a =", a, ", b =", b) Mechanism: A third variable ( temp ) is used to temporarily store the value of one variable, allowing the swap to occur without losing data. Steps: temp = a (stores a 's value) a = b ( a gets b 's value) b = temp ( b gets the original a 's value from temp ) Method 2: Using Python's Tuple Assignment (Simultaneous Assignment) # Initial numbers x = 15 y = 20 print("Before swap (Method 2):") print("x =", x, ", y =", y) # Pythonic way to swap x, y = y, x print("After swap (Method 2):") print("x =", x, ", y =", y) Mechanism: Python allows simultaneous assignment, which creates a tuple on the right-hand side and unpacks it into the variables on the left-hand side. This is the most common and recommended way in Python. Steps: The expression y, x on the right creates a tuple (value_of_y, value_of_x) . This tuple is then unpacked into x and y on the left, effectively swapping their values. Method 3: Using Arithmetic Operators (for numbers only) # Initial numbers p = 25 q = 30 print("Before swap (Method 3):") print("p =", p, ", q =", q) # Using arithmetic operators p = p + q # p now holds sum of original p and q q = p - q # q now holds original p (p+q - q = p) p = p - q # p now holds original q (p+q - original p = q) print("After swap (Method 3):") print("p =", p, ", q =", q) Mechanism: This method uses addition and subtraction to swap values without a temporary variable. It only works for numeric types. Constraint: Can lead to overflow issues with very large numbers in some languages, though less common in Python due to arbitrary precision integers.