You are on page 1of 18

Subject-Computer Science (083)

Year: 2022-23
Class 12
Duration: 3 hours Max Marks: 70

General Instructions:

1. This question paper contains five sections, Section A to E.

2. All questions are compulsory.

3. Section A has 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.

ps
8. All programming questions are to be answered using Python Language only.
Ki

© Kips Learning Pvt. Ltd 2023


Part-A
1. State True or False: 1
Operator Associativity defines the order in which operators of the same precedence are
evaluated.

Ans True

2. The statement that helps to terminate the loop is called ______________. 1


a) continue
b) break
c) exit
d) pass

Ans b) break

3. Which of the following options will not result in an error when performed on tuples in Python 1
where tupl=(5,2,7,0,3)?

a) tupl[1]=2
b) tupl.append(2)
c) tupl1=tupl+tupl
d) tupl.sort()

ANs c) tupl1=tupl+tupl

4.

Ans
a) Error
b) False
c) 0
d) -1

d)-1
ps
What is the value returned by find() function for an unsuccessful search of sequence in the given
string?
1

5. Choose the appropriate statement to change the "year" value from 2000 to 2015. 1
Ki
car = {
"brand": "Maruti Suzuki",
"model": "Dzire",
"year": 2000
}

a) car["year"] = 2015
b) car.year = 2015
c) car.year[2015]
d) year = 2015

Ans a) car["year"] = 2015

6. The ________________ method returns the file object’s current position. 1


a) seek(curr)
b) tell()
c) loc()
d) curr()

Ans b) tell()

© Kips Learning Pvt. Ltd 2023


7. To give a temporary name to a table or a column in a table for more readability, what is used? 1
a) SQL Wildcards
b) SQL aliases
c) SQL LIKES
d) SQL Comments

Ans b) SQL aliases

8. By using an aggregate function, the __________clause filters the results of the GROUP BY 1
clause.
a) HAVING
b) ORDER BY
c) DISTINCT
d) GROUP BY

Ans a) HAVING
9. What is the meaning of “ORDER BY” clause in MySQL? 1
a) Sorting your result set using column data
b) Aggregation of fields
c) Sorting your result set using row data
d) None of the above
Ans

10.
ps
a) Sorting your result set using column data

What will happen when you run the following MySQL statement?

SELECT e.emp_id, e.fname,e.lname,d.name


FROM employee e INNER JOIN department d
ON e.dept_id=e.dept_id;
1

a) Error
b) No Error
Ki
Ans b) No Error

11. To read two characters from a file object infile, we use ____________. 1
a) infile.read(2)
b) infile.read(0,3)
c) infile.readline(2)
d) infile.readlines()

Ans a) infile.read(2)

12. “SELECT” clause cannot be used without which clause in MySQL? 1


a) FROM
b) WHERE
c) ORDER BY
d) All of the above

Ans a) FROM
13. In an environment with many high-voltage devices, the best transmission medium would be 1
_______.

© Kips Learning Pvt. Ltd 2023


a) Twisted-pair cable
b) Coaxial cable
c) Optical fibre
d) None of these

Ans c) Optical fibre

14. Observe the given SQL query and choose the correct option. 1

SELECT branch_name, COUNT (DISTINCT customer_name)


FROM depositor, account
WHERE depositor.account_number = account.account_number
GROUP BY branch_id

a) The query is syntactically correct, but gives the wrong answer.


b) The query is syntactically wrong.
c) The query is syntactically correct and gives the correct answer.
d) The query contains one or more wrongly named clauses.

Ans b) The query is syntactically wrong.

15.

ANs
16.
b) False

a) True
ps
State True or False:

SQL does not permit distinct with count(*)

a) True

Which connector is used to link database with Python?


1

a) Mysql-connector
Ki
b) Connector-Python
c) Python-connector
d) Mysql-Python-connector

ANs a) Mysql-connector

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 , 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.
17. Assertion (A): The scope refers to different parts of the function and program within which a 1
variable or value is legal and accessible.
Reason (R): Global is a keyword to create global variable.

Ans b) Both A and R are true , but R is not the correct explanation for A.

18. Assertion (A): The pickling module consist of two main functions. load() is used during the 1
pickling process, whereas dump() is used during unpickling process.

© Kips Learning Pvt. Ltd 2023


Reason (R): You can use load() and dump() function by adding pickle module. You can use
"import pickle" statement to include the pickle module in your program.

ANs d) A is false but R is True.

Part- B

19. Sejal has written a code to print prime numbers between given range. Her code is having errors. 2
Rewrite the correct code and underline the corrections made.

