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
- Practice 10–15 programs daily.
- Always dry run programs before final exam.
- Write comments to explain logic (helps in step marking).
- Revise past year board papers.
Related Reading 📖
📞 Contact Amit Sir
Want to master Python for CBSE Class 12? Book your 1-on-1 demo session today:
📱 Call Now 💬 WhatsApp