CBSE Class 12 – Computer Science Question Paper 2023
SECTION-A
1. State True or False.
“Identifiers are names used to identify a variable, function in a program.”
Answer:
True
2. Which of the following is a valid keyword in Python?
(a) false
(b) return
(c) non_local
(d) none
Answer:
(c) non_local
3. Given the following Tuple:
Tup = (10, 20, 30, 50)
Which of the following statements will result in an error?
(a) print(Tup[0:1])
(b) Tup.insert(2, 3)
(c) print(Tup[1:2])
(d) print(len(Tup))
Answer:
(b) Tup.insert(2, 3)
Tuples are immutable in Python, so the insert
method cannot be used on them.
4. Consider the given expression:
5<10 and 12>7 or not 7>4
Which of the following will be the correct output, if the given expression is evaluated?
(a) True
(b) False
(c) NONE
(d) NULL
Answer:
(a) True
Explanation:
The expression evaluates as follows:
5 < 10 (True), 12 > 7 (True), 7 > 4 (True).
So, the expression becomes True and True or not True, which evaluates to True.
5. Select the correct output of the code:
S = “Amrit Mahotsav @ 75”
A = S.partition(“@”)
print(A)
Answer:
(a) (‘Amrit Mahotsav’, ‘@’, ’75’)
Explanation:
The partition
method splits the string into a tuple with three parts: the part before the separator (@
), the separator itself, and the part after the separator.
6. Which of the following mode keeps the file offset position at the end of the file?
(a) r+
(b) x
(c) w
(d) a
Answer:
(d) a
7. Fill in the blank.
… function is used to arrange the elements of a list in ascending order.
(a) arrange()
(b) sort()
(c) ascending()
(d) asort()
Answer:
(b) sort()
8. Which of the following operators will return either True or False?
(a) +=
(b) !=
(c) –
(d) =
Answer:
(b) !=
9. Which of the following statement(s) would give an error after executing the following code?
Answer:
(d) Statements 2 and 4
Explanation:
- Statement 2: You cannot access a dictionary by value (
Stud[95]
is incorrect). - Statement 4: The
pop()
method requires a key as an argument, not called without one.
10. Fill in the blank.
… is a number of tuples in a relation.
(a) Attribute
(b) Degree
(c) Domain
(d) Cardinality
Answer:
(d) Cardinality
11. The syntax of seek() is:
file_object.seek(offset[, reference_point])
What is the default value of reference point?
(a) 0
(b) 1
(c) 2
(d) 3
Answer:
(a) 0
12. Fill in the blank:
… clause is used with SELECT statement to display data in a sorted form with respect to a specified column.
(a) WHERE
(b) ORDER BY
(c) HAVING
(d) DISTINCT
Answer:
(b) ORDER BY
13. Fill in the blank:
… is used for point-to-point communication or unicast communication such as radar and satellite.
(a) INFRARED WAVES
(b) BLUETOOTH
(c) MICROWAVES
(d) RADIOWAVES
Answer:
(c) MICROWAVES
14. What will the following expression be evaluated to in Python?print(4+3*5/3-5%2)
Answer:
(b) 8.0
Explanation:
Order of operations (PEMDAS):
- First, multiplication and division: 3 * 5 = 15, 15 / 3 = 5
- Then, modulus: 5 % 2 = 1
- Then, addition and subtraction: 4 + 5 – 1 = 8.0
15. Which function returns the sum of all elements of a list?
(a) count()
(b) sum()
(c) total()
(d) add()
Answer:
(b) sum()
16. fetchall() method fetches all rows in a result set and returns a:
(a) Tuple of lists
(b) List of tuples
(c) List of strings
(d) Tuple of strings
Answer:
(b) List of tuples
17. Assertion (A): To use a function from a particular module, we need to import the module.
Reason (R): import statement can be written anywhere in the program, before using a function from that module.
Answer:
(a) Both (A) and (R) are true and (R) is the correct explanation for (A).
18. Assertion (A): A stack is a LIFO structure.
Reason (R): Any new element pushed into the stack always gets positioned at the index after the last existing element in the stack.
Answer:
(a) Both (A) and (R) are true and (R) is the correct explanation for (A).
SECTION B
19. Atharva is a Python programmer working on a program to find and return the maximum value from the list. The code written below has syntactical errors. Rewrite the correct code and underline the corrections made.
Incorrect Code:
Corrected Code:
20. (a) Differentiate between wired and wireless transmission.
Answer:
Wired Transmission | Wireless Transmission |
---|---|
Uses physical cables (e.g., copper, fiber optic) to transmit data. | Uses electromagnetic waves (e.g., radio waves, microwaves) for data transmission. |
Examples include Ethernet, DSL, and fiber-optic connections. | Examples include Wi-Fi, Bluetooth, and cellular networks. |
Generally more secure, less interference, and stable. | Susceptible to interference, but offers mobility and flexibility. |
Can have higher bandwidth and speed. | Limited by range and bandwidth. |
(b) Differentiate between URL and domain name with the help of an appropriate example.
Answer:
URL | Domain Name |
---|---|
URL (Uniform Resource Locator) is the complete web address used to access a specific resource on the internet. | A domain name is the human-readable address that points to an IP address of a website. |
Example: https://www.example.com/path/to/resource |
Example: www.example.com |
It includes the protocol (HTTP/HTTPS), domain name, and resource path. | It is a part of the URL and represents the server’s name where the website is hosted. |
21. (a) Given is a Python list declaration:
Write the output of:
Answer:
Output:
Explanation:
The slicing starts from index -1 (last element) and moves backward with a step of -1, stopping just before index -4.
(b) Consider the following tuple declaration:
Write the output of:
Answer:
Output:
Explanation:
The value 20
is found at index 1 in the tuple.
22. Explain the concept of “Alternate Key” in a Relational Database Management System with an appropriate example.
Answer:
An alternate key is a candidate key that was not selected as the primary key. It can uniquely identify records in a table but is not the primary key.
Example:
In a Students
table, both Student_ID
and Email_ID
can be candidate keys. If Student_ID
is chosen as the primary key, then Email_ID
will be the alternate key.
23. (a) Write the full forms of the following:
(i) HTML: HyperText Markup Language
(ii) TCP: Transmission Control Protocol
(b) What is the need of Protocols?
Answer:
Protocols are necessary to define the rules and conventions for communication between devices over a network. They ensure that data is transmitted correctly and efficiently across different systems.
24. (a) Write the output of the code given below:
Answer:
Output:
Explanation:
The function short_sub
doubles the strings in the list subjects
. Since the length of subjects
is greater than n=5
, the loop iterates for all elements in the list, concatenating each string with itself.
OR
(b) Write the output of the code given below:
Answer:
Output:
Explanation:
- The value of
a
is30
, which is even, sox += a
will be executed. call(35)
will return35 + 30 = 65
.call(40)
will return40 + 30 = 70
(sincea
is still30
, which is even).- The
end="+"
andend="="
just control how the print statement’s output appears, so the result is65+70=
.
25. (a) Differentiate between CHAR and VARCHAR data types in SQL with appropriate example.
Answer:
CHAR | VARCHAR |
---|---|
Fixed length data type. | Variable length data type. |
Space is padded if the stored value is shorter than the defined length. | Only the actual length of the data is stored. |
Example: CHAR(10) will store 10 characters, even if fewer are provided. |
Example: VARCHAR(10) will store up to 10 characters, but no extra space is used for shorter values. |
More efficient for storing data of consistent length. | More efficient for storing data of variable length. |
Example: |
OR
(b) Name any two DDL and any two DML commands.
Answer:
DDL (Data Definition Language) Commands:
- CREATE – Used to create a new table, view, or other database objects.
- ALTER – Used to modify an existing database object, such as a table.
DML (Data Manipulation Language) Commands:
- SELECT – Used to query and retrieve data from a database.
- INSERT – Used to add new rows of data into a table.
SECTION C
26. (a) Consider the following tables – LOAN and BORROWER:
Table: LOAN
LOAN_NO | B_NAME | AMOUNT |
---|---|---|
L-170 | DELHI | 3000 |
L-230 | KANPUR | 4000 |
Table: BORROWER
CUST_NAME | LOAN_NO |
---|---|
JOHN | L-171 |
KRISH | L-230 |
RAVYA | L-170 |
Natural Join: A natural join combines rows from two tables where they have the same column names (in this case, the LOAN_NO column). It eliminates duplicate columns and combines the information from the matching rows.
Steps for Natural Join:
- The LOAN_NO column is common in both tables, so the rows with matching LOAN_NO values will be joined.
- L-170 exists in both tables, and L-230 also exists in both tables.
- L-171 is in the BORROWER table but not in the LOAN table, so it will be excluded from the result.
Result of the Natural Join:
LOAN_NO | B_NAME | AMOUNT | CUST_NAME |
---|---|---|---|
L-170 | DELHI | 3000 | RAVYA |
L-230 | KANPUR | 4000 | KRISH |
Number of Rows and Columns in the Result:
- Rows: There are 2 rows (for L-170 and L-230).
- Columns: There are 4 columns: LOAN_NO, B_NAME, AMOUNT, and CUST_NAME.
Final Answer:
- Rows: 2
- Columns: 4
(b) Write the output of the queries (i) to (iv) based on the table, WORKER given below:
TABLE: WORKER
WID | F_NAME | L_NAME | CITY | STATE |
---|---|---|---|---|
102 | SAHIL | KHAN | KANPUR | UTTAR PRADESH |
104 | SAMEER | PARIKH | ROOP NAGAR | PUNJAB |
105 | MARY | JONES | DELHI | DELHI |
106 | MAHIR | SHARMA | SONIPAT | HARYANA |
107 | ATHARVA | BHARDWAJ | DELHI | DELHI |
108 | VEDA | SHARMA | KANPUR | UTTAR PRADESH |
(i) SELECT F_NAME, CITY FROM WORKER ORDER BY STATE DESC;
Answer:
F_NAME | CITY |
---|---|
VEDA | KANPUR |
SAHIL | KANPUR |
SAMEER | ROOP NAGAR |
MAHIR | SONIPAT |
MARY | DELHI |
ATHARVA | DELHI |
(ii) SELECT DISTINCT (CITY) FROM WORKER;
Answer:
CITY |
---|
KANPUR |
ROOP NAGAR |
DELHI |
SONIPAT |
(iii) SELECT F_NAME, STATE FROM WORKER WHERE L_NAME LIKE '_HA%';
Answer:
F_NAME | STATE |
---|---|
MAHIR | HARYANA |
ATHARVA | DELHI |
(iv) SELECT CITY, COUNT(*) FROM WORKER GROUP BY CITY;
Answer:
CITY | COUNT(*) |
---|---|
KANPUR | 2 |
ROOP NAGAR | 1 |
DELHI | 2 |
SONIPAT | 1 |
27. (a) Write the definition of a Python function named LongLines() which reads the contents of a text file named ‘LINES.TXT’ and displays those lines from the file which have at least 10 words in it.
Answer:
Example:
Content of ‘LINES.TXT’:
Output:
27. (b) Write a function count_Dwords() in Python to count the words ending with a digit in a text file “Details.txt”.
Answer:
Example:
Content of ‘Details.txt’:
Output:
31. Quickdev, an IT-based firm, located in Delhi is planning to set up a network for its four branches within a city with its Marketing department in Kanpur. Answer the following questions based on the given setup:
(ii) Suggest an ideal layout for connecting all these branches within Delhi.
Answer: The most suitable network layout for connecting all the branches within Delhi would be a star topology.
Reason:
- In a star topology, each branch would be connected to a central hub or switch, which is the server in Branch D (as suggested earlier).
- The star topology is simple to install, easy to manage, and troubleshooting is easier because if one branch faces an issue, it doesn’t affect others.
- This topology is scalable and efficient for handling the communication between the branches.
(iii) Which device will you suggest, that should be placed in each of these branches to efficiently connect all the computers within these branches?
Answer: The ideal device to be used in each branch is a Switch.
Reason:
- A switch is used to connect multiple computers within a branch, allowing them to communicate with each other effectively.
- Switches provide more efficient traffic handling compared to hubs as they intelligently direct data only to the specific device it is intended for, reducing congestion and collisions.
(iv) Delhi firm is planning to connect to its Marketing department in Kanpur which is approximately 300 km away. Which type of network out of LAN, WAN or MAN will be formed? Justify your answer.
Answer: The network formed between the Delhi branch and the Marketing department in Kanpur would be a WAN (Wide Area Network).
Reason:
- A WAN covers large geographical areas, typically connecting multiple locations, including cities and countries.
- Since the distance between Delhi and Kanpur is 300 km, which is beyond the range of LAN or MAN, a WAN is required for this connection.
- WANs typically use routers, leased lines, and sometimes public networks to establish communication between remote locations.
(v) Suggest a protocol that shall be needed to provide help for transferring of files between Delhi and Kanpur branch.
Answer: The most suitable protocol for transferring files between the Delhi and Kanpur branch is FTP (File Transfer Protocol).
Reason:
- FTP is specifically designed to transfer files over a network.
- It allows easy, secure, and reliable transfer of files between systems.
- FTP can operate over a WAN like the one connecting Delhi and Kanpur, ensuring that large files can be transferred efficiently.
32. (a) What possible output(s) are expected to be displayed on screen at the time of execution of the following Python program:
Answer:
The output of the program will be one of the following options, as the program uses random numbers:
- (i) 10#25#15 2. 20#25#25
- The random.randint function will generate random indices for each of
first
,sec
, andthird
, so the values printed will change each time the program is run.
32. (b) The code given below deletes the record from the table “employee” which contains the following record structure:
Answer:
The Python code connects to the MySQL database emp
, executes a DELETE
query to remove the record from the employee
table where the E_code
is "E001"
, and then commits the transaction to save changes in the database. The program will display the number of records deleted, e.g.,:
This confirms that one record with E_code = 'E001'
has been successfully deleted from the table.
33. (a) Difference between CSV and text files:
CSV (Comma Separated Values) File:
- A CSV file contains data in tabular form where each record is separated by commas, and each row of data represents a new line.
- It’s commonly used for storing and exchanging data between applications or databases.
Text File:
- A text file can store plain data, and the contents are displayed as plain text without any specific structure.
- It doesn’t follow a specific format like CSV, so it can contain any kind of data (e.g., numbers, strings, or even a combination of both).
Program for (a):
33. (b) Why is it important to close a file before exiting?
It is important to close a file before exiting for the following reasons:
- To Save Changes: Closing the file ensures that any data written to the file is saved and flushed from the memory to the disk.
- Resource Management: It releases the system resources associated with the file, preventing resource leakage.
- Data Integrity: It ensures that any data in memory is correctly written to the file, avoiding data corruption.
Program for (b):
34. The School Lab Table and Queries:
(i) Identify the columns which can be considered as Candidate keys.
- Candidate keys: LABNO (since it is unique for each lab and can be used to uniquely identify each record in the table).
(ii) Write the degree and cardinality of the table.
- Degree of the table: 5 (as there are 5 columns in the table: LABNO, LAB_NAME, INCHARGE, CAPACITY, FLOOR)
- Cardinality of the table: 5 (as there are 5 rows in the table)
(iii) SQL Queries:
(a) Insert a new row with appropriate data:
(b) Increase the capacity of all labs by 10 students which are on Floor 1:
OR (iii) SQL Queries:
(a) Add a constraint PRIMARY KEY to the column LABNO in the table:
(b) Delete the table LAB: