PB 1 - ComputerScience MS
PB 1 - ComputerScience MS
SECTION A
Ans. ==
Ans: (a) _a
4. Consider a string S=”ComputerScience”. Which statement out of the following will result in an 1
error:
a. S=S*2
b. S=S+”123”
c. S[0]=”c”
d. S1=S[0:5]
1
5. What will be the output of the following Python code? 1
>>>t = (1, 2, 4, 3, 8, 9)
>>>[t[i] for i in range(0, len(t), 2)]
a) [2, 3, 9]
b) [1, 2, 4, 3, 8, 9]
c) [1, 4, 8]
d) (1, 4, 8)
Ans: c) [1, 4, 8]
6. Which of the following mode in file opening statement results or generates an error if 1
the file does not exist?
Ans: (b) r+
9. Which of the following statement(s) would give an error after executing the following 1
code?
S="Welcome to class XII" # Statement 1 print(S)
# Statement 2 S="Thank you" # Statement 3
S[0]= '@' # Statement 4
S=S+"Thank you" # Statement 5
(a) Statement 3
(b) Statement 4
(c) Statement 5
(d) Statement 4 and 5
Ans: (b) – Statement 4
2
10. Which of the following constraint does not enforce uniqueness? 1
a) UNIQUE
b) Primary key
c) Foreign key
d) None of the mentioned
Answer: c
Explanation: FOREIGN KEY constraints identify and enforce the relationships between
tables.
11. The correct syntax of seek() is:
(a) file_object.seek(offset [, reference_point])
(b) seek(offset [, reference_point])
(c) seek(offset, file_object)
(d) seek.file_object(offset)
Ans: (a) file_object.seek(offset [, reference_point])
12. Mr Riyan from Delhi wants to install some software in his client’s computer who is in Jaipur
through remote login. Which protocol out of the following will be used in this scenario:
A. SMTP
B. FTP
C. PPP
D. Telnet
Ans: d) telnet
Ans: b) gateway
3
16. Which of the following is not a cyber crime: 1
i. Phishing
ii. Identity Theft
iii. Online fraud
iv. Disliking a Social Media post
Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct choice
(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 explanation for A
(c) A is True but R is False
(d) A is false but R is True
17. Assertion (A):- If the arguments in a function call statement match the number and order 1
of arguments as defined in the function definition, such arguments are called positional
arguments.
Reasoning (R):- During a function call, the argument list first contains default argument(s)
followed by positional argument(s).
18. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks 1
like a text file.
Reason (R): The information is organized with one record on each line and each field is
separated by comma.
Ans: (a) Both A and R are true and R is the correct explanation for A
SECTION B
19. Number = 250 2
while Number<=1000:
if Number >= 750:
print (Number)
Number = Number+100
else:
print (Number*2)
Number = Number+50
4
20. A computer virus is malware attached to another program (such as a document), 2
which can replicate and spread after an initial execution on a target system where
human interaction is required.
WORMS
•A computer worm is a standalone malware computer program that replicates itself in
order to spread to other computers.
2 mark for any correct difference.
OR
Star topology is a topology in which all devices are connected to a central hub. Bus
topology is a topology where each device is connected to a single cable which is known
as the backbone. ... Star topology does not have any terminator. Bus topology has a
terminators at both end of the network..
1
Ans: @20 otnmx SC@
22. The PRIMARY KEY constraint uniquely identifies each record in a table. 2
Primary keys must contain UNIQUE values, and cannot contain NULL
values.
A table can have only ONE primary key; and in the table, this primary key
can consist of single or multiple columns (fields).
1 mark for definition 1 mark for example
5
23. 2
(a) Telephone line, Twisted Pair Cable, Coaxial Cable, Fiber Optics
(1 mark for correct answer)
OR
Ans:
DDL- ALTER, DROP
DML – INSERT, UPDATE
def Diff(N1,N2): if
N1>N2:
return N1-N2 else:
return N2-N1
Ans: 22 # 40 # 9 # 13 #
OR
6
Predict the output of the Python code given below:
Ans: (22,44,66)
SECTION C
27. Write a method COUNTLINES() in Python to read lines from text file 3
‘TESTFILE.TXT’ and display the lines which are not starting with any vowel.
7
Example:
The COUNTLINES() function should display the output as: The number
of lines not starting with any vowel - 1
COUNTLINES()
OR
Write a function ETCount() in Python, which should read each character of a text file
“TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and
T individually (including small cases e and t too).
Example:
Ans:
def ETCount() :
8
file = open ('TESTFILE.TXT', 'r') lines
= file.readlines() countE=0
countT=0
for w in lines : for ch
in w: if ch in 'Ee':
countE = countE + 1
if ch in 'Tt': countT=countT
+ 1
print ("The number of E or e : ", countE) print
("The number of T or t : ", countT) file.close()
28. (i) SELECT SUBJECT,COUNT(*) FROM SCHOOL GROUP BY SUBJECT HAVING COUNT(*)>=2; 3
+-----------+----------+
| SUBJECT | COUNT(*) |
+-----------+----------+
| ENGLISH | 2|
| PHYSICS | 3|
| +-----------+----------+
½ MARK FOR EACH CORRECT ANSWER
+-------------------------+
| COUNT(DISTINCT SUBJECT) |
+-------------------------+
| 4 |
+-------------------------+
1 MARK FOR CORRECT ANSWER
9
+---------------+---------+----------------+
| TEACHERNAME | SUBJECT | DESIGNATION |
+---------------+---------+----------------+
| SUPRIYA SINGH | ENGLISH | VICE PRINCIPAL |
| YASH KUMAR | MATH | HOD |
| GAGAN SINGH | PHYSICS | HOD |
+---------------+---------+----------------+
1 MARK FOR CORRECT ANSWER ½ MARK FOR PARTIALLY CORRECT ANSWER
for i in range(len(L)):
sum=L[i]+L1[i]
l2.append(sum)
print(l2)
10
30. def PushNV(N): 3
for W in N : for C in W :
if C.upper() in 'AEIOU':
break
else:
NoVowel.append(W)
All=[]
NoVowel=[]
for i in range(5) :
All.append(input('Enter a Word: '))
PushNV(All)
while NoVowel :
print(NoVowel.pop(), end=' ')
else : print('EmptyStack')
OR
OR
def Push3_5(N):
for i in N :
if i%3==0 or i%5==0 :
Only3_5.append(i)
NUM=[]
Only3_5=[]
for i in range(5):
NUM.append(int(input('Enter an Integer: ')))
Push3_5(NUM)
while Only3_5 :
print(Only3_5.pop(), end=' ')
else :
print('StackEmpty')
OR
Any other correct equivalent code
11
(½ mark for checking divisibility correctly)
(½ mark for pushing integers into the stack Only3_5)
(½ mark for reading 5 integers from the users)
(½ mark for assigning those 5 integers into NUM)
(½ mark for writing correct code to pop and display the integers from Only3_5)
(½ mark for writing correct code to check empty stack and display the message 'StackEmpty')
SECTION D
31. (i) Suggest network type (out of LAN, MAN, WAN) for connecting each of the following
set of their offices :
• Head Office and Tech Office
• Head Office and Coimbatore Office
Ans : (i) · Head Office and Tech Office: LAN
1
· Head Office and Coimbatore Office: WAN
(ii) Which device will you suggest to be procured by the company for connecting all the
computers within each of, their offices out of the following devices ?
• Modem
• Telephone 1
• Switch/Hub
Ans : Switch/Hub
(iii) Which of the following communication media, will you suggest to be procured by the company
for connecting their local offices in New Delhi for very effective and fast communication ?
• Ethernet Cable
• Optical Fiber 1
• Telephone Cable
Ans : Optical fiber
(iv)Suggest the best draw the cable layout (Block to Block) to economically
connect 1
(v) Suggest a cable/wiring layout for connecting the company’s local offices located in New Delhi. Also,,
suggest an effective method/technology for connecting the company’s regional offices at “Kolkata”,
“Coimbatore” and “Ahmedabad”.
1
Optical Fiber/Star Topology
Wireless
12
32. (a) Write the output of the code given below: 2+3
p,q=8, [8]
def sum(r,s=5):
p=r+s
q=[r,s]
print(p, q, sep='@')
sum(3,4)
print(p, q, sep='@')
Ans:
Output:
7@[3, 4]
8@[8]
(b) Ans:
Statement 1: con1.cursor()
Statement 2: mycursor.execute(querry)
Statement 3: con1.commit()
OR
(a)Ans:
@ss
13
33. What is the advantage of using a csv file for permanent storage? 5
Write a Program in Python that defines and calls the following user defined functions:
a) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each
record consists of a list with field elements as empid, name and mobile to
store employee id, employee name and employee salary respectively.
b) COUNTR() – To count the number of records present in the CSV file named
‘record.csv’.
Ans:
Advantage of a csv file:
• It is human readable – can be opened in Excel and Notepad applications
• It is just like text file
Program:
14
OR
Give any one point of difference between a binary file and a csv file. Write a
Program in Python that defines and calls the following user defined functions:
b) search()- To display the records of the furniture whose price is more than 10000.
Ans:
Difference between binary file and csv file: (Any one difference may be given)
Binary file:
• Extension is .dat
• Not human readable
• Stores data in the form of 0s and 1s
CSV file
• Extension is .csv
• Human readable
• Stores data like a text file
Program:
15
fin.close() add()
print("Now displaying") search()
SECTION E
34. (a) BookNo 1+1+2
(b) Degree=4 Cardinality =7
(c) UPDATE collections SET quantity = quantity + 20 WHERE quantity < 50;
(d) DELETE FROM Collections;
16