Skip to content

Latest commit

 

History

History
325 lines (213 loc) · 9.65 KB

File metadata and controls

325 lines (213 loc) · 9.65 KB

🐍 100 Python Exercises from Beginner to Expert

This repository contains a curated list of 100 Python exercises, from beginner to expert level, to help you master Python through hands-on problem solving.


🔰 Beginner Python Exercises (1–25)

  1. Hello World
    Print "Hello, World!" to the console.

  2. User Input Greeting
    Ask the user for their name using input() and print a personalized greeting like "Hello, John!".

  3. Swap Two Numbers
    Swap two variables a = 5, b = 10 without using a third variable. Print the swapped values.

  4. Even or Odd
    Given a number input by the user, check if it is even or odd using the modulus operator %.

  5. Largest of Three Numbers
    Compare three numbers (e.g., a = 12, b = 25, c = 9) and print the largest.

  6. Prime Number Check
    Take an integer input from the user and print whether it is a prime number.

  7. Fibonacci Series
    Print the first 10 Fibonacci numbers starting from 0.

  8. Factorial Calculation
    Write a function that takes a number and returns its factorial using recursion.

  9. Multiplication Table
    Ask the user for a number and print its multiplication table up to 10.

  10. Reverse a String
    Input a string and print its reverse (e.g., "hello""olleh").

  11. Vowel Count
    Count how many vowels appear in a string like "I'm learning Python".

  12. Palindrome Check
    Check whether the word "radar" is a palindrome.

  13. Remove Duplicates
    Remove duplicates from the list [1, 2, 2, 3, 4, 4, 5] and return [1, 2, 3, 4, 5].

  14. Sum of List
    Calculate the sum of elements in the list [10, 20, 30, 40, 50].

  15. Sort List Ascending
    Sort the list [5, 3, 8, 1, 9] in ascending order using a loop or the sorted() function.

  16. Max and Min in List
    Find the largest and smallest numbers in [12, 55, 2, 98, 1].

  17. Frequency Counter
    Count the frequency of elements in ["apple", "banana", "apple", "orange", "banana"].

  18. Simple Calculator
    Create a program that asks the user for two numbers and performs all basic arithmetic operations.

  19. Celsius to Fahrenheit
    Ask the user for a Celsius temperature and convert it to Fahrenheit.

  20. List Comprehension Squares
    Generate a list of squares from 1 to 10 using list comprehension: [1, 4, 9, ...].

  21. Merge Dictionaries
    Merge dict1 = {"a": 1, "b": 2} with dict2 = {"c": 3, "d": 4}.

  22. List Length Without len()
    Count how many elements are in [1, 2, 3, 4, 5, 6] without using the len() function.

  23. String Case Conversion
    Convert the string "Python Is Fun" to lowercase and uppercase.

  24. Substring Search
    Check if the word "fun" is present in the string "Python is fun to learn".

  25. Print Odd Numbers
    Print all odd numbers from 1 to 100 using a loop and if condition.


⚙️ Intermediate Python Exercises (26–60)

  1. Common Elements in Lists
    Find common items in [1, 2, 3, 4] and [3, 4, 5, 6][3, 4].

  2. Remove Punctuation
    Remove all punctuation from "Hello, World! Welcome...".

  3. Sort Dictionary by Value
    Sort {'a': 3, 'b': 1, 'c': 2} by value.

  4. Use map() and filter()
    Square a list with map() and filter even numbers using filter() on [1, 2, 3, 4, 5].

  5. Anagram Checker
    Check if "listen" and "silent" are anagrams.

  6. Flatten Nested List
    Flatten [[1, 2], [3, 4], [5]] to [1, 2, 3, 4, 5].

  7. Second Largest Element
    Find the second largest number in [3, 5, 1, 9, 7].

  8. Word Count in String
    Count how many words in "This is a sample sentence.".

  9. Check Sorted List
    Determine if [1, 2, 3, 4, 5] is sorted.

  10. Binary Search
    Perform binary search to find 7 in [1, 3, 5, 7, 9].

  11. List to Dictionary
    Convert [("a", 1), ("b", 2)] into a dictionary.

  12. Random Password Generator
    Generate a random password with length 8 including letters and digits.

  13. Number Guessing Game
    User tries to guess a number between 1 and 100 until correct.

  14. Email Validator
    Check if user@example.com is a valid email using regex.

  15. File Read/Write
    Write "Hello" to a file and then read it.

  16. Paragraph Word Frequency
    Count the frequency of each word in a multi-line string.

  17. Extract Digits from String
    Extract digits from "abc123def456"[1,2,3,4,5,6].

  18. Contact Book CLI
    Create a contact book: Add, remove, and list contacts.

  19. To-Do List App
    Implement CLI for adding/removing/listing tasks.

  20. Replace Spaces with Hyphens
    Replace all spaces in "Hello World Python""Hello-World-Python".

  21. Diamond Pattern
    Print a diamond star pattern of height 5.

  22. Decimal to Binary Converter
    Convert 25 into binary manually.

  23. Case Counter
    Count uppercase and lowercase letters in "PyTHon".

  24. Armstrong Numbers in Range
    Print all 3-digit Armstrong numbers.

  25. LCM and GCD Calculator
    Calculate LCM and GCD of 8 and 12.

  26. Stack with List
    Push and pop elements using a list as a stack.

  27. Queue with List
    Enqueue and dequeue elements from a list.

  28. Zip and Merge Lists
    Combine ['a', 'b'] and [1, 2] into [('a',1), ('b',2)].

  29. Countdown Timer
    Countdown from 10 to 0 with time.sleep().

  30. Calendar Display
    Display calendar for August 2025 using calendar.

  31. Lambda Sorting
    Sort [(1, 'a'), (3, 'c'), (2, 'b')] by the second element.

  32. Dice Simulator
    Simulate rolling a dice using random.randint().

  33. List Shuffler
    Shuffle a list randomly.

  34. URLify a String
    Replace spaces in "Hello World" with %20.

  35. CSV Column Counter
    Read a CSV file and count values in a specific column.


