📝 Unit 1 Board Questions + Practice
2026-27 syllabus में Unit 1 के 40 marks हैं। Part A में 36 नए practice questions answers के साथ हैं (पहले ख़ुद हल करें, फिर "Answer देखें" दबाएँ)। Part B में पिछले CBSE board papers (2022, 2023, 2026) के Unit 1 के सभी 47 questions original रूप में हैं – tables, code और internal choice सहित, हर एक के answer के साथ। Questions board paper की तरह English में हैं।
1) पहले unit के lessons पढ़ें। 2) Part A notebook में हल करें, फिर answers मिलाएँ। 3) Part B को paper-wise timer लगाकर हल करें – लगभग 1.5 minute प्रति mark। 4) गलत हुए questions पर निशान लगाएँ और उस lesson को दोबारा पढ़ें।
Part A – Practice questions (answers के साथ)
State the types of 42 and 42.0. Are the types identical?
Answer देखें
int and float; the types differ.
Evaluate: 7 + 12 // 5 * 2 - 9 % 4
Answer देखें
10.
Predict both outputs.
print('sCHOOL cODE'.capitalize())
print('book:file:read'.partition(':'))Answer देखें
School code; ('book', ':', 'file:read').
Predict the output.
print('COMPUTER'[-1:1:-2])Answer देखें
RTP.
Which operation is invalid for t=(4,8,12)? (A) t[1] (B) t[1:] (C) t.append(16) (D) len(t)
Answer देखें
C; tuples have no append method.
Predict the result.
d = {'A':10, 'B':20, 'A':30}
print(len(d), d['A'])Answer देखें
2 30.
For L=[2,4,6], which raises IndexError: L.pop(2), L.pop(3), L.insert(3,8), or L.append(8)? Treat each independently.
Answer देखें
L.pop(3).
Name the file mode that appends binary records without truncating existing contents.
Answer देखें
ab.
Predict the exact output, including the printed return value.
def add(a, b=4):
print(a+b, end='#')
x = add(3)
print(x)Answer देखें
7#None.
Predict the two lines of output.
x = 10
def f():
x = 3
print(x)
f()
print(x)Answer देखें
3 then 10. Assignment inside f creates a local x.
Predict the final output and explain why the list and integer behave differently.
def change(items, n):
items.append(9)
n += 1
L = [1,2]
a = 5
change(L,a)
print(L,a)Answer देखें
[1, 2, 9] 5. The list object is mutated; n is locally rebound.
Define total(price, qty=2) to return price*qty. Show calls using the default quantity and a positional quantity of 5.
Answer देखें
Function and calls:
def total(price, qty=2):
return price * qty
print(total(100))
print(total(100,5))For d={"R1":80}, use a dictionary method to add R2:75 only if absent, then retrieve R3 with fallback value 0.
Answer देखें
d.setdefault('R2',75)
d.get('R3',0)Write statements to create a sorted copy of L=[8,3,6] without modifying L, then add the individual elements 10 and 12 to L.
Answer देखें
new=sorted(L) L.extend([10,12])
Give all possible values of x and the number of loop iterations. Can the code print 40?
import random
L = [10,20,30,40]
for i in range(3):
x = random.randrange(1,3)
print(L[x], end=' ')Answer देखें
x is 1 or 2; three iterations; outputs are 20 or 30, never 40.
Correct the function so that it returns the number of uppercase characters.
def count_upper(s)
n = 0
for ch in range(s):
if ch.isupper:
n =+ 1
return chAnswer देखें
Corrected function:
def count_upper(s):
n = 0
for ch in s:
if ch.isupper():
n += 1
return nPredict the output and name the handled exception.
try:
print(12//0)
except ZeroDivisionError:
print('Invalid division')
finally:
print('Finished')Answer देखें
Invalid division, then Finished. ZeroDivisionError is handled.
Show one built-in function, one function imported from a module and one user-defined function. Give a valid import and call for the module function.
Answer देखें
Examples: len([1,2]); from math import sqrt followed by sqrt(81); a user-defined total(price,qty) function.
Define adjust(L) to increase each even integer by 2 and decrease each odd integer by 2, modifying L in place. State the result for [4,7,10,13].
Answer देखें
Result [6,5,12,11].
def adjust(L):
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] += 2
else:
L[i] -= 2Define frequency(text) to return a dictionary counting each character, ignoring spaces and letter case. State the result for "A aB".
Answer देखें
{'a':2,'b':1}
def frequency(text):
counts = {}
for ch in text.lower():
if ch != ' ':
counts[ch] = counts.get(ch,0) + 1
return countsDefine count_digits(filename) to count and return digit characters in a text file. For text "Lab 12 has 8 PCs", the result must be 3.
Answer देखें
One valid solution:
def count_digits(filename):
count = 0
with open(filename,'r',encoding='utf-8') as f:
for ch in f.read():
if ch.isdigit():
count += 1
return countDefine show_lines(filename) to display only lines with at least 6 whitespace-separated words, without inserting extra blank lines.
Answer देखें
One valid solution:
def show_lines(filename):
with open(filename,'r',encoding='utf-8') as f:
for line in f:
if len(line.split()) >= 6:
print(line,end='')Define copy_clean(source,target) to copy only lines that do not contain the letter a in either case. The source and target are different files.
Answer देखें
One valid solution:
def copy_clean(source,target):
with open(source,'r',encoding='utf-8') as src:
with open(target,'w',encoding='utf-8') as dst:
for line in src:
if 'a' not in line.lower():
dst.write(line)Assume data.bin contains exactly the ASCII bytes ABCDEFG. Predict all four outputs.
with open('data.bin','rb') as f:
print(f.read(2))
print(f.tell())
f.seek(1)
print(f.read(3))
print(f.tell())Answer देखें
b'AB'; 2; b'BCD'; 4.
Differentiate r, w and a for text files. Explain relative versus absolute paths with examples.
Answer देखें
r reads and requires an existing file; w writes and truncates/creates; a appends/creates. Relative path: data/marks.txt from the current working directory. Absolute path: /school/data/marks.txt on a Unix-like system.
Define push_merit(records,stack). Each record is [Name,Marks]. Push the names having Marks >= 85, preserving input order. For [["Asha",90],["Bilal",78],["Charu",88]], an initially empty stack becomes ["Asha","Charu"].
Answer देखें
One valid solution:
def push_merit(records,stack):
for name,marks in records:
if marks >= 85:
stack.append(name)Define pop_one(stack) to return the top item, or print UNDERFLOW and return None if empty. Define display(stack) to print items top-first without changing the stack.
Answer देखें
One valid solution:
def pop_one(stack):
if not stack:
print('UNDERFLOW')
return None
return stack.pop()
def display(stack):
for item in stack[::-1]:
print(item)Create books.csv with header BookID,Title,Price and records [101,"Python",450], [102,"SQL",380]. Use csv.writer and writerows. Include file closure.
Answer देखें
One valid solution:
import csv
with open('books.csv','w',newline='',encoding='utf-8') as f:
w = csv.writer(f)
w.writerow(['BookID','Title','Price'])
w.writerows([[101,'Python',450],[102,'SQL',380]])Read books.csv from U1-28 and append only records with Price >= 400 to costly.csv. Do not copy the header. Convert the CSV price field to a number before comparing.
Answer देखें
One valid solution:
import csv
with open('books.csv','r',newline='',encoding='utf-8') as src:
with open('costly.csv','a',newline='',encoding='utf-8') as dst:
rows = csv.reader(src)
next(rows,None)
w = csv.writer(dst)
for row in rows:
if row and float(row[2]) >= 400:
w.writerow(row)Define append_student(filename,roll,name,marks) to append the list [roll,name,marks] as one pickled record to a binary file. Define create_empty(filename) to create/truncate a binary file.
Answer देखें
One valid solution:
import pickle
def append_student(filename,roll,name,marks):
with open(filename,'ab') as f:
pickle.dump([roll,name,marks],f)
def create_empty(filename):
with open(filename,'wb'):
passA trusted binary file stores consecutive pickled [roll,name,marks] records with unique rolls. Define find_student(filename,target) to return the matching record, or None if absent. Handle normal end-of-file.
Answer देखें
One valid solution:
import pickle
def find_student(filename,target):
with open(filename,'rb') as f:
while True:
try:
rec = pickle.load(f)
except EOFError:
return None
if rec[0] == target:
return recFor the file format in U1-31, define update_marks(filename,target,newmarks) to update the matching unique roll, preserving all other records. Return True if found, else False. Read records before reopening for writing.
Answer देखें
A read-then-rewrite solution avoids assuming equal pickle record sizes:
import pickle
def update_marks(filename,target,newmarks):
records = []
found = False
with open(filename,'rb') as f:
while True:
try:
rec = pickle.load(f)
except EOFError:
break
if rec[0] == target:
rec[2] = newmarks
found = True
records.append(rec)
if found:
with open(filename,'wb') as f:
for rec in records:
pickle.dump(rec,f)
return foundDefine count_pass(filename) for the same binary format to count records with marks >= 33. Handle normal EOF and return the count.
Answer देखें
One valid solution:
import pickle
def count_pass(filename):
count = 0
with open(filename,'rb') as f:
while True:
try:
rec = pickle.load(f)
except EOFError:
break
if rec[2] >= 33:
count += 1
return countTrace the function and write its output.
def build(s):
result = []
for ch in s:
if ch.isdigit():
result.reverse()
elif ch not in result:
result.append(ch)
return ''.join(result)
print(build('ab2ac3'))Answer देखें
cab.
Write a program that reads two integer inputs and prints their quotient. Handle non-integer input and division by zero separately. Always print Done using finally.
Answer देखें
One valid solution:
try:
a = int(input('First integer: '))
b = int(input('Second integer: '))
print(a/b)
except ValueError:
print('Enter integers only')
except ZeroDivisionError:
print('Divisor cannot be zero')
finally:
print('Done')For a text file, distinguish read(), readline() and readlines(). Explain what writelines() does with ["Red","Blue"] and why a with block is useful.
Answer देखें
read() returns remaining text; readline() reads one line; readlines() returns remaining lines as a list. writelines(['Red','Blue']) writes RedBlue, adding no separators. A with block closes the file on exit, including when an exception occurs.
Part B – पिछले वर्षों के board questions (Unit 1)
CBSE Board Paper 2026 – 22 questions

