Lab 1: Introduction to Python and Basic Syntax
1. Write a Python program to print "Hello, World!".
2. Write a Python program to add two numbers.
3. Write a Python program to calculate the area of a rectangle.
4. Write a Python program to find the square root of a number.
5. Write a Python program to swap two variables.
6. Write a Python program to check whether a number is positive, negative, or zero.
7. Write a Python program to check if a number is odd or even.
8. Write a Python program to find the maximum of two numbers.
9. Write a Python program to print the ASCII value of a character.
10. Write a Python program to convert kilometers to miles.
11. Write a Python program to solve quadratic equations.
12. Write a Python program to find the factorial of a number.
13. Write a Python program to check whether a year is a leap year or not.
14. Write a Python program to calculate the simple interest.
15. Write a Python program to check whether a character is a vowel or consonant.
Lab 2: Control Structures (if-else, loops)
1. Write a Python program to find the largest of three numbers using an if-else statement.
2. Write a Python program to print all numbers between 1 and 100 that are divisible by 7.
3. Write a Python program to find the sum of all numbers between 1 and n.
4. Write a Python program to print the multiplication table of a given number.
5. Write a Python program to check if a number is a prime number.
6. Write a Python program to display the Fibonacci sequence up to n terms.
7. Write a Python program to print the sum of even numbers up to n.
8. Write a Python program to find the reverse of a given number.
9. Write a Python program to calculate the sum of the digits of a number.
10. Write a Python program to find the greatest common divisor (GCD) of two numbers.
11. Write a Python program to check whether a number is an Armstrong number or not.
12. Write a Python program to check whether a number is a palindrome or not.
13. Write a Python program to find the LCM of two numbers.
14. Write a Python program to print the prime factors of a number.
15. Write a Python program to check whether a number is perfect or not.
Lab 3: Functions
1. Write a Python program to create a function that prints "Hello, Python!".
2. Write a Python function to find the factorial of a number.
3. Write a Python function that takes two numbers as arguments and returns their sum.
4. Write a Python function to check whether a number is prime or not.
5. Write a Python function to find the maximum of three numbers.
6. Write a Python function to check if a string is a palindrome.
7. Write a Python function to count the number of vowels in a string.
8. Write a Python function to calculate the sum of squares of the first n natural numbers.
9. Write a Python function to find the sum of a list of numbers.
10. Write a Python function to return the Fibonacci sequence up to n terms.
11. Write a Python function that accepts a string and calculates the number of upper-case and lower-
case letters.
12. Write a Python function to reverse a string.
13. Write a Python function that takes a list and returns a new list with unique elements.
14. Write a Python function to calculate the nth power of a number.
15. Write a Python function to generate a random number between two specified numbers.
Lab 4: Lists
1. Write a Python program to create a list of numbers from 1 to 10.
2. Write a Python program to find the largest and smallest number in a list.
3. Write a Python program to count the number of occurrences of a specific element in a list.
4. Write a Python program to reverse a list.
5. Write a Python program to find the sum of all elements in a list.
6. Write a Python program to find the average of elements in a list.
7. Write a Python program to check if an element exists in a list.
8. Write a Python program to remove a specific element from a list.
9. Write a Python program to find the second largest element in a list.
10. Write a Python program to remove duplicates from a list.
11. Write a Python program to sort a list in ascending order.
12. Write a Python program to merge two lists into one.
13. Write a Python program to append an element to the end of a list.
14. Write a Python program to insert an element at a specific index in a list.
15. Write a Python program to count even and odd numbers in a list.
Lab 5: Tuples
1. Write a Python program to create a tuple.
2. Write a Python program to access elements of a tuple.
3. Write a Python program to find the length of a tuple.
4. Write a Python program to check if an element exists in a tuple.
5. Write a Python program to convert a tuple to a list.
6. Write a Python program to convert a list to a tuple.
7. Write a Python program to find the index of an element in a tuple.
8. Write a Python program to count occurrences of an element in a tuple.
9. Write a Python program to concatenate two tuples.
10. Write a Python program to find the maximum and minimum value in a tuple.
11. Write a Python program to slice a tuple.
12. Write a Python program to reverse a tuple.
13. Write a Python program to find the product of all elements in a tuple.
14. Write a Python program to check if a tuple is empty.
15. Write a Python program to iterate through a tuple and print its elements.
Lab 6: Dictionaries
1. Write a Python program to create a dictionary.
2. Write a Python program to access elements in a dictionary.
3. Write a Python program to add a new key-value pair to a dictionary.
4. Write a Python program to update a value in a dictionary.
5. Write a Python program to delete a key-value pair from a dictionary.
6. Write a Python program to check if a key exists in a dictionary.
7. Write a Python program to iterate through all keys in a dictionary.
8. Write a Python program to iterate through all values in a dictionary.
9. Write a Python program to find the length of a dictionary.
10. Write a Python program to merge two dictionaries.
11. Write a Python program to find the sum of all values in a dictionary.
12. Write a Python program to sort a dictionary by key.
13. Write a Python program to sort a dictionary by value.
14. Write a Python program to create a dictionary from two lists (keys and values).
15. Write a Python program to remove all key-value pairs from a dictionary.
Lab 7: Sets
1. Write a Python program to create a set.
2. Write a Python program to add an element to a set.
3. Write a Python program to remove an element from a set.
4. Write a Python program to check if an element exists in a set.
5. Write a Python program to find the union of two sets.
6. Write a Python program to find the intersection of two sets.
7. Write a Python program to find the difference between two sets.
8. Write a Python program to check if one set is a subset of another.
9. Write a Python program to find the length of a set.
10. Write a Python program to check if two sets are disjoint.
11. Write a Python program to find the symmetric difference between two sets.
12. Write a Python program to iterate through a set.
13. Write a Python program to convert a set into a list.
14. Write a Python program to find the maximum and minimum values in a set.
15. Write a Python program to remove duplicates from a list using a set.
Lab 8: Strings
1. Write a Python program to create a string.
2. Write a Python program to access elements of a string.
3. Write a Python program to find the length of a string.
4. Write a Python program to reverse a string.
5. Write a Python program to check if a string is a palindrome.
6. Write a Python program to convert a string to lowercase.
7. Write a Python program to convert a string to uppercase.
8. Write a Python program to replace a substring in a string.
9. Write a Python program to split a string into a list.
10. Write a Python program to concatenate two strings.
11. Write a Python program to count the number of vowels in a string.
12. Write a Python program to find the index of a character in a string.
13. Write a Python program to remove whitespace from the beginning and end of a string.
14. Write a Python program to check if a string contains only digits.
15. Write a Python program to count the occurrences of a character in a string.
Lab 9: File Handling
1. Write a Python program to create a text file and write some data to it.
2. Write a Python program to read the contents of a file line by line.
3. Write a Python program to append data to an existing file.
4. Write a Python program to count the number of lines in a text file.
5. Write a Python program to count the number of words in a text file.
6. Write a Python program to find and replace a word in a text file.
7. Write a Python program to check if a file exists and handle exceptions if it doesn't.
8. Write a Python program to read a specific line from a file.
9. Write a Python program to copy the contents of one file to another.
10. Write a Python program to remove a file from the system.
11. Write a Python program to list all files in a directory.
12. Write a Python program to merge the contents of two files into a third file.
13. Write a Python program to find the size of a file.
14. Write a Python program to rename a file.
15. Write a Python program to read and display the last n lines of a file.
Lab 10: Exception Handling
1. Write a Python program to demonstrate try-except blocks by catching a division by zero error.
2. Write a Python program to catch multiple exceptions (e.g., ValueError, IndexError).
3. Write a Python program to demonstrate the use of the else clause with exceptions.
4. Write a Python program to raise a custom exception when a condition is not met.
5. Write a Python program to handle file reading exceptions if the file does not exist.
6. Write a Python program to demonstrate the finally block, ensuring code execution after exceptions.
Write a Python program to handle a scenario where the user inputs non-numeric data and raise
an appropriate exception.
7. Write a Python program to define a function that handles and rethrows exceptions.
8. Write a Python program to demonstrate exception chaining.
9. Write a Python program to catch and handle exceptions for an invalid list index.
10. Write a Python program to handle the KeyError exception in a dictionary operation.
11. Write a Python program to handle division by zero using a custom message.
12. Write a Python program to demonstrate nested try-except blocks.
13. Write a Python program to demonstrate the use of the with statement for file handling.
14. Write a Python program to create and handle user-defined exceptions.
Lab 11: Recursion
1. Write a Python program to calculate the factorial of a number using recursion.
2. Write a Python program to find the nth Fibonacci number using recursion.
3. Write a Python program to compute the sum of all elements in a list using recursion.
4. Write a Python program to reverse a string using recursion.
5. Write a Python program to find the greatest common divisor (GCD) using recursion.
6. Write a Python program to compute the power of a number using recursion.
7. Write a Python program to solve the Tower of Hanoi problem.
8. Write a Python program to find the sum of digits of a number using recursion.
9. Write a Python program to check whether a string is a palindrome using recursion.
10. Write a Python program to find the length of a string using recursion.
11. Write a Python program to count the number of occurrences of an element in a list using
recursion.
12. Write a Python program to find the minimum element in a list using recursion.
13. Write a Python program to compute the binomial coefficient using recursion.
14. Write a Python program to generate all permutations of a string using recursion.
15. Write a Python program to flatten a nested list using recursion.
Lab 12: Modules and Packages
1. Write a program that imports the math module and uses it to calculate the square root of a
number.
2. Create a program that uses the random module to generate a random number between 1 and 100.
3. Write a program that imports a custom module and calls a function from it.
4. Create a program that uses the datetime module to display the current date and time.
5. Write a program that uses the os module to list all files in the current directory.
6. Create a program that demonstrates the use of the time module to pause execution.
7. Write a program that uses the json module to read and write JSON data.
8. Create a program that imports the statistics module and calculates the mean of a list of numbers.
9. Write a program that uses the sys module to access command-line arguments.
10. Create a program that uses the requests module to fetch data from a URL.
11. Write a program that imports the re module and uses it for regular expression matching.
12. Create a program that organizes files in a directory by file type using the os module.
13. Write a program that uses the pickle module to serialize and deserialize Python objects.
14. Create a program that imports multiple modules and combines their functionality.
15. Write a program that uses a third-party library (e.g., numpy or pandas) to perform data analysi