Python programming practical examples with detailed comments in the Python file.
Task 1 - > Basic Python operations In the first task, we are doing basic math operations like Addition Substraction Multiplication Division
Task 2 -> Create a personalized greeting In the second task, we are creating a personalized greeting message
Task 3 -> Check if a Number is Even or Odd Takes an integer input from the user. Checks whether the number is even or odd using an if-else statement. Displays the result accordingly.
Task 4 -> Sum of Integers from 1 to 50 Using a Loop Uses a for loop to iterate over numbers from 1 to 50. Calculates the sum of all integers in this range. Displays the final sum.
Task 5 -> Defines a function named factorial that takes a number as an argument and calculates its factorial using a loop or recursion. Returns the calculated factorial. Calls the function with a sample number and prints the output.
Task 6 -> Asks the user for a number as input. Uses the math module to calculate the: Square root of the number Natural logarithm (log base e) of the number Sine of the number (in radians) Displays the calculated results.
Task 7 - Files, Exceptions, and Errors in Python Write a Python program that: 1. Opens and reads a text file named sample.txt. 2. Prints its content line by line. 3. Handles errors gracefully if the file does not exist.
Task 8 - Write and Append Data to a File Write a Python program that: 1. Takes user input and writes it to a file named output.txt. 2. Appends additional data to the same file. 3. Reads and displays the final content of the file
Task 9 - Create a Dictionary of Student Marks 1. Creates a dictionary where student names are keys and their marks are values. 2. Asks the user to input a student's name. 3. Retrieves and displays the corresponding marks. 4. If the student’s name is not found, display an appropriate message.
Task 10 - Demonstrate List Slicing 1. Creates a list of numbers from 1 to 10. 2. Extracts the first five elements from the list. 3. Reverses these extracted elements. 4. Prints both the extracted list and the reversed list