ComputerScience SQP Set1 MS
ComputerScience SQP Set1 MS
Page: 1/11
12. What will be the output of the following code?
x=3
def myfunc():
global x
x+=2
print(x,end=’ ‘)
print(x,end=’ ‘)
myfunc() (1)
print(x,end=’ ‘)
(a) 3 5 5 (b) 5 5 5 (c) 5 3 5 (d) 3 3 5
Ans: (a) 3 5 5
13. In SQL, what is the use of IS NULL operator? (1)
Ans: IS NULL is a logical operator in SQL that allows you to exclude rows with missing
data from your results.
14. Abhay wants to remove the table STORE from the database MyStore. Which command (1)
will he use from the following:
a) DELETE FROM store; (b) DROP TABLE store;
c) DROP DATABASE mystore; (d) DELETE store FROM mystore;
Ans: (b) DROP TABLE store;
15. Which function is used to display the total number of records/cardinality from table in a (1)
database?
(a) sum(*) (b) total(*) (c) count(*) (d) return(*)
Ans: (c) count(*)
16. Which of the following types of table constraints will prevent the entry of duplicate rows? 1 (1)
(a) Unique (b) Distinct (c) Primary Key (d) NULL
Ans: (b) Distinct
17. Which of the following is NOT a standard Python exception? (1)
(a) KeyError (b) ValueException (c) IndexError (d) TypeError
Ans: (b) ValueException
18. Which transmission media is capable of having a much higher bandwidth (data capacity)? (1)
(a) Coaxial (b) Twisted pair cable (c) Untwisted cable (d) Fiber optic
Ans: (d) Fiber optic
19. Switch is a (1)
(a) Broadcast device (b) Uni-cast device
(c) Multi-cast device (d) None of the above
Ans: (b) Uni-cast device
Q20 and Q21 are Assertion(A) and Reason(R) 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 explanationfor A
(C) A is True but R is False
(D) A is False but R is True
20. Assertion (A): Default parameters are used in Python functions to specify values for (1)
arguments that are not explicitly passed by the caller.
Reasoning (R): This allows the function to have a default behaviour when the caller does
not provide a value for an argument.
Ans: (A)
21. Assertion (A): The BETWEEN operator in SQL is used to match a within a range of
values.
Reasoning (R): The BETWEEN operator can only be used with numerical values in SQL. (1)
Ans: (C) The values can be numbers, text, or dates
Page: 2/11
Section-B ( 7 x 2=14 Marks)
22. What is slicing? Write the output for the following: (2)
Str= “Computer Science”
(i) print(Str[-10:4]) (ii) print(Str[-10:-4])
Ans: (i) not output (ii) er Sci
23. What is an exception in Python? Write suitable example. (2)
Ans: An exception is an unexpected event that occurs during program execution.
Example:
L=['JAVA','PYTHON','C++','ASP','JSP']
try:
print(L[5])
except IndexError as e:
print(e)
24. If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then
(Answer using built in functions only)
(I)
A) Delete 5th position value of the list L2.
OR (2)
B) Empty list L2
(II)
A) Write a statement to insert element 7 in 5th position of List L1
OR
B) Write a statement to reverse the elements of list L1.
Ans: (I) A) L2.pop(5) B) L2.clear( )
(II) A) L1.insert(5,7) B) L1.reverse()
25. What are the possible outcome(s) will get after execution of the following code? (2)
import random
lst=[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
for i in range(3):
print(ord(random.choice(lst))+1,’@’, end= “”)
(a) 102@99@100@ (b) 98@99@98@ (c) 103@100@98 (d) 97@99@101@
Ans: Ans: (a), (b), (c)
26. Write a program to replaces elements having even values with its half and elements having
odd values with twice its value in a list.
eg: if the list contains
3, 4, 5, 16, 9
then rearranged list as
6, 2,10,8, 18
However, there are syntax and logical errors in the code. Rewrite it after removing all
errors. Underline all the corrections made.
Def rearranged(L):
L=[3, 4, 5, 16, 9]
for i in range(n):
if L[i] % 2 == 0:
L[i] =/ 2
else:
L[i] =/ 2
print (L)
Ans:
L=[3, 4, 5, 16, 9]
def rearranged(L):
for i in range(len(L)):
Page: 3/11
if L[i] % 2 == 0:
L[i]/=2
else:
L[i]/= 2
print (L)
rearranged(L)
27. A) List one advantage and one disadvantage of Ring topology.
Ans:
Advantages Disadvantages (2)
No Need for a Server Equipment Connection
OR
B) Expand the term MODEM. What is the use of MODEM?
Ans: The name modem means modulator demodulator. A modem connects our computer to
a standard phone line or to our cable, which allows us to send data or receive data.
28. (i) a) An attribute A of datatype varchar(20) has the value “Amit” . The attribute B of (2)
datatype char(20) has value ”Karanita” . How many characters are occupied in attribute
A ? How many characters are occupied in attribute B?
Ans: 4 characters are occupied in attribute A .
20 characters are occupied in attribute B
OR
b) While creating a table named “Employee”, Mr. Rishi got confused as which data type
he should choose for the column “EName” out of char and varchar. Help him in
choosing the right data type to store employee name. Give valid justification for the
same.
Ans: Varchar would be the suitable data type for EName column as char data type is a
fixed length data type while varchar is a variable length data type. Any employee‟s
name will be of variable length so it‟s advisable to choose varchar over char data
type.
Section-C ( 3 x 3 = 9 Marks)
29. A) A text file contains alphanumeric text (say an.txt). Write a program that reads this text
file and prints only the numbers or digits from the file.
Ans: (3)
fh=open(“python.txt","r")
rec=fh.read();
for a in rec:
if a.isdigit():
print(a,end=' ')
fh.close()
OR
C) Write a function remove_lowercase() that accepts two filenames, and copies all the
lines that do not start with a lowercase letter from the first file into the second.
Ans:
def Remove_Lowercase(input_file, output_file):
input_file = open(input_file, 'r')
output_file = open(output_file, 'w')
for line in input_file:
if line.strip() and line[0].isupper():
output_file.write(line)
input_file.close()
output_file.close()
input_file = 'file1.txt'
output_file = 'file2.txt'
Page: 4/11
Remove_Lowercase(input_file, output_file)
30. A) Julie has created a dictionary containing names and marks as key value pairs of 6
students. Write a program, with separate user defined functions to perform the following
operations:
● Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.
● Pop and display the content of the stack.
For example: If the sample content of the dictionary is as follows:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be: TOM ANU BOB OM
Ans:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
N=[]
def PUSH(R,N): (3)
for i in R:
if R[i]>=75:
N.append(i)
def POP(N):
if N!=[]:
return N.pop()
else:
return None
def TRAVERSE(N):
if len(N)==0:
print("Empty Stack")
else:
for i in range(len(N)-1,-1,-1):
print(N[i])
PUSH(R,N)
TRAVERSE(N)
POP(N)
OR
(B) Write a program to create a Stack for storing only odd numbers out of all the
numbers entered by the user. Display the content of the Stack along with the largest
odd number in the Stack. (Hint. Keep popping out the elements from stack and
maintain the largest element retrieved so far in a variable. Repeat till Stack is empty)
Ans:
n=int(input("Enter the number of values: "))
stack=[]
for i in range(n):
num= int(input("Enter number: "))
if num%2!= 0:
stack.append(num)
largestNum = stack.pop()
while(len(stack)>0):
num= stack.pop()
if num>largestNum:
largestNum=num
print("The largest number found is: ",largestNum)
31. Predict the output of the following code:
def fun(s):
k=len(s)
Page: 5/11
m=" "
for i in range(0,k):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
else: (3)
m=m+'bb'
print(m)
fun('school2@com')
Ans:
SCHOOLbbbbCOM
OR
Predict the output of the following code:
v=50
def display(n):
global v
v=25
if n%7==0:
v=v+n
else:
v=v-n
print(v,end="#")
display(20)
print(v)
Ans: 50#5
Section-D ( 4 x 4 = 16 Marks)
32. Write the characteristics of CSV files. (4)
Write a Program in Python that defines and calls the following user defined functions:
i) APPEND() – To add two records of book to a CSV file „BOOK.csv‟. Each record
consists of a list with field elements as bookid, bname and price to store book id, book name
and book price respectively.
ii) DISP() – To count and display the number of records in the following format. Books
above price 500 :
BookID Bname price
101 Computer Application 450
102 Computer Science 670
105 Informatics Practices 500
Ans:
Ans:
import csv
def APPEND ():
fw=open("Book.csv",'w',newline='')
Book=[]
writer=csv.writer(fw)
writer.writerow(['BookID', 'BName', 'Price'])
for i in range(5):
BookID=input("Book ID : ")
Bname=input("Book Name : ")
price=int(input("Price : "))
data=[BookID,Bname,price]
Book.append(data)
writer.writerows(Book)
fw.close()
def DISP():
Page: 6/11
fr=open("Book.csv",'r')
reader=csv.reader(fr)
print(reader)
count=0
next(reader)
for row in reader:
if int(row[2])>500:
print(row[0],row[1],row[2],sep='\t')
fr.close()
APPEND()
DISP()
33. Consider the tables BOOK and MEMBER Given table:
Table: BOOK
CODE BNAME TYPE
F101 The Priest Fiction
L102 German easy Literature
C101 Tarzan in the lost world Comic
F102 Untold story Fiction
C102 War heroes Comic
TABLE: MEMBER (4)
MNO MNAME CODE ISSUEDATE
M101 Raghav Sinha L102 2016-10-13
M103 Sarthak John F102 2017-02-23
M102 Anisha Khan C101 260-06-12
Write SQL queries for the following:
(i) To display all details from table MEMBER in descending order of ISSUEDATE.
Ans: Selcet * From Member order by Issuedate Desc;
(ii) To display the CODE and BNAME of all Fiction Type books from the table Book.
Ans: Select Code, Bname from Book, Member where Book.Code=Member.Code and
Book.Type= ‘Fiction’;
(iii) To display each Member name and corresponding Bookname.
Ans: Select Mname,Bname fron Member, Book where Book.Code=Member.Code;
(iv) To display Booknames, Member name and issue date for books of type 'Fiction'.
OR
Write the output of the queries (i) to (iv) based on the table, SALES given below:
Page: 7/11
1000000;
Ans:
Name Sales
Y.P.SINGH 1300000
TINHA JAISWAL 1400000
GURDEEP SINGH 1250000
SIMI FAIZAL 1450000
Page: 8/11
database= “company”)
mycur=mydb.cursor()
mycur.execute(“Select * From Emp”)
data=mycur.fetchall()
for row in data:
print(row)
mycur.close()
mydb.close()
Q.No. SECTION E (2 X 5 = 10 Marks) Marks
36. A binary file "Book.dat" has structure [BookNo, Book_Name, Author, Price]. (5)
i. Write a user defined function createFile() to input data for a record and add to Book.dat.
ii. Write a function to increase price 100/- those Book name has ‘Computer Science’.
iii. Write a function countRec(Author) in Python which accepts the Author name as
parameter and count and return number of books by the given Author are stored in the
binary file "Book.dat".
Ans:
import pickle
#Program to write multiple record in binary file
def create():
fw=open("book.dat",'ab')
while True:
BookNo=int(input("Enter Roll No. :"))
Book_Name=input("Enter Name :")
Author=input("Enter Author : ")
Price=int(input("Enter Marks :"))
pickle.dump([BookNo, Book_Name, Author, Price],fw)
ch=input("Add more records? press y/n").lower()
if ch=='n': break
fw.close()
#Program to update record in binary file
def update():
fr=open("book.dat",'rb+')
r=input("Enter Book Name ")
found=False
try:
while True:
cPos=fr.tell()
rec=pickle.load(fr)
if rec[1]==r:
rec[3]=rec[3]+100 #int(input("Enter New Marks :"))
fr.seek(cPos)
pickle.dump(rec,fr)
found=True
except EOFError:
print("")
if found==False:
print("Recod Not found")
fr.close()
37. Bias Methodologies is planning to expand their network in India starting with three cities
in India to build infrastructure for research and development of their chemical products.
The company has planned to setup their main office in Pondicherry at three different
locations and have named their offices as Back Office, Research Lab and Development
Unit. The company has one more research office namely Corporate Unit in Mumbai. A
Page: 9/11
rough layout of the same is as follows:
(5)
In continuation of the above, the company experts have planned to install the following
number of computers in each of these offices.
(i) Suggest the kind of network required (out of LAN, MAN, WAN) for connection each
of the following office unit
(a) Research Lab and Back Office
(b) Research Lab and Development Unit
(ii) Which of the following devices will you suggest for connecting all the computers with
each of their office units?
(a) Switch/Hub (b) Modem (c) Telephone
(iii) Which of the following communication media, will you suggest to be procured by the
company for connecting their local office units in Pondicherry for very effective (high
speed) communications?
(a) Telephone cable (b) Optical fiber (c) Ethernet cable
(iv) Suggest a cable/wiring layout for connecting the company’s local office units located
in Pondicherry. Also, suggest an effective method/technology for connecting the
company’s office located in Mumbai.
(v) Suggest the most appropriate location of the server inside the Pandicharry campus.
Justify your choice.
Ans:
(i) The type of network between the Research Lab and the Back Office is LAN (Local Area
Network). The type of network between Research Lab and Development Unit is MAN
(Metropolitan Area Network).
(ii) The suitable device for connecting all the computers within each of their office units is
switch/hub.
(iii) For connecting the local office units in Pondicherry for very effective (high speed)
communication is optical fiber.
(iv) The cable/wiring layout for connection is as follows:
Page: 10/11
(v) Research Lab
Page: 11/11