0% found this document useful (0 votes)
48 views20 pages

Unit Test2 Solns

This document is a Unit Test paper for Class XII Computer Science at Saraswati Vidya Mandir, Rourkela, consisting of 35 questions divided into five sections with varying marks. The questions cover topics such as Python programming, SQL, and database management, including multiple-choice questions, programming tasks, and theoretical explanations. Students are instructed to answer programming questions using Python only.

Uploaded by

r6466932
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views20 pages

Unit Test2 Solns

This document is a Unit Test paper for Class XII Computer Science at Saraswati Vidya Mandir, Rourkela, consisting of 35 questions divided into five sections with varying marks. The questions cover topics such as Python programming, SQL, and database management, including multiple-choice questions, programming tasks, and theoretical explanations. Students are instructed to answer programming questions using Python only.

Uploaded by

r6466932
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

SARASWATI VIDYA MANDIR

ROURKELA
Unit Test-2
Class XII FM.-70
SUB-Computer Science

General Instructions
● This question paper contains 35 questions
● This paper is divided into 5 sections-A,B,C,D,E
● Section-A, consists of 18 questions(1 to 18).Each question carries 1
mark
● Section-B, consists of 7 questions (19 to 25). Each question carries
2 marks
● Section-C, consists of 5 questions (26 to 30). Each question carries
3 marks
● Section-D, consists of 3 questions (31 to 33). Each question carries
5 marks
● Section-E, consists of 2 questions (34 to 35). Each question carries
4 marks.
● All programming questions are to be answered using Python
language only

SECTION-A
Questions 1 to 18 are MCQ of one mark each. [1x18=18]
1. State True or False.
“Variable declaration is implicit in Python.” True [1]
2. Evaluate the following expression and identify the correct answer.
16-(4+2)*5+2**3*4 [1]
a. 54 c. 46
b. 18 d. 32
3. Ramanathan is confused about the SQL constraint to be used to restrict
NULL values in a column, while creating a table. Which constraint
should he use? [1]
a. NOT NULL c. Default
b. Unique d. None of the above
4. The following code is used to increase all the elements of the list ‘lst’ by
the parameter received. Write the missing statement to achieve the
objective. [1]
def Update(n):
for a in range(0,len(lst)):
lst[a]=______________ # missing statement
a. n c. lst[a]+n
b. lst[a].increase(n) d. none of the above
5. What will be the output of the following statement?
print(3-2**2**3+99/11) [1]
a. 244 c. 244.0
b. -244 d. -244.0
6. Select the correct output of the code: - [1]
s=’Python is fun’
l=s.split()
s_new=’-‘.join([l[0].upper(),l[1],l[2].capitalize()])
a. PYTHON-IS-Fun c. PYTHON-is-Fun
b. Python-is-fun d. Python-is-FUN
7. In a table in MySQL database, an attribute of datatype vachar(20) has the
value ‘Keshav’. The attribute B of datatype char(20) has the value
‘Meenakshi’. How many characters are occupied by the attribute A and
attribute B? [1]
a. 20,6 c. 6,20
b. 9,6 d. 6,9
8. Which of the following statement(s) would give an error during the
execution of the following code? [1]
tup=(20,30,40,50,60,70)
print(tup) #statement 1
print(tup[3]+50) #statement 2
print(max(tup)) #statement 3
tup[4]=80 #statement 4

a. #statement1 c. #statement 3
b. #statement2 d. #statement 4
9. Fill in the blank: [1]
In case of ___________ switching, before a communication starts, a
dedicated path is identified between sender and receiver.
a. Circuit c. bus
b. Packet d. ring
10. State True or False: [1]
An exception may be raised even if the program is syntactically correct.
TRUE
11. Fill in the blank:
The modem at the sender’s computer acts as a _______ [1]
a. model c. modulator
b. demodulator d. convertor
12. SELECT statement combined with a ______ clause returns the data
that meets a particular condition.
a. Where c. unique
b. Describe d. null
13. Which of the following is the communication protocol that forms the
backbone of the internet?
a. UDP c. TCP
b. HTTP d. None of the
above
14. ________ is a non-key attribute whose values are derived from the
primary key of some other table.
a. Primary key c. foreign key
b. Candidate key d. alternate key
15. SELECT statement when combined with the ________ clause, returns
records without repetition.
a. DISTINCT c. DESCRIBE
b. UNIQUE d. NULL
16. Which of the following is not a DDL command in SQL?
a. DROP c. CREATE
b. UPDATE d. ALTER
Q. 17 and 18 are assertion (A) and reasoning(R) based questions.
Mark the correct choice as
(A) Both (A) and (R) are true and (R) is the correct explanation of (A)
(B) Both (A) and (R) are true and (R) is not the correct explanation of (A)
(C) (A) is true but (R) is false
(D) (A) is false but (R) is true
17. Assertion(A): CSV is a human readable text file where each line has a
number of fields, separated by comma or some other delimiter
Reason(R): writerow() method is used to write a single row in a
CSV file. B
18. Assertion(A):A binary file in python is used to store collection objects
like lists and dictionaries that can be later retrieved in their original form
using pickle module.
Reason(R): Binary files are just like normal files and can be read
using a text editor like Notepad. C

