Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🐍 Unit 1 – Programming 2 (40 marks)  ·  Lesson 10

📝 Unit 1 Board Questions + Practice

इस page पर क्या है

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 के साथ)

U1-011 markज़रूरी

State the types of 42 and 42.0. Are the types identical?

Answer देखें

int and float; the types differ.

U1-021 markज़रूरी

Evaluate: 7 + 12 // 5 * 2 - 9 % 4

Answer देखें

10.

U1-031 markज़रूरी

Predict both outputs.

Python
print('sCHOOL cODE'.capitalize())
print('book:file:read'.partition(':'))
Answer देखें

School code; ('book', ':', 'file:read').

U1-041 markज़रूरी

Predict the output.

Python
print('COMPUTER'[-1:1:-2])
Answer देखें

RTP.

U1-051 markज़रूरी

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.

U1-061 markज़रूरी

Predict the result.

Python
d = {'A':10, 'B':20, 'A':30}
print(len(d), d['A'])
Answer देखें

2 30.

U1-071 markज़रूरी

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).

U1-081 markज़रूरी

Name the file mode that appends binary records without truncating existing contents.

Answer देखें

ab.

U1-092 marksज़रूरी

Predict the exact output, including the printed return value.

Python
def add(a, b=4):
    print(a+b, end='#')
x = add(3)
print(x)
Answer देखें

7#None.

U1-102 marksज़रूरी

Predict the two lines of output.

Python
x = 10
def f():
    x = 3
    print(x)
f()
print(x)
Answer देखें

3 then 10. Assignment inside f creates a local x.

U1-112 marksज़रूरी

Predict the final output and explain why the list and integer behave differently.

Python
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.

U1-122 marksज़रूरी

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:

Python
def total(price, qty=2):
    return price * qty
print(total(100))
print(total(100,5))
U1-132 marksज़रूरी

For d={"R1":80}, use a dictionary method to add R2:75 only if absent, then retrieve R3 with fallback value 0.

Answer देखें
Python
d.setdefault('R2',75)
d.get('R3',0)
U1-142 marksज़रूरी

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 देखें
Python
new=sorted(L)
L.extend([10,12])
U1-152 marksज़रूरी

Give all possible values of x and the number of loop iterations. Can the code print 40?

Python
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.

U1-162 marksज़रूरी

Correct the function so that it returns the number of uppercase characters.

Python
def count_upper(s)
    n = 0
    for ch in range(s):
        if ch.isupper:
            n =+ 1
    return ch
Answer देखें

Corrected function:

Python
def count_upper(s):
    n = 0
    for ch in s:
        if ch.isupper():
            n += 1
    return n
U1-172 marks

Predict the output and name the handled exception.

Python
try:
    print(12//0)
except ZeroDivisionError:
    print('Invalid division')
finally:
    print('Finished')
Answer देखें

Invalid division, then Finished. ZeroDivisionError is handled.

U1-182 marks

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.

U1-193 marksज़रूरी

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].

Python
def adjust(L):
    for i in range(len(L)):
        if L[i] % 2 == 0:
            L[i] += 2
        else:
            L[i] -= 2
U1-203 marks

Define 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}

Python
def frequency(text):
    counts = {}
    for ch in text.lower():
        if ch != ' ':
            counts[ch] = counts.get(ch,0) + 1
    return counts
U1-213 marksज़रूरी

Define 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:

Python
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 count
U1-223 marksज़रूरी

Define show_lines(filename) to display only lines with at least 6 whitespace-separated words, without inserting extra blank lines.

Answer देखें

One valid solution:

Python
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='')
U1-233 marksज़रूरी

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:

Python
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)
U1-243 marks

Assume data.bin contains exactly the ASCII bytes ABCDEFG. Predict all four outputs.

Python
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.

U1-253 marks

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.

U1-263 marksज़रूरी

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:

Python
def push_merit(records,stack):
    for name,marks in records:
        if marks >= 85:
            stack.append(name)
U1-273 marksज़रूरी

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:

Python
def pop_one(stack):
    if not stack:
        print('UNDERFLOW')
        return None
    return stack.pop()

def display(stack):
    for item in stack[::-1]:
        print(item)
U1-284 marksज़रूरी

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:

Python
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]])
U1-294 marksज़रूरी

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:

Python
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)
U1-304 marksज़रूरी

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:

Python
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'):
        pass
U1-314 marksज़रूरी

A 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:

Python
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 rec
U1-325 marksज़रूरी

For 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:

Python
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 found
U1-334 marksज़रूरी

Define 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:

Python
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 count
U1-343 marksज़रूरी

Trace the function and write its output.

Python
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.

U1-353 marks

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:

Python
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')
U1-363 marks

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

Board 2026 · Q1
CBSE 2026 Class 12 CS board question Q1, Unit 1 Computational Thinking and Programming – 2
Answer देखें

