CS Answers - 2019-20 - SET1
CS Answers - 2019-20 - SET1
GENERAL INSTRUCTIONS
PART A
Q1 a) Identify and write the name of the module to which the following functions belong: 1
i) ceil()
ii) match()
Ans. i) ceil() – math module
ii) match() – re module
d) Rewrite the following code in python after removing all syntax error(s). Underline each 2
correction done in the code.
x=int(“Enter value for x:”))
for y in range[0,11]:
if x=y:
print(x+y)
else:
Print(x-y)
Page 1 of 12
e) Find the output of the following code: 2
def CALLME(n1=1, n2=2):
n1=n1*n2
n2+=2
print(n1, n2)
CALLME()
CALLME(2,1)
CALLME(3)
Ans. 2 4
2 3
6 4
Ans: wORKAISAwORSHIP
g) Observe the following program and answer the questions that follow: 2
import random
import random
x=3
n = random.randint(1,x)
for i in range(n):
print(i, '#', i+1)
i) What is the minimum and maximum number of times the loop will execute?
ii) Find out, which line of output(s) out of (i) to (iv) will not be expected from
the program?
i. 0#1 ii. 1#2 iii. 2#3 iv. 3#4
Page 2 of 12
b) What is the output of the following program: 1
def myfunc(a):
a = L + [2]
for i in range(0,len(L)):
L[i]=L[i]*2
return sum(L)
L=[4,8,9]
print(myfunc(L))
Ans: 42
c) Reorder the following efficiencies from the smallest to the largest: 1
i) 2n ii) n! iii) n5 iv) 10,000 v) nlog2(n)
d) Write a function remove_lowercase( ) that accepts two file names, and copies all lines that 2
do not start with a lowercase letter from the first file into the second.
Ans:
def remove_lowercase(infile, outfile) :
print(infile,outfile)
output = open(outfile, "w+")
for line in open(infile) :
if not line[0] in "abcdefghijklmnopqrstuvwxyz" :
output.write(line)
output.close()
#Main function
f1 = input("Enter first file name:")
f2 = input("Enter second file name:")
remove_lowercase(f1,f2)
# main function
n = int(input("Enter the number : "))
Page 3 of 12
res = compute(n)
print("The sum of the series from 1..",n," is :",res)
OR
Write a python function to search for a value in the given list using binary search method.
Function should receive the list and value to be searched as arguments and return index if
the value is found -1 otherwise
Ans:
#Binary Search
def BS(l,ll,ul,s):
if ll > ul:
return -1
else:
m = (ll + ul)//2 #ll + (ul - ll) //2
if l[m] > s:
return BS(l,ll,m-1, s)
elif l[m] < s:
return BS(l, m+1, ul,s)
else:
return m
def main():
lst = eval(input("Enter the list :"))
se = int(input("Enter the search element:"))
#lst.sort()
p = BS(lst,0,len(lst)-1,se)
if p < 0 :
print("Not found")
else:
print("Found at ", p)
main()
def isEmpty(stk):
if stk == []:
return True
else:
return False
def Push(stk,item):
stk.append(item)
top = len(stk) - 1
Page 4 of 12
def Pop(stk):
if isEmpty(stk):
print("Stack empty")
else:
top = len(stk) - 1
del stk[top]
def Display(stk):
if isEmpty(stk):
print("Stack empty")
else:
top = len(stk) - 1
print(stk[top])
for a in range(top-1,-1,-1):
print(stk[a])
# __main__
Stack = []
top = None
while True:
print("STACK OPERATIONS :")
print("1. PUSH")
print("2. POP")
print("3. EXIT")
ch = int(input("Enter your choice (1 - 5) :"))
if ch == 1:
pin = int(input("Enter city pincode to be inserted :"))
cname = input("Enter city name to be inserted :")
item = [pin,cname]
Push(Stack,item)
Display(Stack)
elif ch == 2:
Pop(Stack)
Display(Stack)
elif ch == 3:
break
else:
print("Invalid Choice")
OR
Ans:
def InsertItem(queue,item):
queue.append(item)
def DeleteItem(queue):
if (queue==[]):
print("Queue empty")
Page 5 of 12
else:
print("Deleted element is: ",queue[0])
del queue[0]
#Calling function
que = []
cont = True
while cont == True:
print("Enter 1 to add a member :")
print("Enter 2 to delete a member :")
ch = int(input("Enter your choice :"))
if ch == 1:
print("For the new member, enter details below:")
mNo = int(input("Enter member no :"))
mName = input("Enter member name :")
mAge = int(input("Enter member's age :"))
ele = [mNo,mName,mAge]
InsertItem(que,ele)
else:
DeleteItem(que)
print("The updated list is :", que)
c = input("Do you want to continue... (Y/N)? ")
if c.upper( ) == 'N':
cont = False
h) Evaluate the following postfix expression using a stack and show the contents of 2
stack after execution of each operation:
120, 45, 20, +, 25, 15, -, +, *
Ans: 9000
Element Stack Contents
120 120
45 120, 45
20 120, 45, 20
+ 120, 65
25 120, 65, 25
15 120, 65, 25, 15
- 120, 65, 10
+ 120, 75
* 9000
i) Write a Python code to plot the below graph: 3
Page 6 of 12
Ans : import matplotlib.pyplot as plt
import numpy as np
p = np.array([1,2,3,4])
plt.bar(p, p**2, width = 0.3, label = 'Range1')
plt.bar(p+0.3, p*2, width = 0.3, label = 'Range2')
plt.legend(loc='upper left')
plt.show()
OR
Ans:
PART B
Q3 a) _______________ is a device that links two networks together and can handle 1
networks that follow same protocols.
Ans: A bridge
b) Sum of data bits calculated from digital data that is used to ensure the data 1
integrity at the receiver‟s end is called ___________
Ans: CheckSum
Ans: IoT is a phenomenon that connects smart devices to the Internet over wired
or wireless connections.
Page 7 of 12
e) Write the expanded forms of the following abbreviated terms used in networking and 2
communications:
i) SMTP
ii) POP
iii) GSM
iv) DNS
Ans:
i) SMTP - Simple Mail Transfer Protocol
ii) POP - Post Office Protocal
iii) GSM - Global System for Mobile
iv) DNS - Domain Name System
Ans: In a computer network, collision is a specific condition that occurs when two
or more nodes on a network transmit data at the same time. In case of a collision,
the data gets garble and cannot be read.
The wireless networks employ a protocol called CSMA/CA (Carrier Sense
Multiple with Collision Avoidance) to avoid collisions in the network.
h) Hi-Standard Tech Training Ltd is a Mumbai based organization which is expanding its office 4
set- up to Chennai. At Chennai office compound, they are planning to have 3 different blocks
for Admin, Training and Accounts related activities. Each block has a number of computers,
which are required to be connected in a network for communication, data and resource sharing.
As a network consultant you have to suggest the best network related solution for the
queries (i) to (iv) as per the distances between various blocks and other given parameters.
Chennai Office
Mumbai
Admin Accounts
Block Head Office
Block
Training
Block
Page 8 of 12
Distances between various Blocks are as follows:
Admin to Accounts 300 m
Accounts to Training 150 m
Admin to Training 200 m
Mumbai Head office to Chennai 1300 km
Office
Number of Computers
Accounts 30
Training 150
Admin 40
i) Suggest the most appropriate block to house the server in the Chennai office.
Justify your answer.
ii) Suggest the best wired medium and draw the cable layout to efficiently connect
various blocks within the Chennai office compound.
iii) Suggest the device/software and its placement that would provide data security to
the entire network of the Chennai office.
iv) Suggest a device and the protocol that shall be needed to provide wireless Internet
access to all Smartphone / laptop users in the Chennai office.
Ans:
(i) Training Block is the most appropriate location to house the server as it has the
maximum number of computers.
(ii)
Admin Accounts
Block
Block
Training
Block
(iii) Suggested device is firewall. It will be placed where all messages are
entering or leaving the entire network.
(iv) Device: WiFi card Protocol: TCP/IP
PART C
Q4 a) Ms Krupa has created a table „Employee‟ that has 8 rows and 5columns. She deleted 3 1
rows and added 2 more columns. What is the Cardinality and Degree of the resulting
table?
Ans: Cardinality : 6
Degree : 7
Page 9 of 12
b) Is NULL value the same as 0? Give the reason 1
Ans: No. NULL value specifies a legal empty value whereas 0 is a number having the
value Zero.
c) i) Which SQL function is used to count the number of unique elements in a column of 1
a table?
ii) Which SQL command is used to put a condition in a GROUP BY clause?
Ans:
i) COUNT(DISTINCT Columnname)
ii) HAVING
d) Ramesh wants to write a python script to connect to MySQL database with the credentials: 2
Server: „localhost‟
User Name: „Ramesh‟
Password: „Pass123‟
Database: „School‟
i) Write a python statement for him to connect to the MySQL server with the given
details.
ii) Write a python statement to create a cursor object named „ncursor‟
Ans:
i) con = mysql.connector.connect(host=‟localhost‟, user=‟Ramesh‟,
passwd=‟Passq123‟, database=School‟)
ii) ncursor = con.cursor()
f) Write a view function that can process a GET request and display “main.html” as 2
template. Required file(s) and method(s) are already imported.
Page 10 of 12
Ans:
i) SELECT Watchid, Watch_Name WHERE Watch_Name LIKE „%Time‟
ii) SELECT * FROM WATCHES ORDER BY Price DESC;
iii) DELETE FROM Watches WHERE Type = „Unisex‟;
iv) UPDATE Watches SET Price = Price + Price * 0.1 WHERE Qty_Store < 150;
Ans :
i)
DISTINCT(Type)
Unisex
Ladies
Gents
ii)
Watch_Name Price Qty_Store
LifeTime 15000 150
Wave 20000 200
HighFashion 7000 250
iii)
AVG(Price)
8500
15000
225000
PART D
Q5 a) ___________________ is stealing someone else‟s intellectual work and representing 1
it as your own work without giving credits.
Ans: Plagiarism
b) Which out of the following does not come under Cyber Crime? 1
i) Copying data from the social networking account of a person without his/her
information & consent.
ii) Deleting some files, images, videos, etc. from a friend‟s computer with his consent.
iii) Viewing & transferring funds digitally from a person‟s bank account without
his/her knowledge.
iv) Intentionally making a false account on the name of a celebrity on a social
networking site.
Ans : ii)
c) Define the terms: 2
i) Computer forensic
ii) Identity theft
Page 11 of 12
Ans :
i) Computer forensic – refers to methods used for interpretation of computer media
for digital evidence.
ii) Identity theft – Online identity theft is the theft of personal information in order to
commit fraud.
d) Discuss Gender issues that you see in the field of computer studies 2
Ans: The major gender issues at school level computer science education are:
i) Under representation – the reasons are; Preconceived notations like boys are better
at technical things and girls in humanities, Lack of interest, Lack of motivation, Lack
of role models and lack of Encouragement in class.
ii) Non Girl-friendly Work Culture – Boys prefer to work with boys, Boys are not
comfortable in situations where they are not playing active roles, problems faced by
girls like „insufficient access time‟, „difficulty in maintenance‟ etc.
Page 12 of 12