Learning Python becomes much easier when you practice writing programs regularly. Reading Python concepts is useful, but solving Python practice problems helps you understand programming logic and improve your coding skills.
If you are a beginner, B.Tech student, college student, or someone learning Python for the first time, this collection can help you practice important programming concepts step by step.
In this article, you will find 50+ Python practice problems with simple solutions. The problems cover variables, input and output, operators, conditional statements, loops, numbers, strings, lists, tuples, dictionaries, functions, patterns, searching, sorting, and basic problem-solving.
The examples are written in a simple way so beginners can understand and practice them easily.
Why Practice Python Problems?
Programming is a skill that improves through practice.
By solving Python problems, you can learn how to:
- Write Python programs
- Understand programming logic
- Use variables and data types
- Work with conditions
- Use loops
- Manipulate strings
- Work with lists and dictionaries
- Create functions
- Solve mathematical problems
- Find and fix errors
- Prepare for coding tests
- Prepare for practical exams
Try to solve each problem yourself before looking at the solution.
Python Practice Problems for Beginners
1. Print Hello World
Problem
Write a Python program to print “Hello World”.
Solution
print("Hello World")
Output
Hello World
This is one of the simplest Python programs and is useful for understanding the print() function.
2. Print Your Name
Problem
Write a program to print your name.
Solution
name = "Ravi"
print(name)
Output
Ravi
3. Add Two Numbers
Problem
Write a Python program to add two numbers.
Solution
a = 10
b = 20
sum = a + b
print(sum)
Output
30
4. Take Input from the User
Problem
Write a program to accept a name from the user and display it.
Solution
name = input("Enter your name: ")
print("Hello", name)
Example Output
Enter your name: Ravi
Hello Ravi
5. Find the Sum of Two User Inputs
Problem
Take two numbers from the user and find their sum.
Solution
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)
Example Output
Enter first number: 10
Enter second number: 20
Sum = 30
6. Find the Average of Three Numbers
Solution
a = 10
b = 20
c = 30
average = (a + b + c) / 3
print("Average =", average)
Output
Average = 20.0
7. Check Whether a Number Is Even or Odd
Problem
Write a program to check whether a number is even or odd.
Solution
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Example Output
Enter a number: 10
Even
The % operator returns the remainder.
8. Check Whether a Number Is Positive, Negative, or Zero
Solution
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
9. Find the Largest of Two Numbers
Solution
a = 25
b = 40
if a > b:
print("Largest =", a)
else:
print("Largest =", b)
Output
Largest = 40
10. Find the Largest of Three Numbers
Solution
a = 10
b = 50
c = 30
if a >= b and a >= c:
print(a)
elif b >= a and b >= c:
print(b)
else:
print(c)
Output
50
Number-Based Python Practice Problems
11. Find the Square of a Number
num = 5
square = num * num
print("Square =", square)
Output
Square = 25
12. Find the Cube of a Number
num = 4
cube = num ** 3
print("Cube =", cube)
Output
Cube = 64
13. Swap Two Numbers
Solution
a = 10
b = 20
a, b = b, a
print("a =", a)
print("b =", b)
Output
a = 20
b = 10
Python allows two variables to be swapped without using a third variable.
14. Find the Factorial of a Number
Solution
num = 5
fact = 1
for i in range(1, num + 1):
fact = fact * i
print("Factorial =", fact)
Output
Factorial = 120
15. Print Numbers from 1 to 10
for i in range(1, 11):
print(i)
Output
1
2
3
4
5
6
7
8
9
10
16. Print Even Numbers from 1 to 20
for i in range(1, 21):
if i % 2 == 0:
print(i)
Output
2
4
6
8
10
12
14
16
18
20
17. Print Odd Numbers from 1 to 20
for i in range(1, 21):
if i % 2 != 0:
print(i)
18. Find the Sum of Natural Numbers
Problem
Find the sum of numbers from 1 to 10.
Solution
total = 0
for i in range(1, 11):
total += i
print("Sum =", total)
Output
Sum = 55
19. Print a Multiplication Table
Solution
num = 5
for i in range(1, 11):
print(num, "x", i, "=", num * i)
Output
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
20. Count the Number of Digits
Solution
num = 12345
count = 0
while num > 0:
num = num // 10
count += 1
print("Digits =", count)
Output
Digits = 5
Prime Number Practice Problems
21. Check Whether a Number Is Prime
Solution
num = 7
if num < 2:
print("Not Prime")
else:
for i in range(2, num):
if num % i == 0:
print("Not Prime")
break
else:
print("Prime")
Output
Prime
A prime number has exactly two positive factors: 1 and itself.
22. Print Prime Numbers from 1 to 50
for num in range(2, 51):
for i in range(2, num):
if num % i == 0:
break
else:
print(num)
23. Find Factors of a Number
num = 12
for i in range(1, num + 1):
if num % i == 0:
print(i)
Output
1
2
3
4
6
12
24. Find the Sum of Digits
Solution
num = 1234
total = 0
while num > 0:
digit = num % 10
total += digit
num //= 10
print("Sum =", total)
Output
Sum = 10
25. Reverse a Number
Solution
num = 12345
reverse = 0
while num > 0:
digit = num % 10
reverse = reverse * 10 + digit
num //= 10
print("Reverse =", reverse)
Output
Reverse = 54321
Fibonacci and Special Number Problems
26. Print Fibonacci Series
Solution
n = 10
a = 0
b = 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b
Output
0 1 1 2 3 5 8 13 21 34
27. Check Armstrong Number
An Armstrong number is a number equal to the sum of its digits raised to the power of the number of digits.
For example:
153 = 1³ + 5³ + 3³
Solution
num = 153
temp = num
total = 0
while temp > 0:
digit = temp % 10
total += digit ** 3
temp //= 10
if total == num:
print("Armstrong Number")
else:
print("Not Armstrong Number")
Output
Armstrong Number
28. Check Palindrome Number
Solution
num = 121
if str(num) == str(num)[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
Output
Palindrome
Python String Practice Problems
29. Find the Length of a String
text = "Python"
print(len(text))
Output
6
30. Reverse a String
text = "Python"
print(text[::-1])
Output
nohtyP
31. Check Whether a String Is a Palindrome
text = "madam"
if text == text[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
Output
Palindrome
32. Count Vowels in a String
Solution
text = "python programming"
count = 0
for char in text:
if char.lower() in "aeiou":
count += 1
print("Vowels =", count)
33. Count Consonants in a String
text = "python"
count = 0
for char in text.lower():
if char.isalpha() and char not in "aeiou":
count += 1
print("Consonants =", count)
34. Count Words in a Sentence
text = "Python is easy to learn"
words = text.split()
print("Number of words =", len(words))
Output
Number of words = 5
35. Convert String to Uppercase
text = "python"
print(text.upper())
Output
PYTHON
36. Convert String to Lowercase
text = "PYTHON"
print(text.lower())
Output
python
37. Count Occurrence of a Character
text = "banana"
print(text.count("a"))
Output
3
Python List Practice Problems
38. Create and Print a List
numbers = [10, 20, 30, 40, 50]
print(numbers)
39. Find the Largest Element in a List
numbers = [10, 50, 20, 80, 30]
print("Largest =", max(numbers))
Output
Largest = 80
40. Find the Smallest Element in a List
numbers = [10, 50, 20, 80, 30]
print("Smallest =", min(numbers))
Output
Smallest = 10
41. Find the Sum of List Elements
numbers = [10, 20, 30, 40]
print("Sum =", sum(numbers))
Output
Sum = 100
42. Find the Average of List Elements
numbers = [10, 20, 30, 40]
average = sum(numbers) / len(numbers)
print("Average =", average)
Output
Average = 25.0
43. Remove Duplicate Elements from a List
numbers = [1, 2, 2, 3, 3, 4]
unique = list(set(numbers))
print(unique)
For applications where the original order must be preserved, use an order-preserving approach instead of relying on a set.
44. Sort a List
numbers = [5, 2, 8, 1, 3]
numbers.sort()
print(numbers)
Output
[1, 2, 3, 5, 8]
45. Reverse a List
numbers = [1, 2, 3, 4, 5]
numbers.reverse()
print(numbers)
Output
[5, 4, 3, 2, 1]
Python Dictionary Practice Problems
46. Create a Dictionary
student = {
"name": "Ravi",
"age": 20,
"course": "B.Tech"
}
print(student)
47. Access a Dictionary Value
student = {
"name": "Ravi",
"age": 20
}
print(student["name"])
Output
Ravi
48. Add an Item to a Dictionary
student = {
"name": "Ravi"
}
student["course"] = "B.Tech"
print(student)
49. Count Characters Using a Dictionary
text = "banana"
count = {}
for char in text:
count[char] = count.get(char, 0) + 1
print(count)
This type of problem is useful for understanding dictionaries and frequency counting.
Python Function Practice Problems
50. Create a Function to Add Two Numbers
def add(a, b):
return a + b
result = add(10, 20)
print(result)
Output
30
51. Create a Function to Check Even or Odd
def check_even_odd(num):
if num % 2 == 0:
return "Even"
return "Odd"
print(check_even_odd(10))
Output
Even
52. Create a Function to Find Factorial
def factorial(num):
result = 1
for i in range(1, num + 1):
result *= i
return result
print(factorial(5))
Output
120
Python Pattern Practice Problems
53. Print a Star Pattern
Solution
for i in range(1, 6):
print("*" * i)
Output
*
**
***
****
*****
54. Print a Number Pattern
for i in range(1, 6):
for j in range(1, i + 1):
print(j, end=" ")
print()
Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
55. Print a Square Pattern
for i in range(5):
print("* " * 5)
Output
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Python Searching Problems
56. Search for an Element in a List
numbers = [10, 20, 30, 40, 50]
target = 30
if target in numbers:
print("Element Found")
else:
print("Element Not Found")
Output
Element Found
57. Find the Position of an Element
numbers = [10, 20, 30, 40]
target = 30
if target in numbers:
print("Position =", numbers.index(target))
else:
print("Not Found")
Output
Position = 2
Remember that Python list indexing starts from 0.
Python Sorting Problems
58. Sort Numbers in Ascending Order
numbers = [5, 1, 8, 2, 3]
numbers.sort()
print(numbers)
Output
[1, 2, 3, 5, 8]
59. Sort Numbers in Descending Order
numbers = [5, 1, 8, 2, 3]
numbers.sort(reverse=True)
print(numbers)
Output
[8, 5, 3, 2, 1]
Beginner Python Problem-Solving Challenges
After completing the basic problems above, try solving these problems yourself before checking a solution.
60. Find the Second Largest Number
Given:
10, 20, 50, 30, 40
Find the second-largest number.
Expected output:
40
61. Count Even and Odd Numbers
Given a list of numbers, count how many numbers are even and how many are odd.
Example:
[1, 2, 3, 4, 5, 6]
Expected result:
Even = 3
Odd = 3
62. Find Common Elements
Given two lists, find the elements that appear in both lists.
Example:
List 1 = [1, 2, 3, 4]
List 2 = [3, 4, 5, 6]
Expected output:
3 4
63. Find Duplicate Elements
Write a program to find duplicate values in a list.
Example:
[1, 2, 2, 3, 4, 4]
Expected output:
2 4
64. Find the Frequency of Each Number
Given:
[1, 2, 2, 3, 3, 3]
Expected output:
1 : 1
2 : 2
3 : 3
65. Merge Two Lists
Given two lists, combine them into a single list.
Example:
[1, 2, 3]
[4, 5, 6]
Expected output:
[1, 2, 3, 4, 5, 6]
66. Find Missing Number
Given:
[1, 2, 3, 5]
Find the missing number.
Expected output:
4
67. Check Whether Two Strings Are Anagrams
Two strings are anagrams if they contain the same characters with the same frequencies.
Example:
listen
silent
Expected output:
Anagram
68. Find the Longest Word
Given:
Python is easy to learn
Find the longest word.
Expected output:
Python
69. Remove Spaces from a String
Given:
Python programming
Expected output:
Pythonprogramming
70. Count Uppercase and Lowercase Characters
Given a string, count uppercase and lowercase characters.
Example:
Python PROGRAM
Find:
Uppercase = 7
Lowercase = 6
How to Practice Python Problems Effectively
Simply reading solutions is not enough. Follow a simple practice method.
Step 1: Read the Problem
Understand exactly what the program needs to do.
For example:
Find whether a number is even or odd.
The important concept is the modulus operator.
Step 2: Think About the Logic
Before writing code, think about the steps.
For even or odd:
- Get the number.
- Divide it by 2.
- Check the remainder.
- If the remainder is 0, it is even.
- Otherwise, it is odd.
Step 3: Write the Code
Convert your logic into Python syntax.
Step 4: Test Different Inputs
Do not test only one value.
For an even/odd program, test:
10
7
0
-4
-5
This helps you understand how your program behaves in different situations.
Step 5: Find and Fix Errors
You may encounter:
- Syntax errors
- Name errors
- Type errors
- Value errors
- Logical errors
- Runtime errors
Debugging is an important part of learning programming.
Common Python Topics to Practice
If you are preparing for a college practical exam or coding test, focus on these topics:
Python Basics
- Variables
- Data types
- Input
- Output
- Type conversion
Operators
- Arithmetic operators
- Comparison operators
- Logical operators
- Assignment operators
- Membership operators
Conditions
ifif-elseelif- Nested conditions
Loops
forwhilebreakcontinuepass
Strings
- String slicing
- String methods
- Searching
- Replacing
- Counting
- Reversing
Collections
- Lists
- Tuples
- Sets
- Dictionaries
Functions
- Parameters
- Arguments
- Return values
- Default arguments
- Lambda functions
Problem Solving
- Prime numbers
- Factorial
- Fibonacci
- Palindrome
- Armstrong numbers
- Number reversal
- Searching
- Sorting
- Pattern programs
Tips for Beginners
Practice Every Day
Try solving at least 3–5 Python problems every day.
Even small programs can improve your programming logic.
Don’t Copy the Solution Immediately
First try to solve the problem yourself.
If you get stuck, look at the solution and understand the logic.
Modify Existing Programs
After completing a program, change it.
For example, if you write a program to print even numbers from 1 to 20, modify it to print even numbers from 1 to 100.
Practice Without Looking at Notes
After learning a program, close your notes and try writing it again.
This is especially useful before practical examinations.
Understand the Output
Try predicting the output before running the program.
This improves your understanding of Python execution.
Frequently Asked Questions
What are Python practice problems?
Python practice problems are programming questions designed to help learners improve their Python coding and problem-solving skills.
Are these Python problems suitable for beginners?
Yes. The problems start with basic concepts and gradually move toward lists, strings, functions, searching, sorting, and problem-solving.
How many Python problems should I solve daily?
Beginners can start with 3–5 problems per day. As your confidence improves, you can solve more challenging problems.
Which Python problems should beginners practice first?
Start with basic input/output, arithmetic operations, even or odd numbers, positive or negative numbers, loops, factorial, Fibonacci, strings, lists, and functions.
Are Python practice problems useful for B.Tech students?
Yes. Practicing Python problems can help B.Tech students prepare for programming labs, practical examinations, coding tests, and basic technical interviews.
Should I memorize Python programs?
It is better to understand the logic instead of memorizing complete programs. Once you understand the logic, you can write similar programs independently.
Conclusion
Practicing programming problems is one of the best ways to improve your Python skills. Beginners should start with simple programs and gradually move toward more challenging problems.
In this article, we covered 50+ Python practice problems and additional coding challenges involving numbers, strings, lists, dictionaries, functions, loops, patterns, searching, and sorting.
Do not simply copy the solutions. First read each problem, think about the logic, write your own code, run it, and test it with different inputs.
With regular practice, you can improve your Python programming skills and become more confident in solving coding problems.
Keep practicing Python problems and gradually move from beginner-level exercises to intermediate and advanced programming challenges.





