Python Programming Exercises

Sharpen your Python skills with comprehensive topic-wise practice problems

Beginner to Advanced 200+ Problems Topic-wise Lists

Practice Makes Perfect

Master Python programming through hands-on practice with our comprehensive collection of exercises. Each topic includes problems of varying difficulty levels to help you strengthen your understanding and problem-solving skills.

200+ Problems

Comprehensive coverage of all Python topics

Progressive Difficulty

From beginner to advanced levels

Practical Focus

Real-world problem scenarios

1. Introduction to Python, Basic Syntax and Structure

Get familiar with Python program structure and basic syntax

  1. Write a program that displays "Hello, World!" on the screen. Easy
  2. Create a simple program that takes user input and displays a personalized greeting. Easy
  3. Write a program with single-line and multi-line comments explaining the code. Easy
  4. Create a program that demonstrates Python's indentation rules and structure. Easy
  5. Write a program that shows the difference between Python 2 and Python 3 syntax. Medium
  6. Create a program that demonstrates Python's interactive mode vs script mode. Medium
  7. Write a program that uses the __name__ == "__main__" construct. Medium
  8. Create a program that demonstrates basic error handling with try-except. Medium
  9. Write a program that uses command-line arguments with sys.argv. Hard
  10. Create a program that demonstrates Python's execution model and namespace concept. Hard

2. Variables and Data Types, Constants

Practice working with different data types and constants

  1. Declare variables of different data types (int, float, str, bool, list) and display their values and types. Easy
  2. Create a program that demonstrates dynamic typing in Python. Easy
  3. Write a program that demonstrates type conversion (int(), float(), str(), etc.). Medium
  4. Create a program that uses constants (conventionally with uppercase names). Easy
  5. Write a program that demonstrates complex numbers and their operations. Medium
  6. Create a program that shows the difference between mutable and immutable data types. Medium
  7. Write a program that demonstrates variable scope (local vs global). Medium
  8. Create a program that uses None and demonstrates its purpose. Medium
  9. Write a program that demonstrates the use of type hints (Python 3.5+). Hard
  10. Create a program that shows memory usage of different data types. Hard

3. Input and Output (I/O), Operators

Practice using I/O functions and different operators

  1. Write a program that takes user input and displays it with appropriate formatting. Easy
  2. Create a calculator program that performs basic arithmetic operations on two numbers. Easy
  3. Write a program that demonstrates the use of relational and logical operators. Easy
  4. Create a program that demonstrates the use of assignment operators. Easy
  5. Write a program that uses formatted string literals (f-strings) for output. Medium
  6. Create a program that demonstrates operator precedence and associativity. Medium
  7. Write a program that uses the print() function with various parameters (sep, end, file). Medium
  8. Create a program that handles input validation and error checking. Medium
  9. Write a program that demonstrates the use of the ternary conditional operator. Hard
  10. Create a program that uses bitwise operators for low-level data manipulation. Hard

4. Conditional Control Statements

Practice using if, elif, else statements

  1. Write a program that checks if a number is positive using an if statement. Easy
  2. Create a program that determines the grade based on marks using if-elif-else statements. Medium
  3. Write a program that implements a simple calculator using conditional statements. Medium
  4. Create a program that uses nested if statements to solve a complex conditional problem. Hard
  5. Write a program that demonstrates short-circuit evaluation in conditional statements. Medium
  6. Create a program that uses conditional statements to determine leap years. Medium
  7. Write a program that implements a menu-driven interface using conditional statements. Medium
  8. Create a program that uses conditional expressions to find the maximum of three numbers. Medium
  9. Write a program that demonstrates the use of the match-case statement (Python 3.10+). Hard
  10. Create a program that uses conditional statements to solve a quadratic equation. Hard

5. Loops

