CBQ PracticeClass 12 Computer Science
💻

Class 12 Computer Science
CBQ Practice

Competency Based Questions · 4 chapters · 8 CBQ sets

Question types:Case StudySource BasedAssertion–Reason
💡Attempt each question before clicking Show Answers — then compare.
Filter:
Ch 1

Python — Functions, Recursion and Modules

2 sets
CBQ 1Case StudyRecursive Factorial Calculation4 marks

Read the passage

Arjun is writing a Python program to calculate the factorial of a number using both an iterative and a recursive approach. The recursive function calls itself with a smaller input each time until it reaches the base case. He writes: def factorial(n): if n == 0 or n == 1: return 1; return n * factorial(n-1). He also writes a module 'mathutils.py' that contains this function. In his main program, he imports the module and calls mathutils.factorial(5). He notices that Python maintains a 'call stack' to track recursive function calls, and excessive recursion can cause a 'RecursionError'.
1

What is the base case in Arjun's recursive factorial function?

1M
(A)return n * factorial(n-1)
(B)if n == 0 or n == 1: return 1
(C)def factorial(n):
(D)mathutils.factorial(5)
2

What will factorial(4) return when Arjun's function is called?

1M
(A)12
(B)24
(C)16
(D)4
3

How does Arjun call the factorial function from 'mathutils.py' in his main program?

1M
(A)import mathutils; factorial(5)
(B)from mathutils import *; factorial(5)
(C)import mathutils; mathutils.factorial(5)
(D)include mathutils; mathutils.factorial(5)
4

Explain the difference between a local variable and a global variable in Python with an example.

1M
CBQ 2Assertion–Reason1 mark
A
Assertion

Every recursive function must have a base case.

R
Reason

Without a base case, a recursive function would call itself infinitely, leading to a stack overflow error (RecursionError in Python) as the call stack fills up with unresolved function calls.

(A) Both A and R are true and R is the correct explanation of A
(B) Both A and R are true but R is not the correct explanation of A
(C) A is true but R is false
(D) A is false but R is true
Ch 2

File Handling in Python

2 sets
CBQ 1Case StudyStudent Results File Processing4 marks

Read the passage

A school's Python program reads student marks from 'results.txt'. Each line has the format: RollNo,Name,Marks. The program reads all lines, identifies students scoring above 90, and writes their details to 'toppers.txt'. The developer first opens results.txt in 'r' mode and toppers.txt in 'w' mode. Later, she realises that running the program twice overwrites toppers.txt each time. She switches toppers.txt to 'a' (append) mode to preserve records. She also uses a with statement to ensure files are closed automatically.
1

Which file mode should be used to read 'results.txt' and add new records to 'toppers.txt' without losing existing data?

1M
(A)'r' for results.txt and 'w' for toppers.txt
(B)'r' for results.txt and 'a' for toppers.txt
(C)'w' for results.txt and 'r' for toppers.txt
(D)'a' for results.txt and 'r+' for toppers.txt
2

What is the advantage of using 'with open(filename) as f:' in Python?

1M
(A)It automatically reads all lines from the file
(B)It ensures the file is automatically closed when the block exits, even if an exception occurs
(C)It allows writing to a read-only file
(D)It increases file reading speed
3

Which method reads the entire file content as a single string?

1M
(A)f.readline()
(B)f.readlines()
(C)f.read()
(D)f.readall()
4

Write a Python code snippet to read 'results.txt' and print only names of students scoring above 90.

1M
CBQ 2Assertion–Reason1 mark
A
Assertion

The 'r+' mode in Python file handling allows both reading and writing without erasing the existing content.

R
Reason

The 'r+' mode opens an existing file for both reading and writing; the file pointer is placed at the beginning, and writing starts from there without truncating the file first.

(A) Both A and R are true and R is the correct explanation of A
(B) Both A and R are true but R is not the correct explanation of A
(C) A is true but R is false
(D) A is false but R is true
Ch 3

Data Structures — Stack and Queue

2 sets
CBQ 1Case StudyBrowser History as a Stack4 marks

Read the passage

A browser maintains visited page history using a Python list as a stack. Pages visited: Google → Flipkart → Amazon → YouTube. PUSH adds a page to the top; POP removes the most recent page (Back button). After visiting all four pages, the user clicks Back twice. The stack after all pushes: ['Google', 'Flipkart', 'Amazon', 'YouTube'] (YouTube at top = index -1). After first Back: POP removes YouTube → ['Google', 'Flipkart', 'Amazon']. After second Back: POP removes Amazon → ['Google', 'Flipkart']. Current page = top of stack = 'Flipkart'.
1

Which data structure principle is used in the browser history model?

1M
(A)FIFO (First In, First Out)
(B)LIFO (Last In, First Out)
(C)Random Access
(D)Priority Queue
2