Answer देखें
False – 74 is int and 74.0 is float.

Answer देखें
(A) The truth

Answer देखें
(C) 3>1 and 3>2 – it gives True. (B) gives 2, not True.

Answer देखें
(A) ('War and Peace ', 'by', ' Leo Tolstoy')

Answer देखें
mroPo

Answer देखें
(C) ('t', 'u', 'p', 'l', 'e', 'p') – t2 = t[2], is a one-element tuple ('p',).

Answer देखें
(B) A dictionary cannot have two elements with same key.

Answer देखें
(B) L.pop(6) – valid indexes are 0 to 5, so IndexError. (insert never raises IndexError.)

Answer देखें
(C) 3-None – f1 prints 3- and returns None, which is then printed.

Answer देखें
(B) rb

Answer देखें
False – try-except handles run-time errors (exceptions), not logical errors.

Answer देखें
(A) – both are true and the reason explains the assertion (TypeError: can only concatenate list to list).

Answer देखें
Positional parameters get values according to their position in the call and must be given. Default parameters have a value in the function header, which is used when no argument is passed; they must come after the positional (non-default) parameters.
def bill(price, qty=1): # price: positional, qty: default
return price * qty
Answer देखें
L1 = sorted(L) # (i) ch.isalnum() # (ii) True if ch is an alphabet or a digit

