Amit Sir – CBSE Python Tutor

Top Python Programs You Must Practice for CBSE Class 12 Computer Science

By Amit Sir | August 16, 2025

Why Python Programs Matter in CBSE Class 12 CS

Python forms the backbone of the CBSE Class 12 Computer Science exam. The board gives heavy weightage to programs involving loops, functions, file handling, and SQL integration. By mastering these, you can confidently attempt any coding question and secure 95+ marks.

1. Program to Check Prime Numbers

n = int(input("Enter a number: "))
flag = True
for i in range(2, n//2 + 1):
    if n % i == 0:
        flag = False
        break
if flag:
    print(n, "is Prime")
else:
    print(n, "is Not Prime")

2. Fibonacci Series using Recursion

def fibonacci(n):
    if n <= 1:
        return n
    else:
        return fibonacci(n-1) + fibonacci(n-2)

terms = int(input("Enter terms: "))
for i in range(terms):
    print(fibonacci(i))

3. Count Words in a Text File

with open("story.txt", "r") as f:
    data = f.read()
    words = data.split()
    print("Total Words:", len(words))

4. Stack Implementation using List

stack = []
stack.append(10)
stack.append(20)
print("Stack:", stack)
print("Popped:", stack.pop())

5. SQL Integration with Python

import mysql.connector
mydb = mysql.connector.connect(host="localhost", user="root", passwd="1234", database="school")
cur = mydb.cursor()
cur.execute("SELECT * FROM student")
for row in cur.fetchall():
    print(row)

Tips for Scoring 95+ in Python Section

Related Reading 📖

  • Success Stories of CBSE CS & IP Toppers to stay motivated.
  • How to Score 90+ in ICSE Computer Applications
  • Common Mistakes in ICSE Computer Applications
  • ICSE & CBSE Computer Tuition – Home
  • 📞 Contact Amit Sir

    Want to master Python for CBSE Class 12? Book your 1-on-1 demo session today:

    📱 Call Now 💬 WhatsApp