Computer Sci
Computer Sci
91
1!11 .
" .
GJ =·=
6 · · Which of the following mode keeps the file offset position at the end of the
file? 1
(a) r+ (b) r
(c) w (d) a
1
10. Fill in the blank.
_ is a number of tuples in a relation.
(a) Attribute (b) Degree
(c) Domain (d) Cardinality
1
11. The syntax of seek() is :
file object.seek(offset[,reference_point])
Whatis the default value of reference _point ?
(a) 0 (b) 1
(c) 2 (d) 3
1
12. Fill in the blank : ,
___ clause is used with SELEC'r statement to display data in a sorted
form with respect to a specified column.
(a) WHERE (b) ORDER BY
(c) HAVING (d) DISTINCT
91 <D 1!11
.
Iii :,:
P.T.O.
13. Fi!! in the blank. icast communication l
.
18 .. ·cation or un
--- used for point-to-point commum
such as radar and satellite. TOOTH
(a) INFRARED WAVES (b) BLUE S
(c) MICROWAVES (d) RA DIOWAVE
14
"nat Will
· n,,_ .
the following expression be evaluated to in Python
. ?
l
Pri~t(4+3*5/3-5%2)
(a) 8. 5
(b) 8. 0
(c) 10. 2
(d) 10.0
15
- Which function returns the sum of all elements of a liS t ?
(a) count() (b) sum()
I
(c) total () (d) add ()
16. fetchallO method fetches all rows in a result set and returns a:
1
(a) Tuple of lists (b) List ·of tuples
(c) List of strings (d) Tuple of strings
91
SECTION-B
19. Atharva. is .a Python programmer working on a program to find and ret~rn
the maxunum value from the list. The code written below·has syntactical
errors. R~write the correct code and underline the corrections made. 2
def max_num (L) :
max=L(0)
for a in L:
·if a > max
.max=a
return max
20. (a) · Differentiate between wired and wireless transmission. 2
OR
(b) · Differentiate between URL and domain name with the help of an f2
appropriate example.
21. (a) G~ven is a Python list declaration: ·1
Listofnames=["Aman","Ankit","Ashish","Rajan","Rajat"]
Write the output of:
print (Listofnaines [-1,: - •4: -;1,])
(b) Consider the following tuple declaration : 1
tupl=(l0,20,30, (10,20,30) ,40)
Write the output of ~
print(tupl.index(20))
22. ·Explain · the concept of "Alternate ' Key" ·in a Relational Database
Management System with an appropriate example. 2
l .. .' ,' , i' ;
25. (a) Differentiate between CHAR and VARCHAR data types in SQL with
appropriate example. 2
OR
(b) Name any two DDL and any two DML commands. 2
SECTION-C
26. (a) Consider the following tables - LOAN and BORROWER : 1+2
Table: LOAN
LOAN NO B NAME AMOUNT
L-170 DELHI 3000
L-230 KANPUR 4000
Table : BORROWER
CUST NAME LOAN NO
JOHN L-171
KRISH L-230
RAVYA L-170
How many rows and columns will be there in the natural j'oin of
these two tables ?
91 [!]I
...
Iii :,:
l
(b) Write the output of the queries (i) to (iv) based on the table,
WORKER given below :
TABLE· WORKER
W ID F NAME L NAME CITY STATE
102 SAHIL KHAN KANPUR UTTAR
PRADESH
104 SAMEER PARIKH ROOPNAGAR PUNJAB
105 MARY JONES DELHI 'DELHI
106 MAHIR SHARMA SONIPAT HARYANA
107 ATHARVA BHARDWAJ DELHI DELHI
108 VEDA SHARMA KANPUR UTTAR
PRADESH
(i) SELECT F~NAME, CITY FROM WORKER ORDER BY STATE
DESC;
(ii) SELECT DISTINCT (CITY) FROM WORKER;
(iii) SELECT F_NAME, STATE FROM WORKER WHERE · L NAME
LIKE I - HA% I ;
(iv) SELECT CITY, COUNT ( *) FROM WORKER GROUP BY CITY f
91 C0 l!]I
...
Ii] :,:
P.T.O.
(b) Write a function count Dwords () in Python to count the words
e nding with a digit in a t;xt file "Details. txt". 3
Example:
If the file content is as follows:
On seat2 VIP1 wiil sit and
On seatl VVI~2 will be sitting
Output will be: ,
Number of words ending with a digit are 4
28 · (a) Write the outputs of the SQL queries (i) to (iv) based on the relations
. COMPUTER and SALES given below : . · 2
Table : COMPUTER
PROD_ID PROD NAME PRiCE COMPANY TYPE
P00l MOUSE 200 LOGITECH INPUT
P002 LASER PRINTER 4000 CANON OUTPUT
P003 KEYBOARD 500 LOGITECH INPUT
P004 JOYSTICK 1000 IBALL INPUT
P005 SPEAKER 1200 CREATIVE OUTPUT
P006 DESKJET PRINTER 4300 CANON OUTPUT
Table : SALES
PROD_ID QTY_SOLD QUART~R
P002 4 1
P003 2 2
P00l 3 2
P004 2 1
(i) SELECT MIN (PRICE), MAX (PRICE) FROM COMPUTER;
(ii) SELECT COMPANY, CO{,JNT ( *) FROM COMPUT~R GROUP BY
COMPANY HAVING COUNT (COMPANY) . > 1;
(iii) SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C, SALES
S WHERE C.PROD_ID=S.PROD_ID AND TYPE= 'INPUT';
(iv) SELECT PROD NAME, COMPANY, QUJi.RTER FROM COMPUTER
C SALES S WHERE C. PROD ID=S. -'PROD ID;
' - . -
(b) Write the command to view all databases. 1
91
1!11
" .
l!I :,:
29. Write a function EOReplace0 in Python which accepts a list L of
numbers. Thereafter, it increments all even ~umbers by 1 and decrements
all odd numbers by 1. 3
Example:
If Sample Input data of the list is :
L=[l0,20,30,40,35,55]
Output will be :
L=[ll,21,31,41,34,54]
91
l!ll
" .
:,:
P.T.O.
SECTION-D
3 1. Quickd~v, an IT based firm located in Delhi is planning to set up a
1
~etwork for its four branches within a city with its Marketing de~art~ent
m Kanpur. As a network professional, give solutions to the q~e st10~ 8 (i) to
(~), after going through the branches locations and other details which are
given below :
- -
Distance between various branches is as follows :
t t
(ii) sugg~stan ideal layout for connecting all these branches within
Delhi. 1
(iii) Which d · . ·
evice will you suggest that should be placed in each of these
branches to effi1c1ent
. 1y connect
. '. .
all the computers w1'thin these
branches? · 1
(iv) Delhi firm is planning to connect to its Marketing department in
Kanpur which is approximately 300 km away. Which type of network
out of LAN, WAN or MAN will be formed? Justify your answer. 1
(v) SuggeS t a protocol that shall be needed to provide help for
tra~sferring of files between Delhi and Kanpur branch. 1
32. (a) What possible output(s) are expected to be displayed on screen at the
time of execution of the following program :
import random
M=[5,10,15,20,25,30]
for i in range(l,3}:
first=random.randint(2,5)- 1
sec=random.randint(3,6)- 2
third=random.randint(l~4)
print(M[first],M[sec],M[third],sep="#")
(i) 10#25#15 (ii) 5#25#20
20#25#25 25#20#15
(iii) 30#20#20 (iv) 10#15#25# ·
20#25#25 15#20#10# 2
(b) The code given below deletes the record from. the table employee which
contains the following record structure :
E_ code - String
E_ name - String
Sal - I~teger
City - String
Note the following to establish connectivity between Python and MySQL :
• Username is root
• Password is root .
• The table exists in MySQL database named emp, .
• The details (E_c9de,E_name,Sal,City) are the attributes of the
table.
91 1!11
" .
:,:
P.T.O.
Write the following statements to complete the code :
Statement 1 - to import the desired library.
Statement 2 ·- to execute the command that deletes the record with
E code as 'ElOl'.
Statement 3 - to delete the record permanently from th~ database.
mycursor=mydb.cursor( )
# Statement 2
# Statement 3
print ("Record deleted") 3
OR
(a) Predi~t the output of the code given below :
def makenew(mystr):
newstr=""
count=O
for i in mys tr: ·
if count%2!"=0:
newstr=newstr+str(count)
else
if i. lower() :
newstr=newstr+i.upper()
else:
newstr=newstr+i
count+=l
print(newstr)
makenew ( "No@l") 2
91 1!11
" .
I!] :,:
(b ) The code given
· below
employee and d" reads the following records from the table
. isplays l
commg from city 'Delhi': on Y those records who have employees
E_ code . String
E_name . String
Sal - Integer
City - String
Note the following to establish connectivity between Python and
MySQL :-
• Username is root
• Password is root
• The table exiSt s in a MySQL database named emp.
• The details (E_code,E_name,Sal,City) are the attributes
of the table.
Write the following statements to complete the code :
Statement 1- to import the desired library.
Statement 2 - to execute the quecy that fetches records of the employees
coming from city 'Delhi'.
Statemerit 3 - to read the complete data of the query (rows whose city is
Delhi) into the object named details, from the table employee in 3
details==
for i in ditails:
print (i) [!JI
. .
IE :,:
P.T.0.
91
-
33 · (a) Write one difference between CSV and text files. 5
Write a program in Python that defines and calls the following user
defined functions :
(i) COURIER ADD () : It takes the values from the user and adds
the details to a csv file I courier. csv I . Each record consists of
a list with field elements as cid, s name, Source,
destination to store Courier ID, Sender name, Source and
destination address respectively.
(ii) COURIER SEARCH () : Takes the destination as the input and
displays ail the courier records going to that destination. •
OR
(b) Why it is important to close a file before exiting?
Write a program in Python that defines and calls the following user
defined functions : 5
(i) Add_Book0 : Takes the details of the books and adds them to a
csv file 'Book.csv'. Each record consists of a list with field
elements as book ID, B name and pub to store book ID, book
name and publish;r respe~tively.
(ii) Search_Book0 : Takes publisher name as input and counts and
displays number of books published by them.
SECTION -E
34. The school has asked their ~state manager Mr. Rahul to maintain the
data of all the labs in a table LAB. Rahul has created a table and entered
data of 5 labs.
LABNO LAB NAME INCHARGE CAPACITY FLOOR
LOOI CHEMISTRY Daisv 20 I
L002 BIOLOGY Venkv 20 II
L003 MATH Preeti 15 I
L004 LANGUAGE - Daisv 36 III
L005 COMPUTER MarvKom 37 II
Based on the data given above answer the following questions :
(i) Identify the columns which can be considered as Candidate keys. 1
(ii) Write the degree and cardinality of the table. 1
(iii) Write the statements to : 2
· (a) Insert a new row with appropriate da~a.
(b) Increase the capacity of all the labs·by 10 students which are on
'I' Floor.
OR
(Option for part (iii) only)
(iii) Write the statements to : ·
(a) Add a constraint PRIMARY KEY to the column LABNO in the table.
(b) Delete the table LAB. 2
91
..lill!JI:,:
35. Shreyas is a pr · •
user defin d fu o~ammer, who has recently been given a task to write a
Cust f . le nction n~~e4 write_bin ( ) to create a binary file called
i e • da t conto, ... ,.... t infi .
( c _no-) , name (c n ..........u.ug
) cus omer
. ormation
. - .customer number
·
( amt) 0 f each customer.
- ame ' quantity (qty), pnce (price) · and amount
The function accept
Thereafte 1't di s customer number, name, quantity and price.
SAVE' J' ~plays the m_essage 'Quantity less than 10 ..... Cannot ·
1 1' quantity entered 1s less than 10. Otherwise the function
cha cu£ ates am~u~t as price quantity and then writes the record in
e orm o~ a list mto the binary file.
import pickle
def write bin() :
bin file= . #Statement 1
while True:
c_no=int(input("enter customer number"))
c_name=input("enter customer name")
qty=int(input("enter qty"))
p ~ice~int(input("enter pricefl))
. if. _ _ _ #Statement 2
print("Quantity less than 10 .. Cannot SAVE")
else:
amt=price * qty
c_detail=[c_no,c name,qty,price,amt]
#Statement 3
ans=input("Do you wish to enter more records y/n~)
if ans.lower()=='n':
#Statement 4
#Statement 5
#Statement 6
(i) Write the correct statement to open a file 'Cust_file.dat' for
writing the data of the customer. 1
(ii) Which statement should Shreyas fill in Statement 2 to check
whether quantity is less than 10. 1
(iii) Which statement should Shreyas fill in Statement 3 to write data to
the binary file and in Statemen,t _4 to ,stop further processing if the
. user does not wish to ente!. more records. 2
OR
(Option for part (iii) only)
(iii) What should Shreyas .f.W. µi Statem~Ilt 5 to close the binary file
named Cust file. dat and in Statement 6 to call ~-function ,to
write data in binary file..? . .·.• 2
91