CBSE Class 12 Computer Science — Short Answer Questions
Short answer questions from all previous year papers.
20 questions found
2026(20 questions)
- 22
What is the difference between default parameters and positional parameters in Python ? Also give an example of a function header which uses both.
2 marks· B· Positional and Default Parameters - 23
To create a new list L1 containing the elements of list L arranged in ascending order, without modifying list L.
1 mark· B· Sorting a List — sorted() - 24
A statement to check whether the given character, ch is an alphabet or a number.
1 mark· B· Checking Alphanumeric Characters — isalnum() - 25
(a) Write a Python expression to check if the key, 'RNo' is present in D1. OR (b) Write a Python expression to check if any key in D1 has a value 12.
1 mark· B· Dictionary Membership Operators - 26
(a) Write a single statement using a BUILT_IN function to add the key : value pair 'RNo' : 12, if the key 'RNo' is not present in D1. However, if the key 'RNo' is present, the function should return its value. OR (b) Write a single statement to delete all the elements from D1.
1 mark· B· Dictionary Built-in Methods - 28
The function given below is written to accept a string s as a parameter and return the number of vowels appearing in the string. The code has certain errors. Observe the code carefully and rewrite it after removing all the logical and syntax errors. Underline all the corrections made. ```python def CountVowels(s): c=0 for ch in range(s): if 'aeiouAEIOU' in ch: c=+1 return(ch) ```
2 marks· B· Debugging Python Functions (String Traversal) - 29
(a) Write an SQL command to create the above table (W_Code should be the primary key). OR (b) Can U_Price be the primary key of the above table ? Justify your answer.
1 mark· B· SQL — CREATE TABLE and Primary Key - 30
(a) Assuming that the table W_STOCK is already created, write an SQL command to add an attribute E_Date (of DATE type) to the table. OR (b) Assuming that the table W_STOCK is already created, write an SQL command to remove the column B_Qty from the table.
1 mark· B· SQL — ALTER TABLE (ADD/DROP Column) - 31
(a) List one advantage and one disadvantage of Bus topology. OR (b) What is protocol in the context of computer networks? Which protocol is used to transmit hypertext across the web?
2 marks· B· Network Topologies and Protocols - 32
(a) Write a Python function that counts and returns the number of digits appearing in the text file "Space.txt". For example, if the file contains : ``` Space exploration has unlocked incredible advancements in technology and science. Since the first moon landing in 1969, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about 400 km, serves as a hub for research. With missions planned for 2030, humanity's cosmic journey continues! ``` Then the function should return 11. OR (b) Write a Python function that displays the words in which the lowercase letter 'e' appears at least twice in the text file 'Space.txt'. For example, if the file contains : ``` Space exploration has unlocked incredible advancements in technology and science. Since the first moon landing in 1969, space agencies have sent probes to Mars, Jupiter and beyond. The ISS, orbiting Earth at about 400 km, serves as a hub for research. With missions planned for 2030, humanity's cosmic journey continues! ``` Then the function should display : agencies serves incredible advancements science. research.
3 marks· C· Text File Handling in Python - 33
(a) A stack named FruitStack, implemented using list, contains records of some fruits. Each record is represented as a dictionary with keys `Name', `Origin', `Price', and `Expiry'. A sample record is given here : ```python {'Name':'Apple','Origin':'France','Price':120, 'Expiry':'12-08-2025'} ``` Write the following user-defined functions in Python to perform the specified operations on FruitStack : (i) push_fruit(FruitStack, Fruit): This function takes the stack FruitStack and a new record Fruit as arguments and pushes the record stored in Fruit onto FruitStack if the Price is less than 100. (ii) pop_fruit(FruitStack): This function pops the topmost record from the stack and returns it. If the stack is already empty, the function should display "UNDERFLOW". (iii) display(FruitStack): This function displays all the elements of the stack starting from the topmost element. If the stack is empty, the function should display `EMPTY STACK'. OR (b) Write a Python program to accept 10 integers from the user. If the entered number is a three-digit even integer, push it onto a stack. After all inputs are taken, pop all the three-digit even integers from the stack and display them. For example, if the user enters 12, 31, 320, 457, 6, 92, 924, 220, 1, 218, then the stack should contain : 320, 924, 220, 218 and the output of the program should be : 218 220 924 320
3 marks· C· Stack Implementation using List — PUSH, POP and Display Operations - 34
(a) Write the output of the following code : ```python def Exam2026(given) : new=[] for ch in given[1:-1]: if ch.isupper(): new.reverse() elif ch not in new: new.append(ch) elif ch in new: new.pop() print(new) Exam2026("Gold-24Medals") ``` OR (b) Write the output of the following code : ```python def Exam2026(given): new = 0 while given: if new % 2: new += given % 10 else: new += given % 5 print(new, end='-') given //= 10 Exam2026(123456) ```
3 marks· C· Tracing Function Output — String Slicing, List append/pop/reverse, Modulo Arithmetic - 35
(a) Based on the data given above, write the SQL queries for the following tasks : (i) To display Type and the maximum Price for each Type of milk. (ii) For each record, increase the Price by 0.5 where Type is 'F'. (iii) To display the total value of the stock (total of Qty x Price). (iv) To display the details of all records where Code starts with 'A'. OR (b) Considering the table STOCK as given above, write the output on execution of the following queries : (i) SELECT Volume, Qty, Price FROM STOCK WHERE Type IN ('F','D'); (ii) SELECT Code, Qty FROM STOCK WHERE Price BETWEEN 30 AND 50; (iii) SELECT DISTINCT Type FROM STOCK; (iv) SELECT Volume, count(*) FROM STOCK GROUP BY Volume;
4 marks· D· SQL Queries — GROUP BY, UPDATE, Aggregate SUM, and Pattern Matching (LIKE) - 36
A csv file "States.csv" contains some data about all the states of India. Each record of the file contains the following data : - Name of the State - Capital of the State - Population of the State - Official Language of the State For example, a sample record in the file is : ['Andhra Pradesh','Amaravati',52221000,'Telugu'] Write a Python program which reads the data from this file and appends all those records where population is more than 10000000 into another csv file 'More.csv'. Note : "States.csv" also contains the Header row. The Header row should NOT be copied to "More.csv".
4 marks· D· CSV File Handling — Reading, Filtering and Writing Records - 37
Number of records from LOANS table where Rate of Interest (RoI) is above 7.0.
1 mark· D· SQL COUNT() with WHERE Condition - 38
Names of the customers whose loan amount (L_Amt) is above 1000000.
1 mark· D· SQL Join between CUSTOMERS and LOANS using Common Key C_ID - 39
C_ID, C_Name and Terms of all those records where Loan Date (L_Date) is after 31st December, 2024.
1 mark· D· SQL Join with Date Comparison Condition - 40
(a) Details of all the loans in the descending order of RoI. OR (b) C_ID and average term for each C_ID from the LOANS table.
1 mark· D· SQL ORDER BY and GROUP BY with AVG() - 41
Peter has created a table named Account in MySQL database, SCHOOL, having following structure : - Stud_id - integer - Sname - string - Class - string - Fees - float Help him in writing a Python program to display records of those students whose fees is less than 5000. Note the following to establish connectivity between Python and MySQL : - Username - admin - Password - root - Host - localhost
4 marks· D· Python-MySQL Database Connectivity - 27
What possible output(s) from the given options will NOT be displayed when the following code is executed ? Also, mention, for how many iterations the for loop in the given code will run ? ```python import random a = [1,2,3,4,5,6] for i in range(4): j = random.randrange(i,5) print(a[j],end='-') print() ```
2 marks· B· Random Module and Loop Tracing