Subject: Computer Science
Class XII
Time Allowed: 3 hours
Maximum Marks: 70
General Instructions:
1. This question paper contains five sections, Section A to E.
2. All questions are compulsory.
3. Section A have 18 questions carrying 01 mark each.
4. Section B has 07 Very Short Answer type questions carrying 02 marks each.
5. Section C has 05 Short Answer type questions carrying 03 marks each.
6. Section D has 03 Long Answer type questions carrying 05 marks each.
7. Section E has 02 questions carrying 04 marks each. One internal choice is given in Q35 against part c only.
8. All programming questions are to be answered using Python Language only
SECTION A
1. State True or False
“Identifier can start with an underscore “
Ans. True
2. Which of the following can be used as valid variable identifier(s) in Python?
(a) 4thSum (b) Total (c) Number# (d) _Data
3. Given the following dictionary
dic1={‘aman’:85,’pahul’:98,’divya’:75}
print(sorted(dic1))
select the correct output:
a.[‘aman’, ‘divya’, ‘pahul’]
b.[‘pahul’, ‘divya’, ‘aman’]
c.[75,85,98]
d.[‘aman’:85,’divya’:75,’pahul’:98]
4. Consider the given expression:
True or False and not True
Which of the following will be correct output if the given expression is evaluated?
(a) True (b) False (c) NONE (d) NULL
5 Select the correct output of the code
a = ‘Happy new year 2023’
a = a.split(‘e’)
print(a)
a. [‘Happy’ ,‘n’, ‘w’, ‘y’, ‘ar’ ,‘2023’]
b. [‘Happy’ ,‘n w’, ‘y ar’ ,‘2023’]
c. [‘Happy n’, ‘w y’, ‘ar 2023’]
d. [‘Happy’,’nw’,’yar’ ,‘2023’]
6. Which of the following is not a file access mode
a. rb b. rb+ c. wb d. rw
7. The ____________command can be used to makes changes in the rows of a table in SQL.
a. Alter b. Modify c. Insert d. Update
8. Suggest the suitable command to remove the pre-existing database named Clients.
(a) delete database Clients
(b) drop Clients
(c) drop database Clients
(d) Alter table drop Clients
9.Which of the following statement(s) would give an error after executing the following code? STRING=”WELCOME “ #Statement 1
NOTE=” ” #Statement 2
for S in range[0,8]: #Statement 3
print (S) #Statement 4
10. Fill in the blank:
A column or a group of columns which can be used as the primary key of relation is called a __________
(a) Primary Key (b) Candidate Key (c) Alternate key (d) Foreign Key
11. Minimum argument required in seek function is
a. 0 b. 1 c. 2 d. 3
12. Fill in the blank:
The columns of the table is called __________
(a) Attributes (b) Degree (c) Tuples (d) Cardinality
13 Fill in the blanks Protocol is a set of ______________
a. Formats b. Procedures c. Format and Procedures d. None of the mentioned
14. Evaluate the following expression and identify the correct answer.
x = 6 + 36/6 + 2*5
(a) 45.0 (b) 17.0 (c) 26.25 (d) 22.0
15.Which of the following clauses in SQL is most appropriate to use to select matching tuples in a specific range of values?
(a) IN (b) LIKE (c) BETWEEN (d) IS
16 __________returns the number of rows affected by the last execute method for the same cur object
a. count() b. rowcount() c. countrow() d. countall()
Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct choice as
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True
17. Assertion (A): – The Global variable can be accessed inside or outside of the function
Reasoning (R): – A variable declared outside of the function or in global scope is known as global variable.
Ans. (a) Both A and R are true and R is the correct explanation for A
18. Assertion (A): Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
Reason (R): In Function, a return statement with no arguments gives an error message
Ans. (c) A is True but R is False
SECTION B
19. Gurjot has written a code to input a number and find a new number Reverse from Number with each of the digits of Number in reversed order and display the content of Reverse on screen. His code is having errors. Rewrite the correct code and underline the corrections made.
Def REVERSAR(Number):
S=0
while Number
S=S*10+Number/10
Number=Number//10
print(S)
Ans.
def REVERSAR(Number):
S=0
while Number>0:
S=S*10+Number%10
Number=Number//10
print(S)
20. What is secure Communication? Differentiate between HTTP and HTTPS.
Ans. Secure Communication: The standard security technology that establishes an encrypted connection between a web server and a browser.
OR
How are tags used in XML different from tags in HTML? Write 2 points
21. (a) Given is a Python string declaration:
myexam=”@@CBSE Examination 2022@@”
Write the output of: print(myexam[:5:])
Ans. @@CBS
(b) Write the output of the code given below:
my_dict = {‘empno’: 101, ‘name’: ‘Sonali’}
my_dict[‘name’] = ‘Nikhil’
my_dict[‘Gender’] = ‘M’
print(my_dict.items())
Ans. dict_items([(‘empno’, 101), (‘name’, ‘Nikhil’), (‘Gender’, ‘M’)])
22. Differentiate between the Primary key and Alternate key of a table with the help of an example
Ans. A primary key is a column (or columns) in a table that uniquely identifies the rows in that table.
The values placed in primary key columns must be unique for each row: no duplicates can be tolerated. In addition, nulls are not allowed in primary key columns.
Here in Emp table you can choose either Empno or phone columns as primary key, Empno is preferable choice.
Candidate column other the Primary column is called alternate key, like if Empno is PK then Phone would be the Alternate key.
23 (a) Write the full form of the following abbreviations:
(i) POP (ii) VoIP
Ans. (i) POP: Post Office Protocol (ii) VoIP: Voice Over Internet Protocol
(b) What is web hosting?
Ans. Web Hosting: Web hosting is the process of uploading/saving the web content on a web server to make it available on www.
24. Predict the output of the Python code given below:
def Diff(N1,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [8,20,1,4,3]
for CNT in range (4,0,-1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Diff(A,B),’*’, end=’ ‘)
Ans. 1 * 3 * 19 * 12 *
OR
Predict the output of the Python code given below:
tuple1 = (6, 8, 32, 66, 3 ,6)
list1 =list(tuple1)
new_list = []
for i in list1:
if i%2==0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
Ans. (6, 8, 32, 66, 6)
25 While using SQL pattern matching, what is the difference between ‘_’(underscore) and ‘%’ wildcard symbols?
Ans. “_” is used to represent a single character whereas “%” is used to represent any sequence of Zero or more characters.
OR
Categorize the following commands as DDL or DML:
DROP TABLE, INSERT, ALTER, DELETE
Ans. DDL-DROP TABLE, ALTER
DML-INSERT, DELETE
SECTION C
26 (a) Consider the following tables – Salesperson and item
TABLE: SALESPERSON
What will be the output of the following statement?
SELECT * FROM Salesperson NATURAL JOIN ITEM;
Ans.
(b) Consider the following table:
Give the output
(a) Select sum(distance) from schoolbus where transporter=”Yadav Co.”
Ans. 50
(b) Select min(noofstudents) from schoolbus
Ans. 40
(c) Select avg(charges) from schoolbus where transporter=”Anand Travels”
Ans. 70000
(d) Select distinct transporter from schoolBus.
27 Write a method in python to read lines from a text file INDIA.TXT, to find and display the occurrence of the word “India”. For example: If the content of the file is “India is the fastest growing economy. India is looking for more investments around the globe. The whole world is looking at India as a great market. Most of the Indians can foresee the heights that India is capable of reaching.” ____
Ans.
def display():
f=open(“INDIA.TXT”,”r”)
k=f.read()
l=k.split()
print(l.count(“India”))
f.close( )
The output should be 4
OR
Write a method/function DISPLAYWORDS() in python to read lines from a text file STORY.TXT, and display those words, which are less than 4 characters.
Ans.
def DISPLAYWORDS():
c=0
file=open(“STORY.TXT”,”r”)
line = file.read()
word = line.split()
for w in word:
if len(w)<4:
print (w)
file.close()
28(a). Consider the following tables EMPLOYEES and EMPSALARY. Write SQL outputs for SQL queries (i) to (iv).
(i) SELECT FIRSTNAME, SALARY FROM EMPLOYEES, EMPSALARY WHERE DESIGNATION =‘Salesman’ AND EMPLOYEES.EMPID=EMPSALARY.EMPID;
Ans.
(ii) SELECT COUNT (DISTINCT DESIGNATION)FROM EMPSALARY;
Ans.
(iii) SELECT DESIGNATION, SUM(SALARY) FROM EMPSALARY GROUP BY DESIGNATION HAVING COUNT (*)>2;
Ans.
(iv) SELECT SUM (BENEFITS) FROM EMPLOYEES WHERE DESIGNATION = ’Clerk’;:
Ans.
(b) Write the command to view all the databases.
Ans. show databases;
29 Write definition of a Method AFIND(CITIES) to display all the city names from a list of CITIES, which are starting with alphabet A.
For example:
If the list CITIES contains
[“AHMEDABAD”,”CHENNAI”,”NEW DELHI”,”AMRITSAR”,”AGRA”]The following should get displayed
AHEMDABAD
AMRITSAR
AGRA
Ans. def AFIND(CITIES):
for i in CITIES:
if i[0]= =’A’:
print( i)
30.Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers. The function returns the value deleted from the stack.
Ans. def popStack(Arr) :
if len(Arr)==0: # If stack is empty
print(“Underflow”)
else:
print(“no deleted: “,Arr.pop())
OR
Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at least one element, otherwise display appropriate error message.
Ans. def PUSH(Arr):
s=[]
for x in range(0,len(Arr)):
if Arr[x]%5==0:
s.append(Arr[x])
if len(s)==0:
print(“Empty Stack”)
else:
print(s)
SECTION D
31. BeHappy Corporation has set up its new centre at Noida, Uttar Pradesh for its office and web-based activities. It has 4 blocks of buildings.
Distance between the various blocks is as follows:
A to B 40 m
B to C 120m
C to D 100m
A to D 170m
B to D 150m
A to C 70m
Numbers of computers in each block
Block A – 25
Block B – 50
Block C – 125
Block D – 10
(a) Suggest and draw the cable layout to efficiently connect various blocks of buildings within the Noida centre for connecting the digital devices.
Ans.
(b) Suggest the placement of the following device with justification
i. Repeater ii. Hub/Switch
Repeater: between C and D as the distance between them is 100 mts.
Hub/ Switch: in each block as they help to share data packets within the devices of the network in each block
(c) Which kind of network (PAN/LAN/WAN) will be formed if the Noida office is connected to its head office in Mumbai?
Ans. (c) WAN
(d) Which fast and very effective wireless transmission medium should preferably be used to connect the head office at Mumbai with the centre at Noida
Ans. (d) Satellite
32. (a) Write the output of the code given below:
p=5
def sum(q,r=2):
global p
p=r-q*2
print(p, end=’#’)
a=20
b=5 sum(a,b)
sum(r=5,q=10)
Ans. -35#-15#
(b) Write Python code for the following:
(i) To create a MySQL connection named db for localhost, with username = “teacher” and password = “myclass”
Ans. db=MySQLdb.connect(host=”localhost”, user=”teacher”, passwd = “myclass”)
(ii) To create a database cursor named as dbcrsr.
Ans. dbcrsr = db.cursor()
(iii) To open a database named “CLASS” using the above declared database cursor dbcrsr.
Ans. dbcrsr.execute(“USE CLASS”)
(iv) To add a new record into the table “STUDENT” in the above connected database “CLASS” with details for the attributes (SNo, SName, Marks) as (“S102”, “Tanya”, 92.5)
Ans. dbcrsr.execute(“INSERT INTO STUDENT (SNo, SName, Marks) VALUES (“S102”, “Tanya”, 92.5))
OR
(a) Find and write the output of the following Python code:
Str1=”EXAM2018”
Str2=””
I=0
While I < len(Str1):
If Str1[I] >=”A” and Str1[I] <= “M”
Str2=Str2+Str1[I+1]
Elif Str1[I] >=”0” and Str1[I] <=”9”
Str2=Str2+Str1[I-1]
Else:
Str2=Str2+”*”
I=I+1
Print(Str2)
Ans. X*M2M201
(b) A resultset is extracted from the database using the cursor object (that has been already created) by giving the following statement.
Mydata=cursor.fetchone()
(i) How many records will be returned by fetchone() method?
Ans. One record
(ii) What will be the datatype of Mydata object after the given command is executed?
Ans. tuple
33. What is Delimiters in CSV files? Write a function display () in python to display all the students who have got a distinction(scored percentage more than or equal to 75) from a csv file “stud.csv”, assuming the csv file is containing the following fields: roll,name,percentage
Ans. Delimiter specifies the character used to separate each field. The default is the comma ( ‘,’ ). However, CSV files can use delimiters other than a comma. Few popular ones are | and \t.
def display():
with open(“stud.csv”, “r”) as csvfile:
csvreader = csv.reader(csvfile)
for rows in csvreader:
if rows[2]>=75:
print(rows)
OR
Write a Program in Python that defines and calls the following user defined functions:
(i) add() – To accept and add data of EMPLOYEE to a CSV file ‘emp.csv’. Each record consists of a list with field elements as empid, ename and esalary to store employee id, employee name and employee salary respectively.
Ans.
def add():
with open(“emp.csv”, “a”, newline=’’) as csv:
csv_writer=csv.writer(csv)
r=int(input(“enter empid.csv :”))
n=input(“enter name :”)
m=int(input(“enter salary :”))
rec=[r,n,m]
csv_writer.writerow(rec)
(ii) search()- To display the records of the employee whose salary is more than 10000.
Ans.
def search():
with open(“emp.csv”, “r”) as csvfile:
csvreader = csv.reader(csvfile)
for rows in csvreader:
if rows[2]>10000:
print(rows)
SECTION E
34 Consider the table, MOVIEDETAILS given below:
(a) Identify the degree and cardinality of the table.
Ans. Degree: 5
Cardinality: 6
(b) Which field should be made the primary key? Justify your answer.
Ans. MOVIEID should be made the primary key as it uniquely identifies each record of the table.
(c) Identify the candidate key(s) from the table MOVIEDETAILS.
Ans. MOVIEID and TITLE
(d) Consider the table SCHEDULE given below:
Which field will be considered as the foreign key if the tables MOVIEDETAILS and SCHEDULE are related in a database?
Ans. MOVIEID
35. Amritya Seth is a programmer, who has recently been given a task to write a python code to perform the following binary file operations with the help of two user defined functions/modules:
a. AddStudents() to create a binary file called STUDENT.DAT containing student information – roll number, name and marks (out of 100) of each student.
b. GetStudents() to display the name and percentage of those students who have a percentage greater than 75. In case there is no student having percentage > 75 the function displays an appropriate message. The function should also display the average percent. He has succeeded in writing partial code and has missed out certain statements, so he has left certain queries in comment lines.
You as an expert of Python have to provide the missing statements and other related queries based on the following code of Amritya.
Answer any four questions (out of five) from the below mentioned questions:
import pickle
def AddStudents():
____________ #1 statement to open the binary file to write data
while True:
Rno = int(input(“Rno :”))
Name = input(“Name : “)
Percent = float(input(“Percent :”))
L = [Rno, Name, Percent]
____________ #2 statement to write the list L into the file
Choice = input(“enter more (y/n): “)
if Choice in “nN”:
break
F.close()
def GetStudents():
Total=0
Countrec=0
Countabove75=0
with open(“STUDENT.DAT”,”rb”) as F:
while True:
try:
____________ #3 statement to read from the file
Countrec+=1
Total+=R[2]
if R[2] > 75:
print(R[1], “ has percent = “,R[2])
Countabove75+=1
except:
break
if Countabove75==0:
print(“There is no student who has percentage more than 75”)
average=Total/Countrec
print(“average percent of class = “,average)
AddStudents()
GetStudents()
i. Which of the following commands is used to open the file “STUDENT.DAT” for writing only in binary format? (marked as #1 in the Python code)
a. F= open(“STUDENT.DAT”,’wb’)
b. F= open(“STUDENT.DAT”,’w’)
c. F= open(“STUDENT.DAT”,’wb+’)
d. F= open(“STUDENT.DAT”,’w+’)
ii. Which of the following commands is used to write the list L into the binary file, STUDENT.DAT? (marked as #2 in the Python code)
a. pickle.write(L,f)
b. pickle.write(f, L)
c. pickle.dump(L,F)
d. f=pickle.dump(L)
iii. Which of the following commands is used to read each record from the binary file STUDENT.DAT? (marked as #3 in the Python code)
a. R = pickle.load(F)
b. pickle.read(r,f)
c. r= pickle.read(f)
d. pickle.load(r,f)
iv. Which of the following statement(s) are correct regarding the file access modes?
a. ‘r+’ opens a file for both reading and writing. File object points to its beginning.
b. ‘w+’ opens a file for both writing and reading. Adds at the end of the existing file if it exists and creates a new one if it does not exist.
c. ‘wb’ opens a file for reading and writing in binary format. Overwrites the file if it exists and creates a new one if it does not exist.
d. ‘a’ opens a file for appending. The file pointer is at the start of the file if the file exists.
v. Which of the following statements correctly explain the function of seek() method?
a. tells the current position within the file.
b. determines if you can move the file position or not.
c. indicates that the next read or write occurs from that position in a file.
d. moves the current file position to a given specified position