Programming Fundamentals - LAB
Programming Fundamentals - LAB
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
Lab 5: Tuples
Lab 6: Dictionaries
Lab 8: Strings
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.
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