12 Computer Science SP 08 With Solution
12 Computer Science SP 08 With Solution
Maximum Marks: 70
Time Allowed: : 3 hours
General Instructions:
Section A
1. State true or false:
A string can be surrounded by three sets of single quotation marks or by three sets of double quotation marks.
a) True
b) False
2. What is the full form of DDL?
a) Data Definition Language
b) Dynamic Data Language
c) Detailed Data Language
d) Data Derivation Language
3. User can write Python script using
a) SQL.connect library
b) MySQL.connector library
c) MySQL.connect library
d) None of these
4. Following set of commands are executed in shell, what will be the output?
>>> str = "hello"
>>> str[:2]
a) he
b) llo
c) ello
d) hel
5. Which of the following is the fastest media of data transfer?
a) Fibre Optic
b) Telephone Lines
c) Untwisted Wire
d) Co-axial Cable
6. Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which of the following option can
be used to read all the remaining lines?
a) myfile.read(n-3)
b) myfile.readlines()
c) myfile.read(n)
d) myfile.readline()
7. What is the advantage of DBMS over File Processing System?
a) Redundancy is controlled.
b) It provides backup and recovery.
c) It provides multiple user interfaces.
d) All of these
8. The operation whose result contains all pairs of tuples from the two relations, regardless of whether their attribute values
match.
a) Intersection
b) Set difference
c) Join
d) Cartesian product
9. Which of the following mode will refer to binary data?
a) b
b) w
c) +
d) r
10. Which of the given argument types can be skipped from a function call?
a) positional arguments
b) default arguments
c) keyword arguments
d) named arguments
11. Which data structure is needed to convert infix notation to postfix notation?
a) Tree
b) Stack
c) Queue
d) Branch
12. Which of the following functions removes all leading and trailing spaces from a string?
a) rstrip()
b) lstrip()
c) strip()
d) all of these
13. State true or false:
DNS is a network service type.
a) True
b) False
14. Which of the following cannot be a variable?
a) _on
b) _it
c) in
d) _init_
15. Fill in the blanks:
Columns can be sorted in descending sequence by using the SQL keyword .
16. Find ODD parity bit for 10010001
a) 2
b) 0
c) none of these
d) 1
17. Assertion (A): When the comparison operator is directly applied to a series object, it returns a filtered result containing
the value that returns true.
Reason (R): Applying comparison operator on series works in vectorized way.
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.
18. Assertion (A): flush() function flushes the write buffer of the file stream.
Reason (R): The isatty() method, returns True if the file stream is distinct.
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.
Section B
19. Answer:
1. i. What do you mean by firewall?
ii. For secure transmission through unguided media, which ones would you avoid?
2. OR
i. Wireless networks employ strategies to avoid collisions. Why can't they detect collisions?
20. List the most common parameters and the usage that are passed to communicate with the database.
21. How many times will the given loop iterate?
i = 0
while (i < 25):
print("Python")
i = i + 1
OR
Write a program that rotates the elements of a list so that the element at the first index moves to the second index, the
element in the second index moves to the third index, etc., and the element in the last index moves to the first index.
22. Answer:
1. Which method creates and returns a cursor object that may be used to execute SQL commands?
2. What does connection.commit( ) method do?
23. Write a Python program to concatenate following dictionaries to create a new one.
d1 = {'A': 10, 'B' : 20}
d2 = {'C': 30, 'D' : 40}
d3 = {'E': 50, 'F' : 60}
OR
Observe the output
i. >>> x = ‘Sum' * '3'
ii. >>> x = ‘Sum' + '3'
24. Write a program to accept a filename from the user and display all the lines from the file which contain Python comment
character '# '.
OR
Write a function to count the number of alphabets present in a text file "NOTES.txt".
25. Find the output of the following program:
Section C
26. Answer:
1. Find the syntax error in the following program and underline after correct them.
w = 90;
while (w > 60)
print (w)
w = w - 50
27. Define a function overlapping () that takes two lists and returns true if they have at least one member in common, False
otherwise.
28. Explain the use of ORDER BY clause.
OR
TABLE: FLIGHTS
TABLE: FARES
Number of computers
Admin Wing 10
Lib Wing 25
i. Suggest the type of networking (LAN, MAN, WAN) for connecting Lib Wing to Admin Wing. Justify your answer.
ii. Suggest the most suitable place (i.e. wing) to house the server, with a suitable reason.
iii. Suggest and placement of the following devices with reasons.
a. Repeater
b. Switch
iv. The Institute is planning to link its study centre situated in Delhi. Suggest an economic way to connect it with
reasonably high speed. Justify your answer.
v. Expand the following
PAN
WAN
34. Sarthak a student of class XII, created a table” Class” with following attribute Sname, Sroll,Smark and Grade . Grade is
one of the columns of this table. To find the details of students where Grades have not been entered, he wrote the
following Mysql query which did not give the desired result:
SELECT Sname FROM Class WHERE Grade=”Null”;
SELECT Sroll FROM Class WHERE Grade=”Null”;
SELECT Smark FROM Class WHERE Grade=”Null”;
SELECT * FROM Class WHERE Grade=”Null”;
SELECT Grade FROM Class WHERE Grade=”Null”;
Help Sarthak to run the query by removing the errors from the query and write the correct query.
OR
Table: Issued
Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
i. SELECT COUNT() FROM Books;
ii. SELECT MAX(Price) FROM Books WHERE Quantity >= 15;
iii. SELECT Book_Name, Author_Name FROM Books WHERE Publishers = "EPB";
iv. SELECT COUNT (DISTINCT Publishers) FROM Books WHERE Price >= 400;
35. Answer:
1. i. What is data redundancy? What are the problems associated with it?
ii. Consider the following tables WORKER and PAYLEVEL and answer the following parts of this question :
Table : WORKER
Table : PAYLEVEL
PLEVEL PAY ALLOWANCE
TABLE: GARMENT
TABLE: FABRIC
FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE
i. To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE.
ii. To display the details of all the GARMENTS, which have READYDATE in between 08-DEC-07 and
16-JUN-08 (inclusive of both the dates).
iii. To display the average PRICE of all the GARMENTS. Which are made up of FABRIC with FCODE as
F03.
iv. To display FABRIC wise highest and lowest price of GARMENTS from GARMENT table. (Display
FCODE of each GARMENT alongwith highest and lowest price.)
v. To display garment’s description with their price whose fabric is silk.
Class 12 - Computer Science
Sample Paper - 08 (2023-24)
Solution
Section A
1. (a) True
Explanation: True, A string can be surrounded by three sets of single quotation marks or by three sets of double
quotation marks.
2. (a) Data Definition Language
Explanation: Data Definition Language is a language used to define data structures and modify data.
3. (b) MySQL.connector library
Explanation: MySQL.connector library
4. (a) he
Explanation: str[:2] prints only the values at index 0 and 1 (as 2 is exclusive) of string and hence the answer is “he”.
5. (a) Fibre Optic
Explanation: Fibre Optic
6. (b) myfile.readlines()
Explanation: myfile.readlines()
7. (d) All of these
Explanation: It provides all the mentoined features.
8. (d) Cartesian product
Explanation: Cartesian product is the multiplication of all the values in the attributes.
9. (a) b
Explanation: b, binary mode is referred for binary data.
10. (b) default arguments
Explanation: default arguments
11. (b) Stack
Explanation: The stack data structure is needed to convert infix notation to postfix notation.
12. (c) strip()
Explanation: strip()
13. (a) True
Explanation: True
14. (c) in
Explanation: in is a keyword
15. 1. DESC
2. DESC , used with ORDER BY
16. (b) 0
Explanation: Parity refers to the number of bits set to 1 in the data item
Even parity - an even number of bits are 1
Odd parity - an odd number of bits are 1
A parity bit is an extra bit transmitted with a data item, chose to give the resulting bits even or odd parity
Even parity - data: 10010001, parity bit 1
Odd parity - data: 10010001, parity bit 0
17. (d) A is false but R is true.
Explanation: Applying comparison operator on series works in vectorized way i.e applies this check on each element
and then return true/ false for each element.
18. (c) A is true but R is false.
Explanation: The flush() function flushes the write buffer of the file stream and isatty() function returns True if the file
stream is interactive otherwise it return False.
Section B
19. Answer:
1. i. A firewall is a piece of security software or hardware designed to protect web servers.
ii. Microwave and Radio wave are avoided for secure transmission through unguided media.
2. OR
i. In wireless, we don't have the luxury of detecting collisions and resending packets because there's no way to
detect a collision over the air. Collisions occur when multiple transmissions take place at the same over a
network. Wireless networks are half-duplex in nature, i.e., they cannot listen while transmitting (and while
listening, they cannot transmit - only one operation at a time). Hence they cannot find out if any other
transmission is taking place simultaneously, and thus cannot detect collisions.
Password The password for the user name that you provided to connect to the database.
21. 25 times
OR
OR
i. It will give TypeError and correct code is x = ‘Sum’ * 3
ii. Sum3
24. file_name = raw_input("Enter file name or path:")
try:
for line in open(file_name):
line = line.strip() #remove extra spaces
if line[0]=='#':
print line
except:
print "File Not Found"
OR
def count_alphabet():
file_name="NOTES.txt"
ctr = 0
with open(file_name, 'r') as fileObject:
for line in fileObject:
for word in line:
for char in word:
if char.isalpha():
ctr = ctr + 1
print(ctr)
25. Output
49
25
9
1
Section C
26. Answer:
1. Correct code is
w = 90
while(w > 60) :
print(w)
w = w - 50
2. Output
The original dictionary : {'Ankit' : (15, 'NIIT'), 'Nitin' : (21, 'NIIT')}
The list after conversion : [( 'Ankit', 15, 'NIIT'), ('Nitin', 21, 'NIIT')]
27. def overlapping (list1, list2):
len_1 = len(list1)
len_2 = len(list2)
for i in range (0, len_1):
for j in range (0, len_2):
if list1[i]==list2[j]:
return True
else:
return False
28. The ORDER BY keyword is used to sort the result set along a specified column with the SELECT command.
The ORDER BY keyword sorts the records in ascending order by default. If you want to sort the records in a descending
order, you can use the DESC keyword.
Syntax
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC/DESC;
OR
Create a database Creating database is an easier task. You need to just type the name of the database in a CREATE
DATABASE command.
Syntax
CREATE DATABASE [IF NOT EXISTS]<database_name>;
CREATE DATABASE command will create an empty database with the specified name and would not contain any
table.
IF NOT EXISTS is an optional part of this statement which prevents you from an error if there exists a database with
the given name in the database catalog.
For example, mysql>CREATE DATABASE BOOK;
Output Query OK, 1 row affected <0.01 sec>
29. CountYouMe function will count the number of occurences of word You and Me in the file given.
def CountYouMe():
wordlist = [line.strip() for line in open(‘Notes.txt’)]
# Searching for a word in a file
count =0
for word in wordlist:
words = word.split(" ")
for word in words:
# Remove all leading and trailing white spaces
word =word.strip().lower()
if word == 'you' or word=='me'():
count = count + 1
if count == 0:
print ("Not found in file")
else:
print ("count=", count)
Example: If the file contains
You are my best friend
You and me make a good team.
Output would be: count=3
30. The differences between a local variable and a global variable are as given below :
Local Variable Global Variable
1. It is a variable which is declared within a function or within a 1. It is a variable which is declared outside all the
block functions
3.Local variables are created when the function has started 3.Global variable is created as execution starts
execution and are lost when the function terminates. and is lost when the program ends.
For example, in the following code, x, xCubed are global variables and n and cn are local variables.
def cube(n):
cn = n * n * n
return cn
x = 10
xCubed = cube(x)
print(x, "cubed is", xCubed)
Section D
31. MAX_SIZE = 1000
stack = [0 for i in range(MAX_SIZE)]
top = 0
def isEmpty():
global top
return top == 0
def push(x):
global stack, top
if top >= MAX_SIZE:
return
stack[top] = x
top += 1
def pop():
global stack, top
if isEmpty():
return
else:
top -= 1
return stack[top]
string = input().split()
for i in string:
push(i)
while not isEmpty():
x = pop()
print(x+x, end = ' ')
32. i. SELECT FL_NO, NO_FLIGHT FROM FLIGHTS WHERE STARTING = 'KANPUR' AND ENDING =
'BENGALURU';
ii. SELECT * FROM FLIGHTS ORDER BY FL_NO;
iii. SELECT FL_NO, FARE + FARE * TAX%100 FROM FARES WHERE FL_NO = (SELECT FL_NO FROM
FLIGHTS WHERE STARTING='DELHI' AND ENDING='MUMBAI');
iv. SELECT MIN(FARE) FROM FARES GROUP BY AIRLINES HAVING AIRLINES='INDIAN AIRLINES’;
v. SELECT * FROM FARES WHERE AIRLINES="Indian Airlines";
Section E
33. i. Since, the distance between Lib Wing and Admin Wing is small. So type of networking is small, i.e. LAN.
ii. Since, maximum number of computers are in Student Wing, so suitable place to house the server is Student Wing.
iii. a. Repeater should be installed between Student Wing and Admin Wing as distance is more than 60 m.
b. Switch should be installed in each wing to connect several computers.
iv. Broadband connection as it is between economical and speedy.
v. Personal Area Network
Wide Area Network
34. SELECT Sname FROM Class WHERE Grade IS ”Null”;
SELECT Sroll FROM Class WHERE Grade IS ”Null”;
SELECT Smark FROM Class WHERE Grade IS ”Null”;
SELECT * FROM Class WHERE Grade IS ”Null”;
SELECT Grade FROM Class WHERE Grade IS ”Null”;
OR
i. COUNT()
5
ii. MAX(Price)
750
1 P001
2 P003
2 P002
ii.
MAX (DOB) MIN (DOJ)
12-3ul-1987 13-Sep-2004
iii.
Name Pay
Radhe Shyam 26000
Chander Nath 12000
iv.
PLEVEL PAY+ALLOWANCE
P003 18000
2. OR
i. IS NULL should be used in place of = NULL. Following is the correct statement: SELECT * FROM
employee WHERE grade IS NULL ;
ii. i. SELECT GCODE, DESCRIPTION FROM GARMENT ORDER BY GCODE DESC;
ii. SELECT * FROM GARMENT
WHERE READYDATE BETWEEN '08-DEC-07' AND '16-JUN-08';
iii. SELECT AVG(PRICE) FROM GARMENT WHERE FCODE='F03';
iv. SELECT-FCODE, MAX(PRICE), MIN(PRICE)
FROM GARMENT GROUP BY FCODE;
v. SELECT DESCRIPTION, PRICE FROM GARMENT
WHERE GARMENT.FCODE = FABRIC.FCODE AND TYPE ="SILK";