Answer देखें
(i) (a) 'RNo' in D1 OR (b) 12 in D1.values()
(ii) (a) D1.setdefault('RNo', 12) OR (b) D1.clear()

Answer देखें
Option (D) 5-1-2-4- can NOT be displayed. The loop runs 4 times (i = 0, 1, 2, 3).
In the 2nd iteration j = randrange(1,5) is 1 to 4, so a[j] is 2 to 5 – it can never be 1. Options A, B and C are possible.

Answer देखें
Corrections: iterate over s (not range(s)), test ch in 'aeiouAEIOU', c += 1, return c.
def CountVowels(s):
c = 0
for ch in s:
if ch in 'aeiouAEIOU':
c += 1
return c
Answer देखें
(a)
def count_digits():
count = 0
with open('Space.txt', 'r') as f:
for ch in f.read():
if ch.isdigit():
count += 1
return countOR (b)
def show_e_words():
with open('Space.txt', 'r') as f:
for word in f.read().split():
if word.count('e') >= 2:
print(word, end=' ')
Answer देखें
(a)
def push_fruit(FruitStack, Fruit):
if Fruit['Price'] < 100:
FruitStack.append(Fruit)
def pop_fruit(FruitStack):
if FruitStack == []:
print("UNDERFLOW")
return None
return FruitStack.pop()
def display(FruitStack):
if FruitStack == []:
print("EMPTY STACK")
else:
for rec in FruitStack[::-1]:
print(rec)OR (b)
stack = []
for i in range(10):
n = int(input("Enter an integer: "))
if 100 <= abs(n) <= 999 and n % 2 == 0:
stack.append(n)
while stack:
print(stack.pop(), end=' ')