SECTION-B
[2X7=14]
19. Rahul has written a code to input a number and check whether it is
prime or not. His code is having errors. Rewrite the correct code and
underline the corrections made. [2]
def prime():
n=int(input(‘enter a number to check : :’))
for i in range(2,n//2):
if(n%i=0):
print(‘number is not prime’)
break
else:
print(‘number is prime’)

20. Write two points of difference between circuit switching and packet
switching.
OR
Write two points of difference between Static Web pages and dynamic
web pages. [2]
21. (a). Given is a Python string declaration: [2]
myexam=”@@CBSE Examination2022@@”
Write the output of the following statement:
print(myexam([::-2])
'@20niaiaEEB@'
(b). Write the output of the code given below:
my_dict={‘name’:’Aman’,’age’:26}
my_dict[‘age’]=27
my_dict[‘address’]=’Rajkot’
print(my_dict.items())
dict_items([('name', 'Aman'), ('age', 27), ('address', 'Rajkot')])
22. Explain the use of ‘Foreign key’ in a relational database management
system with an appropriate example. [2]
A foreign key is used to set or represent a relationship between two
relations ( or tables) in a database. Its value is derived from the primary
key attribute of another relation. For example: In the tables TRAINER
and COURSE given below, TID is primary key in TRAINER table but
foreign key in COURSE table.
TRAINER

COURSE

23. Write the full forms of the following: [2]


(a). SMTP: Simple Mail Transfer Protocol
(b). PPP: point to point protocol

24. Predict the output of the following Python code: [2]


def Diff(N1,N2):
if(N1>N2):
return N1-N2
else:
return N2-N1
n=[10,23,14,54,32]
for cnt in range(4,0,-1):
A=n[cnt]
B=n[cnt-1]
print(Diff(A,B),’#’,end=’ ‘)
22#40#9#13#
OR
Predict the output of the following Python code:
tuple1=(11,22,33,44,55,66)
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)
(22,44,66)

25. Differentiate between count() and count(*) functions in SQL with


an example. [2]
COUNT(*) returns the count of all rows in the table, whereas
COUNT () is used with Column_Name passed as argument
and counts the number of non-NULL values in a column that
is given as argument
OR
Categorize the following commands as DDL or DML
INSERT, UPDATE, ALTER, DROP
DML, DML, DDL, DDL
SECTION-C
[3X5=15]
26. (a). Consider the following tables – Bank_Account and Branch [5]
Table: Bank_Account
Acode Name Type
A01 Amrita Savings
A02 Parthodas Current
A03 Miraben Current
Table: Branch
Acode City
A01 Delhi
A02 Mumbai
A03 Nagpur

What will be the output of the following SQL statement?


SELECT * FROM Bank_Account NATURAL JOIN Branch;
Acode Name Type City
A01 Amrita Savings Delhi
A02 Parthodas Current Mumbai
A03 Miraben Current Nagpur

(b). Write the output of the queries (i) to (iv) based on the table,
TECH_COURSE given below:-
CID CNAME FEES STARTDATE TID
C201 Animation & 12000 2022-07-02 101
VFX
C202 CADD 15000 2021-11-15 NULL
C203 DCA 10000 2020-10-01 102
C204 DDTP 9000 2021-09-15 104
C205 Mobile 18000 2022-11-01 101
Application
Development
C206 Digital 16000 2022-07-25 103
Marketing

(i). SELECT DISTINCT TID FROM TECH_COURSE;


C201
C202
C203
C204
C205
C206
(ii). SELECT TID, COUNT(*), MIN(FEES) FROM TECH_COURSE GROUP
BY TID HAVING COUNT(TID)>1;
TID COUNT(TID) MIN(FEES)
101 2 12000

(iii). SELECT CNAME FROM TECH_COURSE WHERE FEES>15000


ORDER BY CNAME;
Digital Marketing
Mobile Application Development
(iv). SELECT AVG(FEES) FROM TECH_COURSE WHERE FEES
BETWEEN 15000 AND 17000;
15500
27. Write a method COUNTLINES() in Python to read lines from text file
“TESTFILE.txt” and display those lines which are not starting with a
vowel. [5]
Example
File content is as follows:-
An apple a day keeps the doctor away.
A marked difference will come in our country.
We all pray for everyone’s safety.
The output should be:-
We all pray for everyone’s safety.
def line(n):
fh=open(n,'r')
lines=fh.readlines()
cw=0
ca=0
for line in lines:
if(line[0]=='A' or line[0]=='E' or line[0]=='I'):
continue
elif(line[0]=='O' or line[0]=='U'):
continue
else:
print(line)
n='TESTFILE1.txt'
line(n)
OR
Write a function ETCount() in Python, which reads each character of the
text file ‘TESTFILE.txt’ and counts as well as displays the occurrence of
alphabets E and T individually(including small cases e and t as well).
Example
File content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on the weather sites.
The ETCount() function should display the output as:
E or e:7
T or t:9

def file_read():
fh=open('hello.txt','r')
fc=fh.read()
print(fc)
e1,t1=0,0
e=['e','E']
t=['t','T']
for i in fc:
if(i in e):
e1+=1
elif(i in t):
t1+=1
print('total occurrences of e or E=',e1)
print('total occurrences of t or T=',t1)

file_read()

28. (a). Write the outputs of the SQL queries (i) to (iv) based on the
relations Teacher and Placement given below:
[5]
Table: Teaching
T_ID Name Age Department Date_of_join Salary Gender
1 Arunan 34 Computer 2019-01-10 12000 M
Science
2 Saman 31 History 2017-03-24 20000 F
3 Randeep 32 Mathematics 2020-12-12 30000 M
4 Samira 35 History 2018-07-01 40000 F
5 Raman 42 Mathematics 2021-08-05 25000 M
6 Shyam 50 History 2019-06-27 30000 M
7 Shiv 44 Computer 2019-02-25 21000 M
Science
8 Shalakha 33 Mathematics 2018-07-31 20000 F
Table: Placement
P_ID Department Place
1 History Ahmedabad
2 Mathematics Jaipur
3 Computer science Nagpur

(i). SELECT Department, avg(Salary) FROM Teacher group by


Department;
Department Avg(salary)
History 35000
Math 25000
Computer science 16500

(ii). SELECT MAX(Date_of_join), MIN(Date_of_join) FROM Teacher;


Max(doj) Min(doj)
2021-08-05 2017-03-24

(iii). SELECT Name, Salary, T.Department, Place FROM Teacher T,


Placement P WHERE T.Department=P.Department AND Salary>20000;
Name Salary T.Department
Randeep 30000 Math
Raman 25000 Math
Samira 30000 History
Shyam 25000 History
Shiv 21000 Comp sci

(iv). SELECT Name, Place FROM Teacher T, Placement P WHERE


Gender=’F’ AND T.Department=P.Department;
NAME PLACE
SAMAN AHMEDABAD
SAMIRA AHMEDABAD
SHALAKHA JAIPUR

(b). Write the command to view all the tables in a database.


SHOW TABLES;
29. Write a function INDEX_LIST(L), where L is the list of elements
passed as argument to function. The function returns another list named
‘indexList’ that contains the indices of all non-Zero elements of L.
Example:
[5]
If L contains [12,4,0,11,0,56]
Then IndexList will have [0,1,3,5]
def index_list(l):
index_list=[]
for i in l:
if(i!=0):
x=l.index(i)
index_list.append(x)
else:
continue
return index_list

l,c,i=[],'y',0
while(c!='n'):
x=int(input('enter list element'))
l.append(x)
i+=1
print('list after ',i,' iterations=',l)
c=input('enter n if you dont want to continue')
print('non zero list',index_list(l))

30. Write a program to display a menu and calculate the area of a circle or
perimeter of a circle according to a user’s choice.
[5]
def area(r):
return 22*r*r/7
def perimeter(r):
return 2*22*r/7
r=int(input('enter radius of circle'))
c=int(input('enter choice 1 for area of circle 2 for perimeter of circle'))
if(c==1):
print(area(r))
else:
print(perimeter(r))

OR
Write a program to take the age of 3 people as input and determine the oldest
and youngest among them.
n=input('enter age of 3 ppl separated by ,')
a,b,c=n.split(',')
print(a,' ',b,' ',c)
a1=int(a)
b1=int(b)
c1=int(c)
if(a1<b1 and b1<c1):
print('minimum is ',a1)
elif(b1<a1 and b1<c1):
print('minimum is ',b1)
elif(c1<b1 and b1<a1):
print('minimum is ',c1)
Section-D
[3X5=15]
31. (i). How is r+ file mode different from rb+ mode?
r+ opens a file for both reading and writing. The file pointer placed at
the beginning of the file.
rb+ opens a file for both reading and writing in binary format. The file
pointer is placed at the beginning
(ii). A binary file has the following structure:
[BookNo, Book_Name, Author, Price]
Write a user defined function CreateFile() to input the data for a
record and add it to Book.dat. [5]
import pickle
def createFile():
fobj=open("Book.dat","ab")
BookNo=int(input("Book Number : "))
Book_name=input("Name :")
Author = input(“Author: “)
Price = int(input("Price : "))
rec=[BookNo,Book_Name,Author,Price]
pickle.dump(rec,fobj)
fobj.close()
OR
Write a function CountRec(Author) in Python which accepts the
Author Name as parameter and counts the number of books by the
given author in the file ‘Book.dat’
def CountRec(Author):
fobj=open("Book.dat","rb")
num = 0
try:
while True:
rec=pickle.load(fobj)
if Author==rec[2]:
num = num + 1
except:
fobj.close()
return numRead
import pickle

def CreateFile():
file = open("Book.dat", "ab")
BookNo = int(input("Enter Book Number: "))
Book_Name = input("Enter Book Name: ")
Author = input("Enter Author Name: ")
Price = float(input("Enter Price: "))
record = [BookNo, Book_Name, Author, Price]
pickle.dump(record, file)
file.close()

def CountRec(authorName):
count = 0
found = False
try:
file = open("Book.dat", "rb")
while True:
record = pickle.load(file)
if record[2] == authorName:
count += 1
found = True

except EOFError:
if found == False:
print("End of file reached. No such records found.")
else:
print("Search successful")
file.close()
return count

CreateFile()
author = input("Enter Author name to count books: ")
print("Number of books by", author, ":", CountRec(author))
32. (i). What do you understand by Candidate Keys in a table?
A candidate key also refers to a set of various attributes (or a
single attribute) that help in uniquely identifying the tuples
available in a table or a relation.
(ii). Consider the tables FACULTY and COURSES with the
following structure:
[5]
FACULTY COURSES
F_ID C_ID
FName F_ID
LName CName
HireDate Fees
Salary
Write a Python code to display the details of those faculty whose
salary is greater than 15000.
Note the following:
Username: Admin
Host: localhost
Password: FacAdm@123
Database: College
33. Sanskar University of Himachal Pradesh is setting up a secured
network for its campus at Himachal Pradesh for operating their
day-to-day office & web based activities. They are planning to have
network connectivity between four buildings. Answer questions (i) to (iv)
after going through the campus & other details given below:

The distance between the various buildings of the university are shown
below:
[5]
Building1 Building2 Distance between buildings (in m)
Main Admin 50
Main Finance 100
Main Academic 70
Admin Finance 50
Finance Academic 70
Admin Academic 60

The number of computers in each building are as follows:


Building Number of computers
Main 150
Admin 75
Finance 50
Academic 60
As a network expert, you are required to give the best possible solutions for
the following queries of the university administration.
(i). Suggest the most suitable building to house the server of the network of
the university: Main building as it houses the maximum number of
computers
(ii). Suggest a suitable cable layout for the connection between the various
buildings
Star topology

(iii). Suggest the placement of the following devices with appropriate


justification:
● Switch/hub
● Repeater
Hub/Switch each would be needed in all the buildings to interconnect the
group of cables from the different computers in each building A repeater
needs to be placed along the wire between main building &
finance building as the distance between them is more than 70 mtr
(iv). Suggest a device/software to be installed in the above campus to take
care of data security.
Firewall
(v). Suggest a protocol needed to provide video conferencing solution
between the Shimla campus of the above university and the Mandi campus of
the above university. VoIP

OR
The university wants to link one of its other offices in a hilly area.
Suggest a suitable transmission media for this case.
Radiowaves can be used in hilly regions as they can travel through
obstacles.
Section-E
[2X4=8]
34. Navdeep creates a table Result with a set of records to maintain the
marks secured by students in Sem 1, Sem 2 & Sem 3 as well as the
division secured by them. He has entered the data of 7 students in the
table:
[4]
Roll_no NAME SEM1 SEM2 SEM3 DIVISION
101 Karan 366 410 402 I
102 Naman 300 350 325 I
103 Isha 400 410 415 I
104 Renu 350 357 415 I
105 Arpit 100 75 178 IV
106 Sabina 100 205 217 II
107 Neelam 470 450 471 I
Based on the data given above answer the following questions:
(i). Identify the most appropriate column that can be considered to be the
primary keyRoll_no
(ii). If 2 columns are added and 2 rows are deleted from the above table, what
will be the new degree and cardinality of the resulting table?
Degree-8
Cardinality-5
(iii). Write the SQL commands to:
(a). Insert the following record into the table.
Roll No – 108, Name – Vignesh, Sem1- 470, Sem2 – 444, Sem3-475, Div- I
INSERT INTO Student VALUES(108,’Vignesh’,470,444,475,’I’);
(b). Increase Sem2 marks of those students by 3% whose name begins with ‘N’
UPDATE Student SET SEM2=SEM2*1.03 WHERE NAME=’N%’;
35. The code given below reads the following record from the table named
Student and displays only those records who have marks greater than
75%
RollNo – integer
Name - string
Class – integer
Marks – integer
Note the following to establish connectivity between Python & MySQL:
● Username: root
● Password: tiger
● Database: school
Write the following missing statements to complete the code:
● Statement1: to form cursor object
● Statement2: to execute the query that extracts the records of those
students with marks greater than 75%
● Statement3: to read the complete result of the query(records of
those students with marks greater than 75%) into the object name
data, from the table Student in the database.
[4]
import mysql.connector as mysql
def sql_data():

con1=mysql.connect(host=”localhost”,user=”root”,password=”tiger”,d
atabase=”school”)
mycursor=con1.cursor()_#statement1
print(“students with marks greater than 75%=”)
mycursor.execute(‘select * from Student where marks>75;’)
#statement2
data=mycursor.fetchall()#statement3
for i in data:
print(i)
print(‘finito’)

You might also like