Class 12 CBSE Final Term Question Bank – Computer Science
Section A – Multiple Choice Questions (Each carries 1 mark)
- True or False: While defining a function in Python, the positional parameters in the function header must always be written after the default parameters.
Answer: False. In Python, positional parameters must always come before any default parameters in the function signature. - The SELECT statement when combined with the ________ clause returns records without repetition:
- (a) DISTINCT
- (b) DESCRIBE
- (c) UNIQUE
- (d) NULL
Answer: (a) DISTINCT. The DISTINCT clause is used to return only distinct (different) values. - What will be the output of the following statement:
print(16*5/4*2/5-8)- (a) -3.33
- (b) 6.0
- (c) 0.0
- (d) -13.33
Answer: (b) 6.0. The expression evaluates to 6.0 following order of operations. - What possible output from the given options is expected to be displayed when the following Python code is executed?
import random Signal = ['RED', 'YELLOW', 'GREEN'] for K in range(2, 0, -1): R = random.randrange(K) print(Signal[R], end='#')- (a) YELLOW # RED #
- (b) RED # GREEN #
- (c) GREEN # RED #
- (d) YELLOW # GREEN #
Answer: (b) RED # GREEN #. This code randomly selects indices from the Signal list and prints them. - In SQL, the aggregate function which will display the cardinality of the table is ________.
- (a) sum()
- (b) count()
- (c) avg()
- (d) sum(*)
Answer: (b) count(). The COUNT() function counts the number of rows or distinct values in a table. - Which protocol out of the following is used to send and receive emails over a computer network?
- (a) PPP
- (b) HTTP
- (c) FTP
- (d) SMTP
Answer: (d) SMTP. SMTP (Simple Mail Transfer Protocol) is used to send and receive emails. - Identify the invalid Python statement from the following:
- (a) d = dict()
- (b) e = {}
- (c) f = []
- (d) g = dict{}
Answer: (d) g = dict{}. It is invalid because Python uses parentheses to initialize a dictionary. - Consider the statements given below and choose the correct output from the given options:
myStr = "MISSISSIPPI" print(myStr[:4] + "#" + myStr[-5:])- (a) MISS#SIPPI
- (b) MISS#SIP
- (c) MISS#IPPIS
- (d) MISSI#IPPIS
Answer: (a) MISS#SIPPI. The slice [:4] gives “MISS” and [-5:] gives “SIPPI”. - Identify the statement from the following which will raise an error:
- (a) print(“A”*3)
- (b) print(5*3)
- (c) print(“15” + 3)
- (d) print(“15” + “13”)
Answer: (c) print(“15” + 3). This will raise a TypeError since strings and integers cannot be concatenated without explicit conversion. - Select the correct output of the following code:
event = "G20 Presidency@2023" L = event.split(' ') print(L[::-2])- (a) [‘G20’]
- (b) [‘Presidency@2023’]
- (c) [‘G20’]
- (d) ‘Presidency@2023’
Answer: (a) [‘G20’]. L[::-2] reverses the list and skips every other element. - Which of the following options is the correct unit of measurement for network bandwidth?
- (a) KB
- (b) Bit
- (c) Hz
- (d) Km
Answer: (b) Bit. Network bandwidth is measured in bits per second (bps). - Observe the given Python code carefully:
a = 20 def convert(a): b = 20 a = a + b convert(10) print(a)- (a) 10
- (b) 20
- (c) 30
- (d) Error
Answer: (b) 20. The value ofain the global scope is unchanged. - True or False: While handling exceptions in Python, the name of the exception has to be compulsorily added with the except clause.
Answer: False. In Python, a generic except block without specifying the exception type can be used. - Which of the following is not a DDL command in SQL?
- (a) DROP
- (b) CREATE
- (c) UPDATE
- (d) ALTER
Answer: (c) UPDATE. UPDATE is a DML (Data Manipulation Language) command, not a DDL command. - Fill in the blank: _________ is a set of rules that needs to be followed by the communicating parties in order to have a successful and reliable data communication over a network.
Answer: Protocol. A protocol is a set of rules for communication over a network. - Consider the following Python statement:
F = open('CONTENT.TXT')Which of the following is an invalid statement in Python?
- (a) F.seek(1, 0)
- (b) F.seek(0, 1)
- (c) F.seek(0, -1)
- (d) F.seek(0, 2)
Answer: (c) F.seek(0, -1). Negative values for the second argument are invalid unless the file is opened in binary mode. - Assertion (A): A CSV file is a human-readable text file where each line has a number of fields, separated by a comma or some other delimiter.
Reason (R): The writerow() method is used to write a single row in a CSV file.- (a) Both (A) and (R) are true, and (R) is the correct explanation for (A).
- (b) Both (A) and (R) are true, but (R) is not the correct explanation for (A).
- (c) (A) is true, but (R) is false.
- (d) (A) is false, but (R) is true.
Answer: (b) Both (A) and (R) are true, but (R) is not the correct explanation for (A). - Assertion (A): The expression
"HELLO".sort()in Python will give an error.
Reason (R): Thesort()method does not exist for strings in Python.- (a) Both (A) and (R) are true, and (R) is the correct explanation for (A).
- (b) Both (A) and (R) are true, but (R) is not the correct explanation for (A).
- (c) (A) is true, but (R) is false.
- (d) (A) is false, but (R) is true.
Answer: (a) Both (A) and (R) are true, and (R) is the correct explanation for (A).
Section B – Very Short Answer Questions (Each carries 2 marks)
- Rewrite the following code to correct syntactical errors:
def max_num(L): max = L(0) for a in L: if a > max: max = a return maxAnswer: The correct code is:def max_num(L): max = L[0] for a in L: if a > max: max = a return max - Differentiate between wired and wireless transmission.
Answer: Wired transmission uses cables like fiber optics or copper wires, whereas wireless transmission uses electromagnetic waves to transmit data. - Differentiate between URL and domain name with the help of an example.
Answer: A domain name is part of the URL. For example, in https://www.example.com, ‘example.com’ is the domain name, while the full URL specifies the exact page and protocol. - Consider the Python list:
Listofnames = ["Aman", "Ankit", "Ashish", "Rajan", "Rajat"]. Write the output of:print(Listofnames[-1::-4:-1])Answer: ‘Rajat’ - Explain the concept of “Alternate Key” in a Relational Database Management System with an example.
Answer: An Alternate Key is a candidate key that is not the primary key. For example, in a table where ‘ID’ is the primary key, ‘Email’ can be an alternate key. - Write the full forms of:
- (i) HTML
- (ii) TCP
Answer: (i) HyperText Markup Language, (ii) Transmission Control Protocol - Write the output of the following code:
subject = ['CS', 'HINDI', 'PHYSICS', 'CHEMISTRY', 'MATHS'] short_sub(subject, 5) print(subject)Answer: The output depends on the logic inside theshort_subfunction, which is not provided.
Section C – Short Answer Questions (Each carries 3 marks)
- Differentiate between CHAR and VARCHAR data types in SQL with an example.
Answer: CHAR stores fixed-length strings, while VARCHAR stores variable-length strings. Example: CHAR(5) stores exactly 5 characters, while VARCHAR(5) can store up to 5 characters. - Consider the following tables – LOAN and BORROWER. How many rows and columns will be there in the natural join of these two tables?
Answer: There will be 2 rows and 3 columns in the natural join of LOAN and BORROWER tables. - Write a Python function
LongLines()that reads the contents of a text file and displays lines with at least 10 words.
Answer:def LongLines(): with open("LINES.TXT", "r") as file: for line in file: if len(line.split()) >= 10: print(line) - Write the SQL queries for:
- SELECT MIN(PRICE), MAX(PRICE) FROM COMPUTER;
- SELECT COMPANY, COUNT(*) FROM COMPUTER GROUP BY COMPANY HAVING COUNT(COMPANY) > 1;
Answer: The two SQL queries return the minimum and maximum price from the COMPUTER table, and the count of products per company having more than 1 product, respectively. - Write a function
EOReplace()in Python which accepts a list of numbers and increments all even numbers by 1 and decrements all odd numbers by 1.
Answer:def EOReplace(L): for i in range(len(L)): if L[i] % 2 == 0: L[i] += 1 else: L[i] -= 1
Section D – Long Answer Questions (Each carries 5 marks)
- Write a function
Push_Cust()to push customer names staying in ‘Delux’ room type in a stack, andPop_Cust()to pop and display customer names.
Answer: Implement the stack withPush_Cust()to add ‘Delux’ room customers andPop_Cust()to remove and display customers. - An IT-based firm is planning to set up a network for its branches. Suggest an ideal layout to connect the branches and justify your choice.
Answer: A star topology can be ideal to connect the branches with the main hub as it is easy to maintain and troubleshoot. - Write a program in Python that defines and calls the following user-defined functions:
COURIER_ADD(): Takes values from the user and adds them to a CSV filecourier.csv.COURIER_SEARCH(): Takes the destination as input and displays all the courier records going to that destination.
Answer:import csv def COURIER_ADD(): with open("courier.csv", "a", newline="") as file: writer = csv.writer(file) cid = input("Enter Courier ID: ") s_name = input("Enter Sender Name: ") source = input("Enter Source: ") destination = input("Enter Destination: ") writer.writerow([cid, s_name, source, destination]) def COURIER_SEARCH(destination): with open("courier.csv", "r") as file: reader = csv.reader(file) for row in reader: if row[3] == destination: print(row)
Section E – Internal Choice Questions (Each carries 4 marks)
- The school has asked their estate manager Mr. Rahul to maintain the data of all the labs in a table LAB. Based on the data, identify the columns which can be considered as Candidate keys and write the degree and cardinality of the table.
Answer: Candidate keys: LABNO. Degree: 4. Cardinality: 5. - Write a user-defined function
write_bin()to create a binary file calledCust_file.datand store customer information (customer number, name, quantity, price, and amount).
Answer:import pickle def write_bin(): with open("Cust_file.dat", "wb") as file: c_no = int(input("Enter Customer Number: ")) c_name = input("Enter Customer Name: ") qty = int(input("Enter Quantity: ")) price = float(input("Enter Price: ")) amt = qty * price pickle.dump([c_no, c_name, qty, price, amt], file)