Practice using for and while loops

  1. Write a program that prints numbers from 1 to 10 using a for loop. Easy
  2. Create a program that calculates the sum of numbers until the user enters 0 using a while loop. Medium
  3. Write a program that demonstrates the difference between for and while loops. Medium
  4. Create a program that prints patterns using nested loops (e.g., pyramid, diamond). Hard
  5. Write a program that uses loops to calculate the factorial of a number. Medium
  6. Create a program that finds prime numbers within a range using loops. Medium
  7. Write a program that demonstrates the use of break, continue, and pass statements in loops. Medium
  8. Create a program that implements the Fibonacci sequence using loops. Medium
  9. Write a program that uses loops to reverse a number or string. Hard
  10. Create a program that demonstrates the use of else clause with loops. Hard

6. Lists, Tuples, and Sets

Practice working with sequence data types

  1. Write a program that demonstrates creation, indexing, and slicing of lists. Easy
  2. Create a program that performs various list operations (append, extend, insert, remove). Medium
  3. Write a program that demonstrates list comprehensions. Medium
  4. Create a program that shows the difference between lists and tuples. Medium
  5. Write a program that uses sets to remove duplicates and perform set operations. Medium
  6. Create a program that demonstrates the use of frozenset. Medium
  7. Write a program that finds the most frequent element in a list. Medium
  8. Create a program that implements common algorithms on lists (sorting, searching). Hard
  9. Write a program that demonstrates the use of the zip() function with lists. Hard
  10. Create a program that uses nested lists to represent matrices and perform operations. Hard

7. Dictionaries

Practice working with key-value pairs

  1. Write a program that demonstrates creation, accessing, and modification of dictionaries. Easy
  2. Create a program that performs various dictionary operations (update, pop, get). Medium
  3. Write a program that demonstrates dictionary comprehensions. Medium
  4. Create a program that iterates over dictionary keys, values, and items. Medium
  5. Write a program that uses dictionaries to count frequency of elements. Medium
  6. Create a program that demonstrates the use of defaultdict from collections. Hard
  7. Write a program that uses dictionaries to implement a simple database. Hard
  8. Create a program that demonstrates the use of OrderedDict. Hard
  9. Write a program that merges multiple dictionaries. Hard
  10. Create a program that uses dictionaries with complex nested structures. Hard

8. Strings

Practice working with string manipulation

  1. Write a program that demonstrates string creation and basic operations. Easy
  2. Create a program that performs various string operations (concatenation, repetition, slicing). Medium
  3. Write a program that demonstrates common string methods (upper, lower, strip, split, join). Medium
  4. Create a program that checks if a given string is a palindrome. Medium
  5. Write a program that counts vowels, consonants, digits, and special characters in a string. Medium
  6. Create a program that demonstrates string formatting techniques (% formatting, format(), f-strings). Medium
  7. Write a program that implements basic string encryption and decryption. Hard
  8. Create a program that removes all occurrences of a character from a string. Medium
  9. Write a program that checks if two strings are anagrams of each other. Hard
  10. Create a program that demonstrates regular expressions for string pattern matching. Hard

9. Functions

Practice creating and using functions

  1. Write a program with functions that perform basic mathematical operations. Easy
  2. Create a program that demonstrates function parameters and return values. Medium
  3. Write a program that demonstrates default parameter values. Medium
  4. Create a program that uses keyword arguments and variable-length arguments. Hard
  5. Write a program that demonstrates lambda functions. Medium
  6. Create a program that uses recursion to solve a problem (e.g., factorial, Fibonacci). Hard
  7. Write a program that demonstrates the use of global and nonlocal keywords. Hard
  8. Create a program that uses function annotations. Hard
  9. Write a program that demonstrates closures and function factories. Hard
  10. Create a program that uses decorators to modify function behavior. Hard

10. File Handling

Practice reading from and writing to files

  1. Write a program that reads a text file and displays its contents. Easy
  2. Create a program that writes user input to a text file. Easy
  3. Write a program that demonstrates different file opening modes (r, w, a, r+, etc.). Medium
  4. Create a program that copies the contents of one file to another. Medium
  5. Write a program that counts the number of lines, words, and characters in a file. Medium
  6. Create a program that searches for a specific word or pattern in a file. Medium
  7. Write a program that demonstrates working with CSV files. Hard
  8. Create a program that demonstrates working with JSON files. Hard
  9. Write a program that uses the with statement for file handling. Medium
  10. Create a program that implements a simple file-based database system. Hard

