PRE BOARD EXAM I SOLUTION - COMPUTER SCIENCE
PRE BOARD EXAM I SOLUTION - COMPUTER SCIENCE
PRE BOARD EXAM I SOLUTION - COMPUTER SCIENCE
Section A
1.
False
Explanation:
False, output 2**2**3 is 256 and (2**2)**3 is 64
2.
(b) Cardinality
Explanation:
Cardinality
3.
(c) [[3,6,9],[4,8,12],[5,10,15]]
Explanation:
The above code generates a list of lists each for an integer values between the values
specified in the range function inclusive the lower limit.
4. (a) he
Explanation:
str[:2] prints only the values at index 0 and 1 (as 2 is exclusive) of string and hence the
answer is “he”.
5. [1.0, 4.0, 1.0]
6. False
Explanation:
False
7. (a) fout = open("c:\\pat.txt", "wb")
Explanation:
fout = open("c:\\pat.txt", "wb")
8.
(b) MySQL.connector library
Explanation:
MySQL.connector library
9.
(b) All of these
r----------------------------------------------------------~
Explanation:
All the group functions ignore NULL values.
10. i. read() method will read all the contents of the file poem.txt.
ii. read(100) will only read the first 100 bytes of the file poem.txt.
11. True
Explanation:
True
12.
(c) LIFO
Explanation:
LIFO (last in first out) is a form of access is used to add/remove nodes from a stack.
13. AND, OR, NOT
14. (a) Circuit
Explanation:
Circuit
15. (d) Relations
16.
(b) Drop
Explanation:
Drop
17. (b) None
Explanation:
When no value is returned by function in Python, it returns None object by default.
18.
(d) peer
Explanation:
peer
19.
(b) Both A and R are true but R is not the correct explanation of A.
r----------------------------------------------------------~
Explanation:
We can say that break is used to abort the current execution of the program and the control
goes to the next line after the loop. break is commonly used in the cases where we need to
break the loop for a given condition.
20.
(c) A is true but R is false.
Explanation:
We can use DictReader() function to read the csv file directly into a dictionary rather than
deal with a list of individual string, not integer elements. In Python, the csv. reader()
module is used to read the csv file.
21.
(b) Both A and R are true but R is not the correct explanation of A.
Explanation:
In large projects, sometimes we may not know the number of arguments to be passed in
advance. In such cases, Python allows us to offer the comma-separated values which are
internally treated as tuples at the function call. By using the variable-length arguments, we
can pass any number of arguments. Special symbols are used for passing arguments: *args
for Non-Keyword Arguments and **kwargs for Keyword Arguments.
Section B
22. The wireless networks employ a protocol called CSMA/CA (Carrier Sense Multiple
Access with Collision Avoidance) to avoid collisions in the network.
It is a multiple access method in which the carrier is sensed first and a node attempts to
avoid collisions by transmitting only when it senses that the carrier is idle i.e., no other
node is transmitting data.
Wireless networks use CSMA/CA as they cannot detect collisions; hence they avoid it.
23. import mysql.connector
mycon=mysql.connector.connect(host="localhost",user="root",passwd="system",database
=”student.db”)
cursor = mycon.cursor()
sql="SELECT * FROM Traders WHERE City = 'Mumbai' OR City = 'Delhi'
try:
cursor.execute(sql)
dis = cursor.fetchall()
for i in disp:
print (i)
except:
mycon.rollback()
r----------------------------------------------------------~
mycon.close()
26. The above code will produce an error as x is an integer and is used in place of a
sequence or iterable in a for loop; hence the error integer values cannot be used as
iterable.
OR
for i in range(3,5)
if(i==4):
print("Welcome")
else:
print("No entry")
print("value of i",i)
r----------------------------------------------------------~
27. The seek() method moves the current file pointer position to the specified position.
Syntax: (offset [, from_what]). The offset argument indicates the number of bytes to be
moved. The from_what argument specifies the reference position from where the bytes are
to be moved. The values for from_what argument can be
0 (beginning of the file); default value,
1 (current position of the pointer) or
2 (end of the file).
OR
def countchar():
filename = "PARA.txt"
count = 0
c = input("Enter the character to search for:")
with open(fname, 'r') as file_obj:
for line in f:
for word in line:
for char in word:
if char.strip() == c.strip(): #remove spaces
count=count + 1
print("No. of occurrences of", c , "=", count)
countchr()
function returns the occurrence of the character entered by the user in the "PARA.txt file.
28. def prinDict(D, num):
for a in D:
if D[a] > num:
print(a, ":", D[a], end = " ")
print()
D1 = {'a':23, 'b':12, 'c':22, 'd': 17}
prinDict(D1, 17)
Section C
29. from bisect import bisect
def listfunc(sortedlist,number):
r----------------------------------------------------------~
insert_point = bisect(sortedlist, number)
sortedlist.insert(insert_point,number)
print ("List after Insertion")
print (sortedlist)
sortedlist.remove(number)
print ("List after Deletion")
print (sortedlist)
maxrange = int(input("Enter Count of numbers: "))
numlist=[]
for i in range(0,maxrange):
numlist.append(input("?"))
numlist.sort()
number = input("Enter the number to insert")
listfunc(numlist,number)
OR
The differences between a local variable and a global variable are as given
below :
Local Variable Global Variable
1. It is a variable which is declared within 1. It is a variable which is declared
a function or within a block outside all the functions
2. It is accessible only within a 2. It is accessible throughout the
function/block in which it is declared Program
3.Local variables are created when the 3.Global variable is created as execution
function has started execution and are starts and is lost when the program
lost when the function terminates. ends.
For example, in the following code, x, xCubed are global variables and n and cn are
local variables.
def cube(n):
cn = n * n * n
return cn
x = 10
xCubed = cube(x)
print(x, "cubed is", xCubed)
30. output
i. 5
ii. 13
iii. 53000
r----------------------------------------------------------~
OR
i. a. Oracle
b. SQL Server
c. MySQL
d. Microsoft Access
ii. Null value signifies a legal empty value. It is different from a zero value
iii. 8
31. def prime(n) :
for i in range (2, n):
for j in range (2, i):
if i%j= = 0:
break
else:
print a
OR
def appendTuple(tuple1, tuple2):
"""This function will join two tuples into one"""
tuple3 = tuple1 + tuple2
return tuple3
Section D
OR
MAX_SIZE = 1000
stack = [0 for i in range(MAX_SIZE)]
top = 0
def isEmpty ( ):
global top
return top == 0
def push(x):
global stack,top
if top >= MAX_SIZE:
return stack[top]= x
top += 1
def pop( ):
global stack,top
if isEmpty( ):
return
else:
top -= 1
return stack[top]
string = input( ).split()
for i in string:
push(i)
while not isEmpty( ):
x = pop( )
print (x + x, end = ' ')
r----------------------------------------------------------~
33. CSV files
can be viewed in spreadsheets
module CSV has to be imported
Text files
can be viewed in the text editor
No specific module required to be imported
import csv
def COURIER_ADD() :
f1=open("courier.csv","a",newline="\n")
writ=csv.writer(f1)
cid=int(input("Enter the Courier id"))
s_name=input ("Enter the Sender Name")
Source=input("Enter the Source Address")
destination=input("Enter Destination Name")
detail=[cid,s_name,Source,destination]
writ.writerow (detail)
f1.close()
def COURIER_SEARCH() :
f1=open("courier.csv","r") # ignore newline
detail=csv.reader(f1)
name=input("Enter the Destination Name to be searched")
for i in detail :
if i[3]==name:
print("Details of courier are: ",i)
COURIER_ADD()
COURIER_SEARCH()
r----------------------------------------------------------~
34. a. Primary Key is a unique and non-null key, which is used to identify a tuple uniquely. If
a table has more than one such attributes which identify a tuple uniquely than all such
attributes are known as candidate keys.
b. i. SELECT GameName, GCode FROM GAMES;
ii. SELECT * FROM Games WHERE PrizeMoney > 7000;
iii. SELECT * FROM Games ORDER BY ScheduleDate;
iv. SELECT Type, SUM(Prizemoney) FROM Games GROUP BY Type;
c. i. 2
ii. 19-Mar-2004 12-Dec-2003
iii. Ravi Sahai Lawn Tennis
iv. 101
108
103
OR
i. SELECT * FROM INTERIORS WHERE TYPE='Sofa';
ii. SELECT ITEMNAME FROM INTERIORS WHERE PRICE > 10000;
iii. SELECT ITEMNAME, TYPE FROM INTERIORS WHERE DATEOFSTOCK
<'22/01/02' ORDER BY ITEMNAME DESC;
iv. INSERT INTO INTERIORS VALUES (14,'True lndian', 'Office Table',
'25/03/03',15000,20);
v. SELECT ITEMNAME, PRICE FROM INTERIORS WHRE DISCOUNT>20;
35. i. import mysql.connector
mycon=mysql.connector.connect(host="localhost",user="Admin",passwd="Admin@12)
cursor = mycon.cursor()
try:
cursor.execute("UPDATE Club SET Address = 'Noida' WHERE Memberld='M003'")
mycon.commit()
except:
mycon.rollback()
mycon.close()
Section E
36. i. The server should be Dedicated server
ii. The most suitable place to house the server is Science Block as it has the maximum
number of computers. Thus, reducing the cabling cost and increase the efficiency of the
network.
iii. SWITCH
iv. Satellite Connection Or Leased line
37. i. SELECT CNO, CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO DESC;
ii. SELECT CNAME FROM TRAVEL WHERE VCODE = 'VO1' OR VCODE = 'V02'
iii. SELECT CNO, CNAME from TRAVEL WHERE TRAVELDATE BETWEEN '2015-
05-01' AND '2015-12-31'
OR
SELECT CNO, CNAME from TRAVEL WHERE TRAVELDATE > = '2015-05-01'
AND TRAVELDATE < = '2015-12-31'
iv. SELECT * FROM TRAVEL WHERE KM > 120 ORDER BY NOP;
v. COUNT(*) VCODE
2 V01
2 V02
vi. DISTINCT VCODE
V01
V02
V03
V04
V05
v. 2 101
1 103
2 102
1 104
1 105
vi. 103
104
105