Monday, September 14, 2026

30 Free Python Practice Exercises for Beginners

If you want to enhance your skills as a Python programmer or learn a new course like Data Science or Data Analytics, start by practicing these 30 problems. Before looking for answers online, take the time to fully understand and learn how to solve each problem on your own.

30 Python Problems — Helpful for Data Science Beginners

Level 1 — Basic Logic

1. Even or Odd

Take a number from the user and print whether it is even or odd.

Example:

Input: 55
Output: Odd

2. Positive, Negative or Zero

Input: 12
Output: positive

3. Find the Largest of Three Numbers

Input: 30, 25, 15, 10
Output: 30

4. Sum of Numbers 1 to N

Input: 9
Output: 45

5. Multiplication Table

Input: 7

5 x 1 = 5
5 x 2 = 10
...
5 x 10 = 50

Level 2 — Loops

6. Print Numbers 1–100

Print all numbers from 1 to 100.

Then modify it to print only even numbers.

7. Sum of Even Numbers

Input: 8
Output: 20

Because:

2 + 4 + 6 + 8 = 20

8. Count Digits

Input: 12345678
Output: 8

9. Reverse a Number

Input: 12321
Output: 12321

10. Find Factorial

Input: 3
Output: 6

Level 3 — Strings

These are particularly useful because data often comes as text.

11. Count Vowels

Input: "data science"
Output: 5

12. Reverse a String

Input: "Python"
Output: "nohtyP"

13. Check Palindrome

Input: "madam"
Output: Palindrome

14. Count Words

Input: "Using Python for Data Science"
Output: 5

15. Find the Most Frequent Character

Input: "programming"

Output:
m = 2

Try to make your program work with any string.

Level 4 — Lists

This section is very important before Pandas.

16. Find Maximum and Minimum

numbers = [10, 25, 3, 45, 18]

Expected:

Maximum: 45
Minimum: 3

17. Calculate Average

numbers = [10, 20, 30, 40, 50]

Expected:

Average: 30

18. Count Even and Odd Numbers

numbers = [10, 15, 22, 31, 40, 55]

Expected:

Even: 3
Odd: 3

19. Remove Duplicates

numbers = [10, 20, 10, 30, 20, 40]

Expected:

[10, 20, 30, 40]

20. Find the Second Largest Number

numbers = [10, 50, 20, 80, 40]

Expected:

Second largest: 50

Level 5 — Dictionaries

Dictionaries are extremely important for understanding structured data.

21. Student Marks

student = {
    "name": "Rahul",
    "math": 80,
    "science": 75,
    "english": 90
}

Calculate the student's average marks.

22. Find Highest Scoring Student

students = {
    "Rahul": 85,
    "Amit": 92,
    "Priya": 88,
    "Neha": 95
}

Expected:

Neha: 95

23. Count Word Frequency

Input:
"python is easy and python is powerful"

Expected approximately:

python: 2
is: 2
easy: 1
and: 1
powerful: 1

24. Find Employees With Salary > 50,000

employees = {
    "Rahul": 45000,
    "Amit": 65000,
    "Priya": 55000,
    "Neha": 40000
}

Expected:

Amit
Priya

25. Calculate Department Average Salary

Use:

employees = {
    "Rahul": {"department": "IT", "salary": 50000},
    "Amit": {"department": "HR", "salary": 45000},
    "Priya": {"department": "IT", "salary": 60000},
    "Neha": {"department": "HR", "salary": 55000}
}

Calculate:

IT Average = 55000
HR Average = 50000

This is a very good preparation for Pandas groupby().

Level 6 — Data-Science Style Problems

Now things become more interesting.

26. Sales Analysis

Given:

sales = [1200, 1500, 800, 2200, 1800, 950, 3000]

Find:

  • Total sales
  • Average sales
  • Highest sales
  • Lowest sales
  • Number of days with sales > 1500

27. Customer Data Cleaning

Given:

names = [
    "Rahul",
    " amit ",
    "PRIYA",
    "neha",
    " Rahul "
]

Clean the names so that the output becomes:

Rahul
Amit
Priya
Neha
Rahul

You'll practice:

strip()
lower()
upper()
title()

These operations become very useful in real data cleaning.

28. Missing Values

Given:

marks = [80, 90, None, 70, None, 85]

Calculate the average without including None.

Expected:

Average = 81.25

This prepares you for handling missing values in Pandas.

29. Sales by Category

Given:

sales = [
    {"product": "Laptop", "category": "Electronics", "sales": 50000},
    {"product": "Mouse", "category": "Electronics", "sales": 5000},
    {"product": "Chair", "category": "Furniture", "sales": 10000},
    {"product": "Table", "category": "Furniture", "sales": 20000}
]

Calculate total sales for each category.

Expected:

Electronics: 55000
Furniture: 30000

This is basically preparing your brain for:

df.groupby("category")["sales"].sum()

30. Mini Data Analysis Project

Finally, create your own dataset:

employees = [
    {"name": "Rahul", "age": 28, "department": "IT", "salary": 55000},
    {"name": "Amit", "age": 32, "department": "HR", "salary": 48000},
    {"name": "Priya", "age": 26, "department": "IT", "salary": 62000},
    {"name": "Neha", "age": 30, "department": "Sales", "salary": 50000},
    {"name": "Raj", "age": 35, "department": "IT", "salary": 75000}
]

Answer:

  1. What is the average age?
  2. What is the average salary?
  3. Who has the highest salary?
  4. Who has the lowest salary?
  5. How many employees are in IT?
  6. What is the average IT salary?
  7. Who earns more than ₹50,000?
  8. What is the highest salary in each department?

Conclusion

If you have learned the basics of Python programming, I’m sure you can complete these 30 exercises on your own. These exercises are designed to strengthen your Python coding skills through hands-on practice. They will also help you better understand how Python is used in real-world data science projects and give you a practical understanding of common data-handling and problem-solving approaches.

No comments:

Post a Comment

Featured Post

Python OOPs Advanced: Class Variables and Instance Variables

We have learned how to create classes and objects . Now, we will explore class variables and instance variables in Python, including how the...