Unit Test2 Solns
Unit Test2 Solns
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
(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
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
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
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’)