After the two Back operations, what is the current page (top of stack)?

1M
(A)Google
(B)Amazon
(C)Flipkart
(D)YouTube
3

Which Python operation correctly implements POP on a list-based stack?

1M
(A)stack.remove()
(B)stack.pop(0)
(C)stack.pop()
(D)stack.delete()
4

How would a Queue (FIFO) be used differently from a Stack? Give a real-world computer science example for each.

1M
CBQ 2Assertion–Reason1 mark
A
Assertion

A queue follows the FIFO (First In, First Out) principle.

R
Reason

In a queue, elements are added at the rear end (ENQUEUE) and removed from the front end (DEQUEUE), ensuring that the first element inserted is the first one to be removed.

(A) Both A and R are true and R is the correct explanation of A
(B) Both A and R are true but R is not the correct explanation of A
(C) A is true but R is false
(D) A is false but R is true
Ch 4

Computer Networks and Database Concepts

2 sets
CBQ 1Case StudyHospital Database Design4 marks

Read the passage

City Hospital has a relational database with two tables: PATIENT (PID, PName, Age, BloodGroup, DID) and DOCTOR (DID, DName, Specialisation, Fees). PID is the primary key of PATIENT; DID is the primary key of DOCTOR. The DID in PATIENT is a foreign key referencing DOCTOR.DID. A nurse needs to: (i) list all patients with blood group 'O+'; (ii) find average age by blood group; (iii) display patient names with their doctor's name. The IT manager also needs to add a column 'Ward' to the PATIENT table.
1

Which SQL command is used to add the 'Ward' column to the PATIENT table?

1M
(A)UPDATE PATIENT ADD Ward VARCHAR(20);
(B)ALTER TABLE PATIENT ADD Ward VARCHAR(20);
(C)MODIFY TABLE PATIENT ADD COLUMN Ward VARCHAR(20);
(D)INSERT INTO PATIENT (Ward) VALUES ('ICU');
2

To display patient names with their doctor's name, the query requires:

1M
(A)A subquery on PATIENT only
(B)An INNER JOIN between PATIENT and DOCTOR on DID
(C)A UNION of PATIENT and DOCTOR tables
(D)GROUP BY on PATIENT table
3

The correct SQL to find average age grouped by blood group is:

1M
(A)SELECT BloodGroup, AVG(Age) FROM PATIENT;
(B)SELECT BloodGroup, AVG(Age) FROM PATIENT GROUP BY BloodGroup;
(C)SELECT AVG(Age) FROM PATIENT WHERE BloodGroup = 'O+';
(D)SELECT BloodGroup, MEAN(Age) FROM PATIENT GROUP BY BloodGroup;
4

Explain the difference between Primary Key and Foreign Key with examples from the hospital database.

1M
CBQ 2Assertion–Reason1 mark
A
Assertion

The WHERE clause and HAVING clause both filter records in an SQL query.

R
Reason

WHERE filters individual rows before grouping (before GROUP BY is applied), while HAVING filters groups after aggregation (after GROUP BY is applied) — they operate at different stages of query execution.

(A) Both A and R are true and R is the correct explanation of A
(B) Both A and R are true but R is not the correct explanation of A
(C) A is true but R is false
(D) A is false but R is true
CBSE Class 10 · Phase 2 Board Exam · May 2026

Appearing for the May Phase 2 Board Exam? Practice with AI-ranked questions.

Built for the May 2026 Phase 2 Board Exam — board paper analysis + unlimited practice for Maths, Science, English & SST.

Improvement · May 2026

Mathematics

299
599
Access to all CBSE Class 10 Maths chapters
Know which questions are most likely to come in your exam
Study by Chapter or by Section (A–E)
Step-by-step solutions for every question
AI-revealed high probability questions
Pattern recognition across past CBSE papers
Expected Paper for Phase 2 Board Exam (unlocks 3 weeks before)
Improvement · May 2026

Science

299
599
Access to all CBSE Class 10 Science chapters
Know which questions are most likely to come in your exam
Study by Chapter or by Section (A–E)
Step-by-step solutions for every question
AI-revealed high probability questions
Pattern recognition across past CBSE papers
Expected Paper for Phase 2 Board Exam (unlocks 3 weeks before)
★ Best Value · May 2026

Maths and Science

Maths · Science

+ SST & English Free
499
998
Both subjects — Maths & Science
Know which questions are most likely to come in your exam
Study by Chapter or by Section (A–E)
Step-by-step solutions for every question
AI-revealed high probability questions
Pattern recognition across past CBSE papers
Expected Paper for Phase 2 Board Exam (unlocks 3 weeks before)
Instant access
Valid till board exam
Secure payment — Razorpay
Phase 2 Board Exam · May 2026

CBSE Class 10 — Board Pattern