False – 74 is int and 74.0 is float.

Board 2026 · Q2
CBSE 2026 Class 12 CS board question Q2, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(A) The truth

Board 2026 · Q3
CBSE 2026 Class 12 CS board question Q3, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(C) 3>1 and 3>2 – it gives True. (B) gives 2, not True.

Board 2026 · Q4
CBSE 2026 Class 12 CS board question Q4, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(A) ('War and Peace ', 'by', ' Leo Tolstoy')

Board 2026 · Q5
CBSE 2026 Class 12 CS board question Q5, Unit 1 Computational Thinking and Programming – 2
Answer देखें

mroPo

Board 2026 · Q6
CBSE 2026 Class 12 CS board question Q6, Unit 1 Computational Thinking and Programming – 2
Answer देखें

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

Board 2026 · Q7
CBSE 2026 Class 12 CS board question Q7, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(B) A dictionary cannot have two elements with same key.

Board 2026 · Q8
CBSE 2026 Class 12 CS board question Q8, Unit 1 Computational Thinking and Programming – 2
Answer देखें

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

Board 2026 · Q9
CBSE 2026 Class 12 CS board question Q9, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(C) 3-None – f1 prints 3- and returns None, which is then printed.

Board 2026 · Q10
CBSE 2026 Class 12 CS board question Q10, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(B) rb

Board 2026 · Q11
CBSE 2026 Class 12 CS board question Q11, Unit 1 Computational Thinking and Programming – 2
Answer देखें

False – try-except handles run-time errors (exceptions), not logical errors.

Board 2026 · Q20
CBSE 2026 Class 12 CS board question Q20, Unit 1 Computational Thinking and Programming – 2
Answer देखें

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

Board 2026 · Q22
CBSE 2026 Class 12 CS board question Q22, Unit 1 Computational Thinking and Programming – 2
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.

Python
def bill(price, qty=1):     # price: positional, qty: default
    return price * qty
Board 2026 · Q23
CBSE 2026 Class 12 CS board question Q23, Unit 1 Computational Thinking and Programming – 2
Answer देखें
Python
L1 = sorted(L)       # (i)
ch.isalnum()         # (ii) True if ch is an alphabet or a digit
Board 2026 · Q24
CBSE 2026 Class 12 CS board question Q24, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(i) (a) 'RNo' in D1 OR (b) 12 in D1.values()

(ii) (a) D1.setdefault('RNo', 12) OR (b) D1.clear()

Board 2026 · Q25
CBSE 2026 Class 12 CS board question Q25, Unit 1 Computational Thinking and Programming – 2
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.

Board 2026 · Q26
CBSE 2026 Class 12 CS board question Q26, Unit 1 Computational Thinking and Programming – 2
Answer देखें

Corrections: iterate over s (not range(s)), test ch in 'aeiouAEIOU', c += 1, return c.

Python
def CountVowels(s):
    c = 0
    for ch in s:
        if ch in 'aeiouAEIOU':
            c += 1
    return c
Board 2026 · Q29
CBSE 2026 Class 12 CS board question Q29, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(a)

Python
def count_digits():
    count = 0
    with open('Space.txt', 'r') as f:
        for ch in f.read():
            if ch.isdigit():
                count += 1
    return count

OR (b)

Python
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=' ')
Board 2026 · Q30
CBSE 2026 Class 12 CS board question Q30, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(a)

Python
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)

Python
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=' ')
Board 2026 · Q31
CBSE 2026 Class 12 CS board question Q31, Unit 1 Computational Thinking and Programming – 2 (part 1)CBSE 2026 Class 12 CS board question Q31, Unit 1 Computational Thinking and Programming – 2 (part 2)
Answer देखें

(a)

Output
['4', '2', '-', 'd', 'l', 'o']

OR (b)

Output
1-6-10-13-15-16-
Board 2026 · Q33
CBSE 2026 Class 12 CS board question Q33, Unit 1 Computational Thinking and Programming – 2
Answer देखें
Python
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)
Board 2026 · Q36
CBSE 2026 Class 12 CS board question Q36, Unit 1 Computational Thinking and Programming – 2
Answer देखें
Python
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

Board 2023 · Q1
CBSE 2023 Class 12 CS board question Q1, Unit 1 Computational Thinking and Programming – 2
Answer देखें

True

Board 2023 · Q2
CBSE 2023 Class 12 CS board question Q2, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(b) return

Board 2023 · Q3
CBSE 2023 Class 12 CS board question Q3, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(b) Tup.insert(2,3) – a tuple is immutable and has no insert() method.

Board 2023 · Q4
CBSE 2023 Class 12 CS board question Q4, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(a) True

Board 2023 · Q5
CBSE 2023 Class 12 CS board question Q5, Unit 1 Computational Thinking and Programming – 2
Answer देखें

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

Board 2023 · Q6
CBSE 2023 Class 12 CS board question Q6, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(d) a

Board 2023 · Q7
CBSE 2023 Class 12 CS board question Q7, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(a) sort()

Board 2023 · Q8
CBSE 2023 Class 12 CS board question Q8, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(b) !=

Board 2023 · Q9
CBSE 2023 Class 12 CS board question Q9, Unit 1 Computational Thinking and Programming – 2
Answer देखें

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

Board 2023 · Q11
CBSE 2023 Class 12 CS board question Q11, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(a) 0 (beginning of the file)

Board 2023 · Q14
CBSE 2023 Class 12 CS board question Q14, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(b) 8.0 – 3*5/3 = 5.0, 5%2 = 1, so 4 + 5.0 - 1 = 8.0

Board 2023 · Q15
CBSE 2023 Class 12 CS board question Q15, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(b) sum()

Board 2023 · Q17
CBSE 2023 Class 12 CS board question Q17, Unit 1 Computational Thinking and Programming – 2
Answer देखें

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

Board 2023 · Q18
CBSE 2023 Class 12 CS board question Q18, Unit 1 Computational Thinking and Programming – 2
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.

Board 2023 · Q19
CBSE 2023 Class 12 CS board question Q19, Unit 1 Computational Thinking and Programming – 2
Answer देखें

Corrections: L[0] instead of L(0), colon after if, indentation of max=a.

Python
def max_num(L):
    max = L[0]
    for a in L:
        if a > max:
            max = a
    return max
Board 2023 · Q21
CBSE 2023 Class 12 CS board question Q21, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(a) ['Rajat', 'Rajan', 'Ashish'] (b) 1

Board 2023 · Q24
CBSE 2023 Class 12 CS board question Q24, Unit 1 Computational Thinking and Programming – 2 (part 1)CBSE 2023 Class 12 CS board question Q24, Unit 1 Computational Thinking and Programming – 2 (part 2)
Answer देखें

(a)

Output
['CSCS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'CHEMISTRYCHEMISTRY', 'MATHSMATHS']

OR (b) a = 30 is even, so x += a each time: 35+30 = 65 and 40+30 = 70.

Output
65#70@
Board 2023 · Q27
CBSE 2023 Class 12 CS board question Q27, Unit 1 Computational Thinking and Programming – 2 (part 1)CBSE 2023 Class 12 CS board question Q27, Unit 1 Computational Thinking and Programming – 2 (part 2)
Answer देखें

(a)

Python
def LongLines():
    with open('LINES.TXT', 'r') as f:
        for line in f:
            if len(line.split()) >= 10:
                print(line, end='')

OR (b)

Python
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)
Board 2023 · Q29
CBSE 2023 Class 12 CS board question Q29, Unit 1 Computational Thinking and Programming – 2
Answer देखें
Python
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)
Board 2023 · Q30
CBSE 2023 Class 12 CS board question Q30, Unit 1 Computational Thinking and Programming – 2
Answer देखें

(a)

Python
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)

Python
stack = []

def Push(Vehicle):
    for car, maker in Vehicle.items():
        if maker.upper() == 'TATA':
            stack.append(car)
Board 2023 · Q32(a)
CBSE 2023 Class 12 CS board question Q32(a), Unit 1 Computational Thinking and Programming – 2 (part 1)CBSE 2023 Class 12 CS board question Q32(a), Unit 1 Computational Thinking and Programming – 2 (part 2)
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"):

Output
N1@3

(count 0 → 'N'; count 1 → '1'; count 2 → '@'.upper() = '@'; count 3 → '3')

Board 2023 · Q33
CBSE 2023 Class 12 CS board question Q33, Unit 1 Computational Thinking and Programming – 2
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).

Python
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.

Python
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()
Board 2023 · Q35
CBSE 2023 Class 12 CS board question Q35, Unit 1 Computational Thinking and Programming – 2
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

Board 2022 · Q1
CBSE 2022 Class 12 CS board question Q1, Unit 1 Computational Thinking and Programming – 2
Answer देखें

A stack follows LIFO (Last In, First Out) – the element added last is removed first. The list method pop() removes the last element.

Python
stack = [10, 20, 30]
stack.pop()        # removes 30
print(stack)       # [10, 20]
Board 2022 · Q8
CBSE 2022 Class 12 CS board question Q8, Unit 1 Computational Thinking and Programming – 2 (part 1)CBSE 2022 Class 12 CS board question Q8, Unit 1 Computational Thinking and Programming – 2 (part 2)
Answer देखें
Python
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

Python
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।

← Class 12 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicNetworks: Evolution और Types आपकी प्रगति: 10 / 24 (42%) · Lesson 11 / 24 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें