Cs Paper-5
Cs Paper-5
Cs Paper-5
SECTION A
312 | P a g e
4. Consider the given expression: 1
True and False or Not True
Which of the following will be correct output if the given expression is evaluated?
(a) True
(b) False
(c) NONE
(d) NULL
6. Which of the following statements is incorrect regarding the file access modes? 1
a. ‘r+’ opens a file for both reading and writing. File object points to its beginning.
b. ‘w+’ opens a file for both writing and reading. Overwrites the existing file if it
exists and creates a new one if it does not exist.
c. ‘wb’ opens a file for reading and writing in binary format. Overwrites the file if it
exists and creates a new one if it does not exist.
d. ‘a’ opens a file for appending. The file pointer is at the end of the file if the file
exists.
7. All aggregate functions except ___________ ignore null values in their input 1
collection.
a) Count (attribute) b) Count (*) c) Avg () d) Sum ()
8. Which of the following SQL commands will change the attribute value of an 1
existing tuple in a table?
(a) insert
(b) update
(c) alter
(d) change
313 | P a g e
9. Consider the following code that inputs a string and removes all special characters 1
from it after converting it to lowercase.
s = input("Enter a string")
s = s.lower()
for c in ',.;:-?!()\'"':
_________________
print(s)
For eg: if the input is 'I AM , WHAT I AM", it should print
i am what i am
Choose the correct option to complete the code .
a. s = s.replace(c, '')
b. s = s.replace(c, '\0')
c. s = s.replace(c, None)
d. s = s.remove(c)
314 | P a g e
d. When the file pointer has reached the end of file.
315 | P a g e
17. Assertion (A):-global keyword is used inside a function to enable the function alter the 1
value of a global variable.
Reasoning (R):- A global variable can not be accessed by a function without the use of
global keyword.
18. Assertion (A): The ‘with’ block clause is used to associate a file object to a file. 1
Reason (R): It is used so that at the end of the ‘with’ block the file resource is
automatically closed.
SECTION B
19. Shraddha wrote the code that, prints the sum of numbers between 1 and the number, for 2
each number till 10.She could not get proper output.
i=1
while (i <= 10): # For every number i from 1 to 10
sum = 0 # Set sum to 0
for x in range(1,i+1):
sum += x # Add every number from 1 to i
print(i, sum) # print the result
a) What is the error you have identified in this code ?
b) Rewrite the code by underlining the correction/s.
20. Write two points of difference between star and bus topology. 2
OR
Differentiate Web browser and Webserver.
316 | P a g e
score = (6, (5, (2, 1), 8), (4, 3, (1, 3, 2)))
print (score [2][2])
317 | P a g e
25. Differentiate betweendrop anddelete commands in SQL with appropriate example. 2
OR
What is the use of order by clause in SQL ? Give example.
SECTION C
26 i) Considering the following table SALEORDER which stores the name of items 1+2
sold on a day ,give the output of the query that follows:-
DATE ITEM
12-09-2022 RICE
12-09-2022 RICE
12-09-2022 SUGAR
12-09-2022 RICE
12-09-2022 COFFEE
12-09-2022 COFFEE
12-09-2022 TEA
SELECT ITEM,COUNT(*) FROM SALEORDER GROUP BY ITEM HAVING
COUNT(*)>1;
ii)Writethe outputofthequeries(a)to(d)basedonthetable BOOK,given below:
Book_Id Book_Name Publisher Price Type Qty
F0001 The Tears EEE 750 Fiction 10
F0002 Thunderbolts EEE 700 Fiction 5
T0001 Let us C++ EPB 250 Text 10
318 | P a g e
27. Write a Python function which reads a text file “poem.txt” and prints the 3
number of vowels in each line of that file, separately.
Eg: if the content of the file “poem.txt” is
The plates will still shift
and the clouds will still spew.
The sun will slowly rise
and the moon will follow too.
The output should be
6
7
6
9
OR
Write a Python program that writes the reverse of each line in “input.txt”
to another text file “output.txt”. Eg: if the content of input.txt is:
The plates will still shift
and the clouds will still spew.
The sun will slowly rise
and the moon will follow too.
The content of “output.txt” should be:
tfihs llits lliw setalp ehT
.weps llits lliw sduolc eht dna
esir ylwols lliw nus ehT
.oot wollof lliw noom eht dna
28 (a) Write the outputs of the SQL queries (i) to (iii) based on the tables VEHICLES and 3
TRAVELS
Table: VEHICLE
VCODE VEHICLETYPE PERKM
V01 VOLVO BUS 150
319 | P a g e
V02 AC DELUXE 125
BUS
V03 ORDINARY 80
BUS
V04 CAR 18
V05 SUV 30
Table: TRAVEL
CNO CNAME TRAVELDATE KM VCODE NOP
101 Arun 2015-12-13 200 V01 32
102 Balaji 2016-06-21 120 V03 45
103 Vignesh 2016-04-23 450 V02 42
104 Selva 2016-01-13 80 V02 40
105 Anupam 2015-02-10 65 V04 2
106 Tarun 2016-04-06 90 V05 4
(b) Write the command to view the structure of the table TRAVEL.
320 | P a g e
29 Write a function sumcube(L) to test if an element from list L is equal to the sum of the 3
cubes of its digits ie it is an ”Armstrong number”. Print such numbers in the list.
If L contains [67,153,311,96,370,405,371,955,407]
The function should print 153,370,371,407
30 Vikram has a list containing 10 integers. You need to help him to create a program with 3
separate user defined functions to perform the following operations based on this list.
● pushnum() to Traverse the content of the list and push the numbers that are divisible by 5
into a stack.
● popnum() to Pop and display the content of the stack and display “Stack underflow” if
the stack is empty.
For Example:
If the sample Content of the list is as follows:
N=[10, 13, 34, 55, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
35
55
10
OR
Write a function in Python, Push(Ride) where , Ride is a dictionary containing the details
of Cab ride , Ride={driver: billamt }.
The function should push the names of those driver names in the stack,INCENTIVE who
have billed greater than 400. Also display the count of names pushed into the stack
For example:
If the dictionary contains the following data:
Ride={‘Raghu’:389,’Anbu’:560,’Siraj’:768,’Syed’:450 }.
The stack INCENTIVE should contain
[‘Anbu’,’Siraj’,’Syed’]
The output should be:
The count of Drivers in the stack is 3
SECTION D
321 | P a g e
31 University of Correspondence in Allahabad is setting up the network between its different 5
wings (units). There are four wings named as Science(S), Journalism(J), Arts(A) and Home
Science(H).
(a) Suggest the suitable topology and draw the cable layout to efficiently connect
(d) Suggest the fast and very effective wired communication medium to connect
another sub office at Kanpur, 670 km far apart from above network.
i. Hub/ Switch
ii. Repeater
322 | P a g e
32 (a) Find and write the output of the following Python code: 2+3
def Display(str):
m=""
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i]+'*'
elif str[i].islower():
m=m+'@'
elif str[i]==' ' :
m=m+'#'
print(m)
Display('LION king')
(b) The code given below inserts the following record in the table Player:
PNo – integer
Name – string
NoofGames– int
Goals – integer
OR
(a) Predict the output for the following code
324 | P a g e
33 a) Mention the advantage of csv files. 5
b) Write the functions to performthe required operations on csv files and call the
functions appropriately.
i) Newgadget() to add the details of new gadgets in csv file gadget.csv which
stores records in the format.Deviceno,name,price,brand
Get the input from the user.
ii) Countgadget() to read the csv file ‘gadget.csv’ and count the devices whose
brand is “Samsung”
OR
a) Is CSV file a text file?
b) Write the functions to perform the required operations on csv files and call the
functions appropriately.
i) Namelist() to add the participants for Music competition in a csv file
“music.csv” where each record has the format
Name,class,age
ii) Display() to read the csv file ‘music.csv’ and display the participants under
15 years of age
SECTION E
SPORTS
ADMNO GAME COACHNAME GRADE
1215 CRICKET RAVI A
1213 VOLLEYBALL AMANDEEP B
1211 VOLLEYBALL GOWARDHAN A
1214 BASKET TEJASWINI B
BALL
Based on the given information answer the questions which follows,
(i) Identify the attribute used as foreign key in table sports
(ii) What is the degree of the table students?
(iii) Write SQL statements to perform the following operations
a) To display the name and game played by sports students
b) To change the address and phonenumber of “Meena ” to B 54, 8864113
(OR only to subpart iii)
325 | P a g e
iii) a) To make the field class in table STUDENTS mandatory while inserting
data
b) To delete the game CRICKET from SPORTS TABLE.
35 Aditi is a Python programmer. He has written a code and created a binary file employee.dat 1+1
with employeeid, ename and salary. The file contains 10 records.
+2
He now has to update a record based on the employee id entered by the user and update the
salary. The updated record is then to be written in the file temp.dat. The records which are
not to be updated also have to be written to the file temp.dat. If the employee id is not
found, an appropriate message should to be displayed.
As a Python expert, help him to complete the following code based on the requirement
given above:
import _______ #Statement 1
def update_data():
rec={}
fin=open("employee.dat","rb")
fout=open("_____________") #Statement 2
found=False
eid=int(input("Enter employee id to update their salary :: "))
while True:
try:
rec=______________ #Statement 3
if rec["Employee id"]==eid:
found=True
rec["Salary"]=int(input("Enter new salary :: "))
pickle.____________ #Statement 4
326 | P a g e
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print("The salary of employee id ",eid," has been updated.")
else:
print("No employee with such id is not found")
fin.close()
fout.close()
(i) Which module should be imported in the program? (Statement 1)
(ii) Write the correct statement required to open a temporary file named temp.dat.
(Statement 2)
(iii) Which statement should Aman fill in Statement 3 to read the data from the binary file,
record.dat and in Statement 4 to write the updated data in the file, temp.dat?
327 | P a g e