11. Object-Oriented Programming (OOP)

Practice using classes and objects

  1. Write a program that defines a simple class with attributes and methods. Easy
  2. Create a program that demonstrates the __init__ method and instance variables. Medium
  3. Write a program that demonstrates inheritance and method overriding. Hard
  4. Create a program that uses class and static methods. Hard
  5. Write a program that demonstrates encapsulation using name mangling. Hard
  6. Create a program that demonstrates polymorphism and duck typing. Hard
  7. Write a program that uses abstract base classes (ABCs). Hard
  8. Create a program that demonstrates the use of properties and descriptors. Hard
  9. Write a program that implements operator overloading. Hard
  10. Create a program that demonstrates multiple inheritance and the MRO. Hard

12. Exception Handling

Practice handling errors and exceptions

  1. Write a program that demonstrates basic try-except blocks. Easy
  2. Create a program that handles multiple exception types. Medium
  3. Write a program that uses the else and finally clauses with try-except. Medium
  4. Create a program that raises custom exceptions. Hard
  5. Write a program that demonstrates exception chaining. Hard
  6. Create a program that creates a custom exception hierarchy. Hard
  7. Write a program that uses context managers (with statement) for resource management. Hard
  8. Create a program that implements a retry mechanism using exception handling. Hard
  9. Write a program that demonstrates the use of the warnings module. Hard
  10. Create a program that logs exceptions to a file. Hard

13. Modules and Packages

Practice organizing code into modules and packages

  1. Write a program that imports and uses functions from the math module. Easy
  2. Create a program that demonstrates different ways to import modules. Medium
  3. Write a program that creates and uses a custom module. Medium
  4. Create a program that demonstrates the use of the __name__ variable in modules. Medium
  5. Write a program that creates a package with multiple modules. Hard
  6. Create a program that uses the __init__.py file in a package. Hard
  7. Write a program that demonstrates relative imports within a package. Hard
  8. Create a program that uses third-party packages installed via pip. Hard
  9. Write a program that creates a namespace package. Hard
  10. Create a program that demonstrates the use of the importlib module. Hard

14. Advanced Python Concepts

Practice using advanced Python features

  1. Write a program that demonstrates generators and the yield keyword. Hard
  2. Create a program that uses iterators and the iter() and next() functions. Hard
  3. Write a program that demonstrates decorators with parameters. Hard
  4. Create a program that uses context managers with the contextlib module. Hard
  5. Write a program that demonstrates metaclasses. Hard
  6. Create a program that uses the asyncio module for asynchronous programming. Hard
  7. Write a program that demonstrates type hints and static type checking. Hard
  8. Create a program that uses data classes (Python 3.7+). Hard
  9. Write a program that demonstrates the use of the enum module. Hard
  10. Create a program that uses the dataclasses module to create immutable objects. Hard

15. Standard Library and Built-in Functions

Practice using Python's extensive standard library

  1. Write a program that uses the datetime module to work with dates and times. Medium
  2. Create a program that uses the collections module (deque, Counter, namedtuple). Hard
  3. Write a program that uses the itertools module for efficient looping. Hard
  4. Create a program that uses the functools module (partial, lru_cache, reduce). Hard
  5. Write a program that uses the os and sys modules for system operations. Hard
  6. Create a program that uses the random module for generating random data. Medium
  7. Write a program that uses the re module for regular expressions. Hard
  8. Create a program that uses the json module for JSON serialization/deserialization. Medium
  9. Write a program that uses the argparse module for command-line argument parsing. Hard
  10. Create a program that uses the logging module for application logging. Hard

Tips for Effective Practice

Start Simple

Begin with basic syntax and gradually move to more complex problems. Don't skip the fundamentals.

Practice Regularly

Consistency is key. Try to solve at least one problem every day to build and maintain your skills.

Understand, Don't Memorize

Focus on understanding the underlying concepts rather than memorizing solutions.

Build Projects

Apply what you've learned by building small projects that combine multiple concepts.