🧠 Advanced Python Exercises (61–85)

  1. Singly Linked List
    Implement a basic singly linked list with insert and display methods.

  2. Execution Time Decorator
    Write a decorator to log function execution time.

  3. OOP with Inheritance
    Create a Vehicle class and subclass Car with unique behavior.

  4. Method Overriding
    Override a method in the child class.

  5. Static and Class Methods
    Use @staticmethod and @classmethod in a class.

  6. Custom Iterator
    Build a custom iterator for squares of numbers up to N.

  7. Bank Account Class
    Create a class with deposit/withdrawal methods and balance tracking.

  8. Pickle Serialization
    Serialize a dictionary and save/load it using pickle.

  9. Prime Number Generator
    Use yield to make an infinite prime number generator.

  10. Command-Line Calculator
    Build a calculator using argparse.

  11. Regex Date Extractor
    Extract all dates from a string like "Today is 12/07/2025".

  12. Login System with Hashing
    Create a system that stores hashed passwords using hashlib.

  13. Web Scraper
    Scrape titles from a blog using requests and BeautifulSoup.

  14. SQLite CRUD
    Perform create, read, update, delete operations with SQLite.

  15. Build a Flask API
    Make a simple REST API with Flask and return JSON responses.

  16. Stack with Error Handling
    Extend your stack to handle underflow/overflow exceptions.

  17. Tic-Tac-Toe Game
    Create a 2-player command-line game.

  18. Rule-based Chatbot
    Respond to user greetings like "hi" or "bye" using if/else.

  19. Quiz Game with JSON
    Load questions and answers from a JSON file and quiz the user.

  20. Parse Nested JSON
    Extract specific data from nested JSON.

  21. Custom List Class
    Implement a class that mimics list behavior (append, remove).

  22. Shopping Cart System
    Simulate adding/removing items and calculating total.

  23. Unit Test with unittest
    Write test cases for a calculator app.

  24. Image Downloader
    Download an image from a URL using requests.

  25. Memoization with lru_cache
    Use functools.lru_cache to optimize a recursive function.


🚀 Expert Python Exercises (86–100)

  1. N-Queens Solver
    Solve the N-Queens puzzle using backtracking.

  2. Recursive File Explorer
    List all files and folders recursively from a given path.

  3. Merge Sort Implementation
    Implement merge sort manually.

  4. Quick Sort Implementation
    Implement quick sort manually.

  5. Sudoku Solver
    Create a solver that uses backtracking to solve Sudoku boards.

  6. Paginated Web Scraper
    Scrape all product pages from a paginated site.

  7. Multithreaded Downloader
    Download multiple files in parallel using threads.

  8. Autocomplete with Trie
    Build an autocomplete system using the Trie data structure.

  9. Keylogger (Ethical)
    Log keystrokes for personal keyboard learning use (not for misuse).

  10. Custom Encryption/Decryption
    Design a reversible string encryption method.

  11. Train ML Model with Scikit-learn
    Train a simple model using scikit-learn to predict house prices.

  12. Snake Game in Terminal
    Create a Snake game using curses.

  13. Telegram Bot
    Create a Telegram bot that responds to /start command.

  14. Distribute CLI Tool
    Build a command-line app and publish with setuptools.

  15. Publish to PyPI
    Create your own Python package and upload it to PyPI.


📄 License

This project is open-source and free to use under the MIT License.