Once beginners understand basic Python syntax, the next step is practice. Reading alone does not help much. Writing small programs again and again is what builds confidence. This article lists Python programs every student should practice, especially those learning Python for the first time. These programs are commonly taught in schools, colleges, and beginner courses, and they help strengthen core concepts like input, conditions, loops, and logic.
Python Programs Every Student Should Practice

1. Check Whether a Number Is Prime
This program helps students understand loops and conditional checks.
Python Code
num = int(input("Enter a number: "))
flag = True
if num <= 1:
flag = False
else:
for i in range(2, num):
if num % i == 0:
flag = False
break
if flag:
print("Prime number")
else:
print("Not a prime number")
Explanation
A prime number is divisible only by 1 and itself. This program checks divisibility using a loop.
2. Generate Fibonacci Series
This is a very common program asked in exams.
Python Code
n = int(input("Enter number of terms: "))
a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a + b
Explanation
The Fibonacci series is formed by adding the previous two numbers. This program uses variables and a loop.
3. Check Whether a Number Is a Palindrome
This program introduces string handling.
Python Code
num = input("Enter a number: ")
if num == num[::-1]:
print("Palindrome")
else:
print("Not a palindrome")
Explanation
A palindrome reads the same forwards and backwards. The slicing method reverses the string.
4. Count Vowels in a String
Useful for understanding loops and conditions.
Python Code
text = input("Enter a string: ")
count = 0
for ch in text:
if ch.lower() in "aeiou":
count += 1
print("Number of vowels:", count)
Explanation
The program checks each character and increases the count if it is a vowel.
5. Find the Sum of Digits of a Number
This helps students understand loops and number manipulation.
Python Code
num = int(input("Enter a number: "))
total = 0
while num > 0:
total += num % 10
num //= 10
print("Sum of digits:", total)
Explanation
Each digit is separated using modulo and added to the total.
6. Swap Two Numbers (Without Using a Third Variable)
A classic beginner problem.
Python Code
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
a, b = b, a
print("After swapping:")
print("a =", a)
print("b =", b)
Explanation
Python allows swapping values directly without using an extra variable.
7. Find the Largest of Three Numbers
Builds conditional logic.
Python Code
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest:", a)
elif b >= a and b >= c:
print("Largest:", b)
else:
print("Largest:", c)
8. Count the Number of Words in a Sentence
Introduces basic string operations.
Python Code
sentence = input("Enter a sentence: ")
words = sentence.split()
print("Number of words:", len(words))
Explanation
The split() function breaks the sentence into words.
9. Check Whether a Year Is a Leap Year
Very common in exams.
Python Code
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap year")
else:
print("Not a leap year")
10. Display a Simple Star Pattern
Introduces nested loops.
Python Code
rows = int(input("Enter number of rows: "))
for i in range(1, rows + 1):
print("*" * i)
Explanation
The loop controls how many stars are printed in each row.
Conclusion
These Python programs are commonly practised by students because they strengthen logical thinking and basic coding skills. Practising these regularly makes it easier to understand more advanced Python concepts later.
Once comfortable with these programs, students can move on to small Python mini projects.
Leave a Reply