Answer देखें
(a)
['4', '2', '-', 'd', 'l', 'o']
OR (b)
1-6-10-13-15-16-

Answer देखें
import csv
with open('States.csv', 'r', newline='') as fin, open('More.csv', 'a', newline='') as fout:
reader = csv.reader(fin)
writer = csv.writer(fout)
next(reader) # skip the header row
for rec in reader:
if int(rec[2]) > 10000000:
writer.writerow(rec)
Answer देखें
import pickle
def Append():
rid = int(input("Resource person ID: "))
name = input("Name: ")
exp = input("Expertise: ")
charges = int(input("Charges per hour: "))
with open('RESOURCES.DAT', 'ab') as f:
pickle.dump((rid, name, exp, charges), f)
def Update():
records = []
with open('RESOURCES.DAT', 'rb') as f:
while True:
try:
records.append(pickle.load(f))
except EOFError:
break
with open('RESOURCES.DAT', 'wb') as f:
for r in records: # tuples are immutable, so make a new tuple
pickle.dump((r[0], r[1], r[2], r[3] + 500), f)CBSE Board Paper 2023 – 23 questions

Answer देखें
True

Answer देखें
(b) return

Answer देखें
(b) Tup.insert(2,3) – a tuple is immutable and has no insert() method.

Answer देखें
(a) True

Answer देखें
(d) – partition(' ') splits at the first space: ('Amrit', ' ', 'Mahotsav @ 75'). The middle element is the separator (a space).

Answer देखें
(d) a

Answer देखें
(a) sort()

Answer देखें
(b) !=

Answer देखें
(d) Statements 2 and 4 – Stud[95] raises KeyError (95 is a value, not a key) and dict.pop() needs a key argument.

Answer देखें
(a) 0 (beginning of the file)

Answer देखें
(b) 8.0 – 3*5/3 = 5.0, 5%2 = 1, so 4 + 5.0 - 1 = 8.0

Answer देखें
(b) sum()

Answer देखें
(b) – both are true, but the reason (where import can be written) is not the explanation of why we must import.

Answer देखें
(a) – both are true and the reason explains LIFO: a new element always goes on top (after the last element), so it is the first to be removed.

Answer देखें
Corrections: L[0] instead of L(0), colon after if, indentation of max=a.
def max_num(L):
max = L[0]
for a in L:
if a > max:
max = a
return max
Answer देखें
(a) ['Rajat', 'Rajan', 'Ashish'] (b) 1