def prime(lower,up)
Print("Prime numbers between", lower, "and", upper, are:)
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num)
if (num % i) = 0:
break:
else:
print(num)
def prime(10,20)

Ans def prime(lower,upper):

ps
print("Prime numbers between", lower, "and", upper, "are:")
for num in range(lower, upper + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:

else:

prime(10,20)
break

print(num)

20. Your friend wishes to install a wireless network in his office. Explain to him the difference 2
Ki
between guided and unguided media.
OR

What is a network? Write any two advantages of a network.

ANs
Basis for
Guided Media Unguided Media
Comparison

Basic The signal requires a physical The signal is broadcasted


path for transmission. through air or sometimes
water.

Alternative It is called wired It is called wireless


name communication or bounded communication or unbounded
transmission media. transmission media.

© Kips Learning Pvt. Ltd 2023


Direction It provides direction to signal It does not provide any
for travelling. direction.

Types Twisted pair cable, coaxial Radio wave, microwave, and


cable, and fibre optic cable. infrared.

OR

A computer network consists of two or more computers that are linked to share resources
such as printers and CD-ROMs, exchange files, or allow electronic communications.

Advantages of a network:
• A user can logon to a computer anywhere on the network and access their work files
from the file server.
• A network provides the means to exchange data among the computers.
• Computers can be managed centrally- with the same software installed on each one.
• Time- It is much faster to install an application once on a –network and copy it across the
network to every workstation.
• Networking also provides the function of back-up.

21.
ps
• Networking provides a flexible networking environment.
• Security - The Network Manager can allocate usernames and passwords to all the users
to help prevent unauthorised access.
Fill the blanks in the following code:

import ________#statement 1
with open("Text.csv", 'r') as ________#statement 2
L = csv.reader(fin)
for line in ___: #statement 3
print(___________) #statement 4
2
Ki
Choose the correct option to fill in statement 1,2,3,4, respectively.
a) csv, fin, L, line
b) CSV , f , fin , line
c) CSV , fin , l , line
d) None of these

Ans a) csv, fin, L, line

22. What is the difference between the primary key and unique key? 2

Ans Both primary and unique key carry unique values, but the primary key cannot have a null value,
whereas the Unique key can. In a table, there cannot be more than one primary key, but unique
keys can be multiple.

23. (a) Write the full forms of the following: 2


(i) SMTP (ii) URL
(b) What is the use of VoIP?
Ans a) (i) SMTP: Simple Mail Transfer Protocol
(ii) URL: Uniform Resource Locator

© Kips Learning Pvt. Ltd 2023


b) Voice over Internet Protocol (VoIP) is one of a family of internet technologies, communication
protocols, and transmission technologies for delivery of voice communications and multi-media
sessions over internet protocol (IP) network, such as the internet.

24. Predict the output of the Python code given below: 2


dic1={10:0, 20:2}
dic2={30:3, 40:4}
dic3={50:5,60:6}
dic4 = {}
for d in (dic1, dic2, dic3):
dic4.update(d)
print(dic4)

OR

def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():

else:

print(m)
ps
m=m+str[i].upper()

if i%2==0:
m=m+str[i-1]
else:
m=m+"#"

Display('Fun@Python3.0')

ANs {10: 0, 20: 2, 30: 3, 40: 4, 50: 5, 60: 6}


Ki
OR
fUNnpYTHON

25. Differentiate between fetchone() and fetchall() methods with suitable examples for each. 2
OR
Differentiate between degree and cardinality.

Ans fetchall() fetches all the rows of a query result. An empty list is returned if there is no record to
fetch the cursor.
fetchone() method returns one row or a single record at a time. It will return None if no more
rows / records are available.
OR

Degree is the total number of attributes in the table, whereas, cardinality is the total number of
tuples in the table.

Part- C

26. 1+1+
a) 1

© Kips Learning Pvt. Ltd 2023


What will be the output of the following statement?

SELECT *
FROM foods
NATURAL JOIN company;

b)
Twinkle is using a table EMPLOYEE. It has the following columns:

ps
Code, Name, Salary, Dept code. She wants to display maximum salary Department wise.
She wrote the following command:

SELECT Dept code, Max(Salary)


FROM EMPLOYEE:

But she did not get the desired result.


Rewrite the above query with necessary change to help her get the desired output.

c) What is the purpose of DDL Language?


Ki
Ans a)

COMPANY_ID ITEM_ID ITEM_NAME ITEM_UNIT COMPANY_NAME COMPANY_CITY


