ComputerScience-SQP Set4-MS
ComputerScience-SQP Set4-MS
ComputerScience-SQP Set4-MS
Page 1 of 12
a) X is now: 50 b) X is now: 2 c) Error d) None of the above
Ans: a) X is now: 50
10 To read the next line from the file object fob, we can use: 1
a)fob.read(2) b) fob.read( ) c) fob.readline( ) d) fob.readlines( )
Ans: c) fob.readline( )
11 TCP/IP stands for 1
a) Transmission Communication Protocol / Internet Protocol
b)Transmission Control Protocol / Internet Protocol
c) Transport Control Protocol / Interwork Protocol
d)Transport Control Protocol / Internet Protocol
Ans: b) Transmission Communication Protocol / Internet Protocol
Page 2 of 12
Q20 and 21 are Assertion and Reasoning based questions.Mark the correct choice as
a) A is true R is false
b) A is false and R is true
c) Both A and R are correct and R is correct explanation of A
d) Both A and R are correct and R is not correct explanation of A
20 Assertion : The number of addresses used in IPv6 addressing method is 128 1
Reason : IPv6 address is a 128 bit unique address
Ans: c)
21 Assertion : Delete command is used to remove rows or records from table. 1
Reason : This command is used to remove records along with structure of the table fromdatabase
Ans: a)
SECTION B
22 Rewrite the following code after removing the syntactical error(if any).Underline eachcorrection: 2
X=input("Enter a Number")
If x % 2 =0:
for i range (2*x):
print i
loop else:
print "#"
Ans:
x=input("Enter a Number")
if x % 2= =0: error 1
for i in range (2*x): error 2
print (i) error 3
else:
print ("#") error 4
23 Write two points of difference between Client side script and Server side script 2
Ans:
OR
Write two advantages of Twisted pair cable.
Ans: Advantages of Twisted Pair cable
• It is easy to install and maintain
• It is very inexpensive
• It can be easily connected
• It is flexible
Page 3 of 12
24 Write the output of the following python code: 2
def func(b):
global x
print ('Global x=',x)
y=x+b
x=7
z=x-b
print ('Local x=' ,x)
print ('y=' ,y)
print ('z=' ,z)
x=5
func(10)
Ans: Global x=5
Local x=7
y=15
z=-3
25 Write two features of return keywords. 2
Ans:
1. No statement in the function will be executed after the return statement.
Example :
def calculate(m,n):
add=0
add=m+n
return add # here terminate the function
p=m+n # it is not executed
2. A Python function may be return multiple values to its called program(main program)
Example2:
def getPerson():
name = "Narain Ji"
age = 45
country = "India"
return name,age,country
name,age,country = getPerson()
print(name)
print(age)
print(country)
----------------------------------
#Output:
Narain Ji
45
India
26 Classify each of the following Web Scripting as Client Side Scripting and Server Side Scripting : 2
(i) Java Scripting (ii) ASP (iii) VB Scripting (iv) JSP
Ans: Client-side scripting from the given Web scripting is as follows:
(i) Java Scripting (ii) VB Scripting
Server-side scripting from the given Web scripting is as follows:
(i) ASP (ii) JSP
27 a) Consider the code given below and fill in the blanks. 2
Page 4 of 12
try:
f=open("Account.txt",'r')
except ………………: #Statement 1
print('File not found')
………..:
print("Finally execute program...") #Statement 2
Ans: Statement 1→ FileNotFoundError Statement 2:→ finally
OR
Write a Python program that opens a file and handles a IndexError exception if the file does not
exist.
Ans:
my_list = [1, 2, 3]
try:
print(my_list[3])
except IndexError:
print("Index is out of range")
28 Differentiate between equi join and cross join function in SQL with an example. 2
Ans:
Equi Join Cross Join/Cartesian Product
It returns data from the table with A product of two or more sets thatconsists
matchingvalues of all combinations of records from two
tables are joined
Syntax: Syntax:
Select column from table1,table2 where Select column from table1,table2
table1.common_col=table2.common_col
OR
Categorize the following commands as DML or DDL
ALTER , UPDATE , DELETE , DESCRIBE
Ans : DDL→ ALTER, DESCRIBE DML→ UPDATE, DELETE
SECTION –C
29 Write two differences between Coaxial and Fiber transmission media. 3
Ans:
Sr. No. Key Optical Fibre Coaxial Cable
1 Transmission Optical Fibre transmits data/signals The coaxial cable transmits data/signals
Type in the form of light. in the form of electrical signals.
2 Material Optical fibre is made using plastic Coaxial cable is prepared using plastic
and glass. and copper wires.
3 Efficiency Optical fibre is highly efficient and Coaxial cable is less efficient.
signal loss is negligible.
4 Cost Optical fibre is costly and its Coaxial cable is cheap and its
installation is quite expensive. installation is less expensive.
OR
(a) Write the full forms the following:
(i) FTP (ii) HTTPS
Ans: FTP- File Transfer Protocol HTTPS→ Hyper Text Transfer Protocol Secure
(b)Name the protocols which are used for sending and receiving emails?
Page 5 of 12
Ans: SMTP
30 Write a function show_word( ) in python to read the content of a text file 'words.txt' and display the 3
entire content in upper case. Example ,if the file contain
"I love my country ,i am proud to be indian"
Then the function should display the output as:
I LOVE MY COUNTRY ,I AM PROUD TO BE INDIAN
Ans:
def show_word():
file=open( "words.txt",'r')
Lines=file.readlines()
for L in Lines:
print(L.upper())
File.close()
OR
Considering the content stored in file “CORONA.TXT”
O Corona O Corona
Jaldi se tum Go na
Social Distancing ka palan karona
sabse 1 meter ki duri rakhona
Lockdown me ghar me ho to
Online padhai karona
Write the output of following statements – f = open("CORONA.TXT")
sr1 = # to read first line of file
str2 = # to read next line of file
str3 = # to read remaining lines of file
Ans: str1 = f.readline()
str2 = f.readline()
str3 = f.readlines() OR str3 = f.read()
31 a) Difference between WHERE and HAVING. 3
Ans:
WHERE HAVING
1. Filters by each row 1. Filters by each group
2. Processed before any grouping 2. Processed after any grouping
3. Cannot have aggregate functions 3. Can have aggregate functions
4. Can be used in SELECT, UPDATE, 4. Can only be used in SELECT statements
DELETE statements 5. Written after GROUP BY clause
Written before GROUP BY clause SELECT
SELECT FROM table
FROM table GROUP BY column2
WHERE column1 >= condition: HAVING MIN(column1)> condition
OR
b) Write down the syntax for the following tasks in MySQL:
1. Viewing the structure of a table
Ans: DESC <Table Name> or DESCRIBE <Table Name> or EXPLAIN <Table Name>
2. Adding a column in an existing table
Ans: ALTER TABLE <Table Name> ADD <Column Name> <Data Type> <Constraint>
SECTION D
Page 6 of 12
32 Write SQL commands for the following queries based on the relation Teacher givenbelow: 4
Table: Teacher
No Name Age Departme nt Date_of_join Salary Sex
1 Jugal 34 Computer 10-01-1997 12000 M
2 Sharmila 31 History 24-03-1998 20000 F
3 Sandeep 32 Maths 12-12-1996 30000 M
4 Sangeeta 35 History 01-07-1999 40000 F
5 Rakesh 42 Maths 05-09-1997 25000 M
6 Shyam 50 History 27-06-1998 30000 M
7 ShivOm 44 Computer 25-02-1997 21000 M
8 Shalakha 33 Maths 31-07-1997 20000 F
(i) To show all information about the teacher of Computer department.
Ans: SELECT * FROM Teacher WHERE Department= “Computer”;
(ii) To list the names of all teachers with their date of joining in descending order.
Ans: SELECT Name FROM Teacher ORDER BY Date_of_join;
(iii) Delete the record of teacher age greater than 45
Ans: DELETE FROM Teacher WHERE Age>45;
(iv) Increase the salary of teachers by 15% whose department is history
Ans: UPDATE Teacher SET Salary=Salary+Salary*15/100 WHERE Department = ‘History’;
OR
Write outputs for SQL queries (i) to (iii) which are based on the given table Passengers:
Table: Passengers
Pnr T_no P_name Sex Age CITY TravelDate
P011 11001 Puneet Kumar M 42 Delhi 2019-07-12
P022 11010 Kush arora M 39 Chandigarh 2014-03-30
P033 12201 Shweta Nagpal F 25 Madras 2014-12-30
P044 11011 Sumit Mishra M 32 Kolkata 2018-07-15
P055 12021 Ashmita Sharma F 33 Delhi 2019-03-30
P066 12012 Vinny Sood F 35 Chandigarh 2017-12-17
P077 13013 Akshat Gupta M 30 Madras 2018-07-22
i. Select P_Name From Passengers Where Age>30;
Ans:
P_name Age
Puneet Kumar 42
Kush arora 39
Sumit Mishra 32
Ashmita Sharma 33
Vinny Sood 35
ii. Select P_Name, City From Passengers Where P_Name Like ‘%A’ and Sex= ‘M’ ;
Ans:
P_name Age
Kush arora 39
Sumit Mishra 32
Akshat Gupta 30
iii. Select Age From Passengers Where City= ‘Chandigarh’;
Ans:
Age
Page 7 of 12
39
35
iv. Select Count(Distinct(City) From Passengers Group By City;
Ans:
CITY Count(Distinct(City)
Delhi 2
Chandigarh 2
Madras 2
Kolkata 1
33 A list contains following records of students: [Adm_no,SName,DOB,Mobile] 4
Write the following user defined function to perform given operations on the stacknamed
'Admission':
i) PUSH() To insert an object containing admission number,student name and Mobile of the
students who's birth year is after 2008 to the stack. If stack holds more than 3 elements show
"stack is full"
ii) POP() To pop the object from the stack and display them in stack one by one.For Example:
If the lists of students detail are : ["20221017","Guru","20-7-2008","9988779988"]
["20221018","Ragunath","06-8-2009","9977889988"]
["20221019","Jenifer","31-12-2007","9988996677"]
["20221020","Priya","21-10-2009","9966557864"]
The stack should contain ["20221017","Guru","9988779988"]
["20221018","Ragunath","9977889988"] ["20221020","Priya","9966557864"]
The output should contain ["20221017","Guru","9988779988"]
["20221018","Ragunath","9977889988"] ["20221020","Priya","9966557864"]
Stack is full
Ans:
students=[["20221017","Guru","20-7-2008","9988779988"],
["20221018","Ragunath","06-8-2009","9977889988"],
["20221019","Jenifer","31-12-2007","9988996677"],
["20221020","Priya","21-10-2009","9966557864"]]
Admission=[]
def Push():
for i in students:
if int(i[2][-4:])>2008:
Admission.append(i)
else:
print("Stack is full")
def Pop():
if Admission==[]:
print("Empty Stack")
else:
print(Admission.pop())
def traverse():
if Admission==[]:
print("Empty Stack")
else:
for i in range(len(Admission)-1,-1,-1):
print(Admission[i])
Push()
Page 8 of 12
traverse()
Pop()
OR
Write a function in python, makepush(var) and makepop(var) ,to add a new variable and delete a
variable from list of variables description, considering them to act as push and pop operations of the
stack data structure.
Ans:
var=[]
def MakePush(var):
a=int(input("enter package title:"))
Package.append(a)
def MakePop(var):
if(Package==[]):
print("Stack empty")
else:
print("Deleted element:",Package.pop())
Page 9 of 12
35 Write code to connect to a MySQL database namely School and then fetch all those records from 4
table Student where grade is ' A' .
Rollno Name Marks Grade Section Project
101 RUHANII 76.8 A A PENDING
102 GEOGRE 71.2 B A SUBMITTED
103 SIMRAN 81.2 A B EVALUATED
104 ALI 61.2 B C ASSIGNED
105 KUSHAL 51.6 C C EVALUATED
106 ARSIYA 91.6 A+ B SUBMITTED
107 RAUNAK 32.5 F B SUBMITTED
Note the following to establish connectivity between Python and MySQL:
host = "localhost",
user = "root",
password = "tiger",
database = "School"
Ans:
import mysql.connector
mydb= mysql.connector.connect(host= ‘localhost’, user= ‘root’, passwd= ‘tiger’, database=
‘School’)
mycur=mydb.cursor()
mycur.execute(“SELECT *FROM Student Where Grade=‘A’ ”)
rec=mycur.fetchall()
for row in rec:
print(row)
mycur.close()
mydb.close()
SECTION E
36 TellAbout Consultants are setting up a secured network for their office campus at Gurgaon for their 5
day-to-day office and web-based activities. They are planning to have connectivity between three
buildings and the head office situated in Mumbai. Answer the questions (i) to (v) after going
through the building positions in the campus and other details, which are given below :
The given building blocks are named as Green, Blue and Red
Page 10 of 12
(i) Suggest the most suitable place (i.e., building) to house the server of this organization. Also
give a reason to justify your suggested location.
(ii) Suggest the placement of the following devices with justification:
a) Repeater. b) Switch.
(iii) Suggest a cable layout of connections between the buildings inside the campus.
(iv) The organization is planning to provide a high speed link with its head office situated in Mumbai
using a wired connection. Which of the following cables will be most suitable for this job.
a) Optical Fiber b) Co-axial Cable c) Ethernet Cable
(v) While connecting the devices two modems are found to be defected. What is the function of
modem?
Ans:
Answers:
i. The most suitable place to install server is building “RED” because this building have
maximum computer which reduce communication delay
ii. Since the cabling distance between buildings GREEN, BLUE and RED are quite large,
so a repeater each, would ideally be need along their path to avoid loss of signals during
the courseof data flow in their routes.
Page 11 of 12
iv. Optical Fiber
v. The modem will do the modulation and demodulation process.That is, it converts digital signal to
analog signal at senders side and analogto digital at receivers side, respectively.
37 Mr. Mathew is a Python programmer. Who has recently joined the company and given at ask to 5
write a python code to perform update operation in binary file (stud.dat) which contain admno
(Admission no) ,name , gender and salary (salary paid by employee).
(i) Write Python function AddEmp() to add few records.
(ii) Write Python code to create function showAll() those salary less than 60000.
Ans:
import pickle
def AddEmp():
fw=open("stud.dat",'wb')
stud=[]
while True:
admno=int(input("Admission no : "))
name=input("Name : ")
gender=input("Gender : ")
salary=float(input("Salary :"))
data=[admno,name,gender,salary]
stud.append(data)
ch=input("Add More records Y/N").upper()
if ch=='N':break
pickle.dump(stud,fw)
fw.close()
def ShowAll():
fr=open("stud.dat",'rb')
stud=pickle.load(fr)
print(stud)
for row in stud:
if int(row[3])<60000:
print(row[0],row[1],row[2],row[3],sep='\t')
fr.close()
AddEmp()
ShowAll()
Page 12 of 12