Class 12 Computer Science
CBQ Practice
Competency Based Questions · 4 chapters · 8 CBQ sets
Python — Functions, Recursion and Modules
2 setsRead the passage
What is the base case in Arjun's recursive factorial function?
1MWhat will factorial(4) return when Arjun's function is called?
1MHow does Arjun call the factorial function from 'mathutils.py' in his main program?
1MExplain the difference between a local variable and a global variable in Python with an example.
1MEvery recursive function must have a base case.
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.
File Handling in Python
2 setsRead the passage
Which file mode should be used to read 'results.txt' and add new records to 'toppers.txt' without losing existing data?
1MWhat is the advantage of using 'with open(filename) as f:' in Python?
1MWhich method reads the entire file content as a single string?
1MWrite a Python code snippet to read 'results.txt' and print only names of students scoring above 90.
1MThe 'r+' mode in Python file handling allows both reading and writing without erasing the existing content.
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.
Data Structures — Stack and Queue
2 setsRead the passage
Which data structure principle is used in the browser history model?
1MAfter the two Back operations, what is the current page (top of stack)?
1MWhich Python operation correctly implements POP on a list-based stack?
1MHow would a Queue (FIFO) be used differently from a Stack? Give a real-world computer science example for each.
1MA queue follows the FIFO (First In, First Out) principle.
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.
Computer Networks and Database Concepts
2 setsRead the passage
Which SQL command is used to add the 'Ward' column to the PATIENT table?
1MTo display patient names with their doctor's name, the query requires:
1MThe correct SQL to find average age grouped by blood group is:
1MExplain the difference between Primary Key and Foreign Key with examples from the hospital database.
1MThe WHERE clause and HAVING clause both filter records in an SQL query.
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.