---------- ---------- ------------------------- ---------- ------------------------- --------------
16 1 Chex Mix Pcs Akas Foods Delhi
15 6 Cheez-It Pcs Jack Hill Ltd London
15 2 BN Biscuit Pcs Jack Hill Ltd London
17 3 Mighty Munch Pcs Foodies. London
15 4 Pot Rice Pcs Jack Hill Ltd London
18 5 Jaffa Cakes Pcs Order All Boston

b)

SELECT Deptcode, Max(Salary)


FROM EMPLOYEE GROUP BY Deptcode;

c)
DDL stands for Data definition language. It is the subset of a database that defines the data
structure of the database when the database is created. For example, we can use the DDL

© Kips Learning Pvt. Ltd 2023


commands to add, remove, or modify tables. It consists of the following commands: CREATE,
ALTER, and DELETE database objects, such as schema, tables, indexes, view, sequence, etc.

27. Write a function in Python to count and display the total number of words in a text file. 3
OR/
Write a function display_words() in Python to read lines from a text file "poem.txt", and display
those words, which are less than 4 characters.

Ans def count_words():


file = open("test.txt","r")
count = 0
data = file.read()
words = data.split()
for word in words:
count += 1
print("Total words are",count)
file.close()
count_words()

OR

ps
def display_words():
file = open("poem.txt","r")
data = file.read()
words = data.split()
for word in words:
if len(word) < 4:
print(word, end=" ")
file.close()
display_words()
Ki
28. a) Write SQL queries for (i) to (iv), which are based on the following tables. 3

TABLE : ACCOUNT

TABLE : TRANSACT

i. To display the details of all the transactions of TYPE Deposit from Table TRANSACT.

© Kips Learning Pvt. Ltd 2023


ii. To display the ANO and AMOUNT of all Deposits and Withdrawals done in the month
of October 2017 from table TRANSACT.
iii. To display the last date of transaction (DOT) from the table TRANSACT for the
Accounts having ANO as 103.
iv. To display all ANO, ANAME and DOT of those persons from tables ACCOUNT and
TRANSACT who have done transactions less than or equal to 3000.

b) Differentiate between DELETE and DROP table commands.

Ans
a)
1. SELECT * FROM TRANSACT WHERE TYPE = 'Deposit ';
2. SELECT ANO,AMOUNT FROM TRANSACT
WHERE DOT >= '2017-10-01' AND DOT <= '2017-10-31' ;
OR
SELECT ANO,AMOUNT FROM TRANSACT WHERE DOT BETWEEN '2017-10-01' AND '2017-
10-31' ;
3. SELECT MAX(DOT) FROM TRANSACT WHERE ANO = 103;
4. SELECT ACCOUNT.ANO,ANAME,DOT FROM ACCOUNT,TRANSACT
WHERE ACCOUNT.ANO=TRANSACT.ANO AND AMOUNT <=3000;

b)
ps OR
SELECT A.ANO,ANAME,DOT FROM ACCOUNT A,TRANSACT T
WHERE A.ANO=T.ANO AND AMOUNT <=3000;

DELETE command is used to remove information from a particular row or rows. If used without
condition, it will delete all the row information, but not the structure of the table. It is a DML
command.
DROP table command is used to remove the entire structure of the table and information. It is a
DDL command.
Ki
29. Write a Python program using the function to accept characters in a list, then find and display 3
vowels present in the list.

Ans # list of alphabets


alphabets = ['a', 'b', 'd', 'e', 'i', 'j', 'o']

# function that filters vowels


def filterVowels(alphabet):
vowels = ['a', 'e', 'i', 'o', 'u']

if(alphabet in vowels):
return True
else:
return False

filteredVowels = filter(filterVowels, alphabets)

print('The filtered vowels are:')


for vowel in filteredVowels:
print(vowel)

© Kips Learning Pvt. Ltd 2023


30. Write a menu-based program to add, delete, and display the record of hostel using list as stack 3
data structure in Python. Record of hostel contains the following fields: Hostel number, Total
Students, and Total Rooms.

OR

Write push(rollno) and pop() method in Python:


a) push(rollno) --add roll number in Stack.
b) pop() --- remove roll number from Stack.

Ans host=[ ]
ch='y'
def push(host):
hn=int(input("Enter hostel number"))
ts=int(input("Enter Total students"))
tr=int(input("Enter total rooms"))
temp=[hn,ts,tr]
host.append(temp)

def pop(host):

ps
if(host==[]):
print("No Record")
else:
print("Deleted Record is :",host.pop())