Answer देखें
(a)
['CSCS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'CHEMISTRYCHEMISTRY', 'MATHSMATHS']
OR (b) a = 30 is even, so x += a each time: 35+30 = 65 and 40+30 = 70.
65#70@


Answer देखें
(a)
def LongLines():
with open('LINES.TXT', 'r') as f:
for line in f:
if len(line.split()) >= 10:
print(line, end='')OR (b)
def count_Dwords():
count = 0
with open('Details.txt', 'r') as f:
for word in f.read().split():
if word[-1].isdigit():
count += 1
print("Number of words ending with a digit are", count)
Answer देखें
def EOReplace(L):
for i in range(len(L)):
if L[i] % 2 == 0:
L[i] = L[i] + 1
else:
L[i] = L[i] - 1
print(L)
Answer देखें
(a)
Hotel = []
def Push_Cust(customers):
for rec in customers:
if rec[1] == 'Delux':
Hotel.append(rec[0])
def Pop_Cust():
while Hotel:
print(Hotel.pop())
print("Underflow")OR (b)
stack = []
def Push(Vehicle):
for car, maker in Vehicle.items():
if maker.upper() == 'TATA':
stack.append(car)

Answer देखें
Possible output: (i) only.
first = randint(2,5) - 1 gives 1 to 4, sec = randint(3,6) - 2 gives 1 to 4, third = randint(1,4) gives 1 to 4, so every value is M[1]…M[4] = 10, 15, 20 or 25 (never 5 or 30), and sep='#' puts # only between values (no # at the end).
Alternative (a) – makenew("No@1"):
N1@3
(count 0 → 'N'; count 1 → '1'; count 2 → '@'.upper() = '@'; count 3 → '3')

Answer देखें
(a) A text file stores plain lines of text; a CSV file is a text file in which each line is a record and values are separated by commas (tabular data, opened with the csv module).
import csv
def COURIER_ADD():
with open('courier.csv', 'a', newline='') as f:
w = csv.writer(f)
cid = input("Courier ID: ")
s_name = input("Sender name: ")
source = input("Source: ")
destination = input("Destination: ")
w.writerow([cid, s_name, source, destination])
def COURIER_SEARCH():
dest = input("Destination to search: ")
with open('courier.csv', 'r', newline='') as f:
for rec in csv.reader(f):
if rec[3] == dest:
print(rec)
COURIER_ADD()
COURIER_SEARCH()OR (b) A file should be closed so that all data in the buffer is written to the disk, the resources are freed and the data is not lost or corrupted.
import csv
def Add_Book():
with open('Book.csv', 'a', newline='') as f:
w = csv.writer(f)
book_ID = input("Book ID: ")
B_name = input("Book name: ")
pub = input("Publisher: ")
w.writerow([book_ID, B_name, pub])
def Search_Book():
p = input("Publisher name: ")
count = 0
with open('Book.csv', 'r', newline='') as f:
for rec in csv.reader(f):
if rec[2] == p:
count += 1
print("Number of books published by", p, "=", count)
Add_Book()
Search_Book()
Answer देखें
(i) Statement 1: bin_file = open('Cust_file.dat', 'wb') (or 'ab' to keep old records)
(ii) Statement 2: if qty < 10:
(iii) Statement 3: pickle.dump(c_detail, bin_file) Statement 4: break
OR (iii) Statement 5: bin_file.close() Statement 6: write_bin()
CBSE Board Paper 2022 (Term-2, 35 marks) – 2 questions

Answer देखें
A stack follows LIFO (Last In, First Out) – the element added last is removed first. The list method pop() removes the last element.
stack = [10, 20, 30] stack.pop() # removes 30 print(stack) # [10, 20]


Answer देखें
def PushNV(N):
for word in N:
for ch in word:
if ch in 'aeiouAEIOU':
break
else: # no vowel found
NoVowel.append(word)
All = []
NoVowel = []
for i in range(5):
All.append(input("Enter a word: "))
PushNV(All)
while NoVowel:
print(NoVowel.pop(), end=' ')
print("EmptyStack")OR
def Push3_5(N):
for x in N:
if x % 3 == 0 or x % 5 == 0:
Only3_5.append(x)
NUM = []
Only3_5 = []
for i in range(5):
NUM.append(int(input("Enter an integer: ")))
Push3_5(NUM)
while Only3_5:
print(Only3_5.pop(), end=' ')
print("StackEmpty")आगे: Unit 2 – Networks: Evolution और Types।
