๐ List of Python Practical Exercises
This is a structured list of Python exercises, covering basic to advanced topics with important mathematical and real-world problems like factorial, Armstrong number, prime number, and matrix operations.
๐น 1๏ธโฃ Python Basics
1. Check Python Version
โ Exercise: Write a program to display the installed Python version.
2. Variables and Data Types
โ Exercise: Define variables of different types and print their values and types.
3. Data Type Conversion
โ Exercise: Convert integer to string, float to integer, and string to float.
4. Arithmetic and Comparison Operators
โ Exercise: Perform addition, subtraction, multiplication, division, modulus, and exponentiation.
5. Logical and Identity Operators
โ Exercise: Check if a given number is positive and even using logical operators.
๐น 2๏ธโฃ Control Statements
6. Decision Making (if-else)
โ Exercise: Check if a number is positive, negative, or zero.
7. Check Even or Odd
โ Exercise: Write a program to check if a number is even or odd.
8. Find the Largest of Three Numbers
โ Exercise: Take three numbers as input and find the largest number.
๐น 3๏ธโฃ Loops in Python
9. Print Numbers from 1 to N
โ Exercise: Use for and while loops to print numbers from 1 to N.
10. Print Multiplication Table
โ Exercise: Display the multiplication table of a given number.
11. Sum of First N Natural Numbers
โ Exercise: Find the sum of the first N natural numbers using loops.
12. Factorial of a Number
โ
Exercise: Write a program to compute the factorial of a number using a loop.
๐ Example: 5! = 5 ร 4 ร 3 ร 2 ร 1 = 120
13. Fibonacci Series
โ Exercise: Print the first N numbers in the Fibonacci series.
14. Armstrong Number
โ
Exercise: Check if a number is an Armstrong number (sum of cubes of digits equals the number).
๐ Example: 153 = (1ยณ) + (5ยณ) + (3ยณ) = 153
15. Prime Number Check
โ Exercise: Write a program to check whether a number is prime or not.
16. Reverse a Number
โ
Exercise: Reverse a given number (e.g., 123 โ 321
).
๐น 4๏ธโฃ Strings and Lists
17. String Operations
โ Exercise: Convert a string to uppercase, lowercase, and reverse it.
18. Palindrome Check (String & Number)
โ
Exercise: Check whether a given string or number is a palindrome.
๐ Example: 121 โ Palindrome
, "madam" โ Palindrome
19. Count Vowels and Consonants in a String
โ Exercise: Write a program to count vowels and consonants in a given string.
20. Remove Duplicates from a List
โ Exercise: Remove duplicate elements from a given list.
๐น 5๏ธโฃ Functions in Python
21. Function to Find Factorial
โ Exercise: Write a function to compute factorial using recursion.
22. Function to Check Armstrong Number
โ Exercise: Create a function that checks Armstrong numbers.
23. Function to Find Maximum in a List
โ Exercise: Write a function to return the largest number in a list.
๐น 6๏ธโฃ File Handling in Python
24. Read and Write to a File
โ Exercise: Create a file, write a message, and read it.
25. Count Words in a File
โ Exercise: Read a file and count the number of words.
26. Copy Contents of One File to Another
โ Exercise: Copy text from one file to another.
๐น 7๏ธโฃ Object-Oriented Programming (OOP)
27. Create a Class and Object
โ
Exercise: Define a class Car
with attributes and methods, and create an object.
28. Inheritance in Python
โ
Exercise: Create a parent class Animal
and a child class Dog
that inherits from Animal
.
29. Method Overloading (Simulated)
โ
Exercise: Write a class Math
with an overloaded method add()
(using default parameters).
30. Method Overriding
โ Exercise: Override a parent class method in a child class.
31. Polymorphism Example
โ
Exercise: Use a common function to call speak()
from different classes (Cat, Dog).
๐น 8๏ธโฃ Advanced Programs
32. Matrix Addition
โ
Exercise: Write a program to add two matrices.
๐ Example:
Matrix 1: [[1, 2], [3, 4]]
Matrix 2: [[5, 6], [7, 8]]
Result: [[6, 8], [10, 12]]
33. Transpose of a Matrix
โ Exercise: Compute the transpose of a matrix.
34. Merge Two Sorted Lists
โ Exercise: Write a function to merge two sorted lists into one sorted list.
35. Find Second Largest Number in a List
โ Exercise: Find the second largest number in a list.
36. Find GCD and LCM of Two Numbers
โ Exercise: Write a function to compute the GCD and LCM of two numbers.
37. Generate a Random Password
โ
Exercise: Use the random
module to generate a random strong password.
38. Implement a Simple Calculator
โ Exercise: Create a basic calculator that can perform addition, subtraction, multiplication, and division.
39. Count Frequency of Words in a String
โ Exercise: Write a Python program to count occurrences of each word in a given string.
๐น Summary Table
Category | Exercises Included |
---|---|
Python Basics | Variables, Operators, Type Conversion |
Control Statements | If-else, Largest Number, Even/Odd |
Loops | Factorial, Fibonacci, Armstrong, Prime |
Strings & Lists | Palindrome, Reverse, Count Vowels, Remove Duplicates |
Functions | Factorial, Armstrong Check, Find Maximum |
File Handling | Read/Write File, Copy Contents, Count Words |
OOP Concepts | Class & Object, Inheritance, Overloading, Overriding, Polymorphism |
Advanced Programs | Matrix Addition, Transpose, GCD/LCM, Random Password, Calculator |
๐ฅ Final Challenge
๐น Create a Simple Student Management System
โ
Add student records (name, age, course).
โ
Store and retrieve records from a file.
โ
Provide options to add, delete, update, and search students.
๐ Conclusion
This comprehensive list of exercises will help you understand Python from basics to advanced level. Let me know if you need solutions or additional challenges! ๐
Leave a Reply