def display(host):
l=len(host)
print("Hostel Number\tTotal Students\tTotal Rooms")
for i in range(l-1,-1,-1):
print(host[i][0],"\t\t",host[i][1],"\t\t",host[i][2])
Ki
while(ch=='y' or ch=='Y'):
print("1. Add Record\n")
print("2. Delete Record\n")
print("3. Display Record\n")
print("4. Exit")
op=int(input("Enter the Choice"))
if(op==1):
push(host)
elif(op==2):
pop(host)
elif(op==3):
display(host)
elif(op==4):
break
ch=input("Do you want to enter more(Y/N)")

OR

MyStack=[]
def Push(rollno):
MyStack.append(rollno)

© Kips Learning Pvt. Ltd 2023


def Pop(MyStack):
if len(MyStack) > 0:
MyStack.pop()
else:
print("Stack is empty.")

Part- D
31. Western School in Mumbai is starting up the network between its different wings. There are four
buildings, named as SENIOR, JUNIOR, ADMIN, and HOSTEL as shown below:

The distance between various buildings is as follows:

ps
Number of Computers in Each Building:
Ki
a) Suggest the cable layout of connections between the buildings. 1
b) Suggest the most suitable place (i.e., building) to house the server of this school and 1
provide a suitable reason.
c) Suggest the placement of the following devices with justification: 1
• Repeater
• Hub/Switch
d) The organisation also has an inquiry office in another city about 50-60 km away in a hilly 1
region. Suggest the suitable transmission media to interconnect to school and inquiry
office out of the following:
• Fibre optic cable
• Microwave
• Radio waves
e) Suggest a protocol that shall be needed to provide video conferencing solution between
various buildings.

© Kips Learning Pvt. Ltd 2023


Ans a)

b) Server can be placed in the ADMIN building as it has the maximum number of computers.
c) Repeater can be placed between ADMIN and SENIOR building as the distance is more than
110 m. Hub can be placed in each block.
d) Radio waves can be used in hilly regions as they can travel through obstacles.
e) Protocol: VoIP
32. a) Find the output of the following: 2+3

n=5
r = b**p
return r
ps
def calcSquare(a):
a = power(a, 2)
return a
def power (b , p):

result = calcSquare(n)
print(result)
Ki
b) Write the steps to perform an Insert query in database connectivity application.
Table ‘student’ values are rollno, name, age (10,’Raman’,26).

RollNo – integer
Name – string
Age – integer

Note the following to establish connectivity between Python and MYSQL:


• Username is root
• Password is 1234
• The table exists in a MYSQL database, named school.
• The details (RollNo, Name, Class, and Age) are to be accepted from the user.

Write the following missing statements to complete the code:


Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table Student
Statement 3- to add the record permanently in the database

import mysql.connector as mydb


conn= mydb.connect(host=”localhost”, user=”root”, passwd=”1234”)
cur=_____________ #Statement 1

© Kips Learning Pvt. Ltd 2023


cur.execute______________________#Statement 2
_______________________ #Statement 3
print("Data Added successfully")

OR
a) Predict the output of the code given below:

s="PyThontest2"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)

Name – string
Age – integer
ps
b) Write the steps to perform an Insert query in database connectivity application.
Table ‘student’ values are rollno, name, age (10,’Raman’,26)

RollNo – integer

Note the following to establish connectivity between Python and MYSQL:


• Username is root
• Password is 1234
Ki
• The table exists in a MYSQL database named school.
• The details (RollNo, Name, Clas and Age) are to be accepted from the user.

Write the following missing statements to fetch all records of a table Student at run time:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that fetch all records of a table Student .
Statement 3- to fetch all records

import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="
123" ,database="school")
mycursor=_________________________# Statement 1
mycursor._____________________ # Statement 2
myrecords=___________________ # Statement 3
for x in myrecords:
print (x)

Ans a)25
b)
import mysql.connector as mydb

© Kips Learning Pvt. Ltd 2023


conn= mydb.connect(host=”localhost”, user=”root”, passwd=”1234”)
cur=conn.cursor()
cur.execute(“INSERT INTO student values(10,’Ashok’,26);”)
cur.commit()
print("Data Added successfully")

OR

a) pPtHhonEes&
b)
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="
123" ,database="school")
mycursor=mydb.cursor()
mycursor.execute("select * from student")
myrecords=mycursor.fetchall()
for x in myrecords:
print (x)

33.
ps
Write a program to search the record from “data.csv” according to the admission number input
from the user. The structure of record saved in “data.csv” is Adm_no, Name, Class, Section, and
Marks. Also, write a function ADD() to accept and add data of an employee to a CSV file
‘data.csv’. Each record consists of a list with field elements as Adm_no, Name, Class, Section, and
Marks, respectively.

OR

a) Give any one point of difference between a binary file and a csv file.
5

b) Write a program to show the details of the student who scored the highest marks. Data
Ki
stored in “Details.csv” is given below:
1, Amit, 87
2, Aman, 98
3, Pooja, 85
4, Sandhya, 80

Ans import csv


f = open("data.csv",'r')
d=csv.reader(f)
next(f) #To Skip Header Row
k = 0
adm = int(input("Enter admission number"))

for row in d:

if int(row[0])==adm:

print("Adm no = ", row[0])

print("Name = ", row[1])

print("Class = ", row[2])

© Kips Learning Pvt. Ltd 2023


print("Section = ", row[3])

print("Marks = ", row[4])

break

else:

print("Record Not Found")

import csv
def ADD():
fout=open("data.csv","a",newline="\n")
wr=csv.writer(fout)
adm_no=int(input("Enter Adm number :: "))
name=input("Enter name :: ")
cls=int(input("Enter Class :: "))
sec=input("Enter Section :: ")
mrk=int(input("Enter Marks :: "))
lst=[adm_no,name,cls,sec,mrk]
wr.writerow(lst)

OR
a)
ps
fout.close()

Difference between binary file and csv file:


Binary file:
• Extension is .dat
• Not human readable
• Stores data in the form of 0s and 1s
CSV file
Ki
• Extension is .csv
• Human readable
• Stores data like a text file

b)
import csv
f=open("details.csv","r")
d=csv.reader(f)
next(f)
max=0
for i in d:

if int(i[2])>max:
max=int(i[2])
f.close()
f=open("data.csv","r")
d=csv.reader(f)
next(f)
for i in d:
if int(i[2])==max:
print(i)
f.close()

© Kips Learning Pvt. Ltd 2023


PART E

3 1. Write SQL queries for (i) to (iv), which are based on the tables Account and Transact. 4
4
.
TABLE : ACCOUNT
34.

TABLE : TRANSACT

ii)

iii)

iv)
ps
i) To display the details of all transactions of TYPE Deposit from Table TRANSACT.
To display the ANO and AMOUNT of all Deposits and Withdrawals done in the month
of October 2017 from table TRANSACT.
To display the last date of transaction (DOT) from the table TRANSACT for the
Accounts having ANO as 103.
To display all ANO, ANAME, and DOT of those persons from tables ACCOUNT and
TRANSACT who have done transactions less than or equal to 3000.
Ki
Ans i) SELECT * FROM TRANSACT WHERE TYPE = 'Deposit ';

ii) SELECT ANO,AMOUNT FROM TRANSACT


WHERE DOT >= '2017-10-01' AND DOT <= '2017-10-31' ;
OR
SELECT ANO,AMOUNT FROM TRANSACT WHERE DOT BETWEEN '2017-10-01' AND '2017-10-31' ;

iii) SELECT MAX(DOT) FROM TRANSACT WHERE ANO = 103;


iv) SELECT ACCOUNT.ANO,ANAME,DOT FROM ACCOUNT,TRANSACT
WHERE ACCOUNT.ANO=TRANSACT.ANO AND AMOUNT <=3000;
OR
SELECT A.ANO,ANAME,DOT FROM ACCOUNT A,TRANSACT T
WHERE A.ANO=T.ANO AND AMOUNT <=3000;
35. Harsh is working on his class project and wrote the following program to write Name and Roll 4
numbers into a binary file. As a Python expert, help him to complete the following code based on
the requirement given above:

import _________________#statement 1
with open ("file.dat", "wb") as ____________#Statement 2:
while True:

© Kips Learning Pvt. Ltd 2023


op = int (input ("Enter 1 to add data, 0 to quit"))
if (op == 1):
name = input ("Enter name : ")
rollno = int (input ("Roll no : "))
____________._______([name,rollno],F1) # statement 3
elif op == 0:
break

1. Which module should be imported in the program? (Statement 1)

2. Choose the appropriate answer to fill in statement 2


a) F1
b) op
c) name
d) rollno

3. Write the appropriate function in statement 3 to load the data.


4. Write the difference between loads() and dumps() function.

Ans 1. pickle / import pickle


2.
3.
4. ps
a) F1
pickle.dump
The dumps() function is called to serialise an object hierarchy. Whereas, the
loads()function is called to de-serialise a data stream.
Ki

© Kips Learning Pvt. Ltd 2023

You might also like