ComputerScience-SQP Set5-MS

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Sample Question Paper – V (THEORY)

Class: XII Session: 2024-25


Computer Science (083)
Marking Scheme

SECTION A
1. State True or False 1
“Python identifiers are dynamically typed.”
Ans: True
2. Which of the following is an invalid operator in Python? 1
(a) - (b) //= (c) in (d) =%
Ans: (d) =%
3. Given the following dictionary 1
employee={'salary':10000,'age':22,'name':'Mahesh'}
employee.pop('age')
print(employee)
What is output?
a. {‘age’:22} b. {'salary': 10000, 'name': 'Mahesh'}
c. {'salary':10000,'age':22,'name':'Mahesh'} d. None of the above
Ans: b. {'salary': 10000, 'name': 'Mahesh'}
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
Ans: (b) False
5. What will the following code print? 1
print(max("zoo 145 com"))
a. 145 b. 122 c. z d. zoo
Ans: c) z
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 fileexists.
Ans: (c)
7. All aggregate functions except ignore null values in their input collection. 1
a) Count (attribute) (b) Count (*) (c) Avg () (d) Sum ()
Ans: (b) Count (*)
8. Which of the following SQL commands will change the attribute value of an existing tuple in a table? 1
(a) Insert (b) Update (c) alter (d) change
Ans: (c) alter
9. Fill in the blank: 1
An attribute or set of attributes in a table that can become a primary key is termed as ………….
(a) Alternate key (b) Candidate key (c) Foreign key (d) Unique key
Ans: (b) Candidate key

Page 1 of 13
10. Fill in the blank: 1
The SELECT statement when combined with clause, is used for pattern matching
(a) Order by (b) Distinct (c) like (d) between
Ans: (c) like
11. Observe the following code snippet 1
file = open(“station.txt”,”r”)
try:
……..
except EOFError: # When will this line execute
……..
When will the line underlined execute?
(a) When the file is closed.
(b) This is a text file.
(c) When the file pointer is at the beginning of the file.
(d) When the file pointer has reached the end of file.
Ans: (d) When the file pointer has reached the end of file.
12. Consider the following code that inputs a string and removes all special characters 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)
Ans: (a) s = s.replace(c, '')
13. is a standard network protocol used to transfer files from one host to another host over a TCP- 1
based network, such as the Internet.
(a) TCP (b) IP (c) FTP (d) SMTP
Ans: FTP
14. What will the following expression be evaluated to in Python? 1
2**3**2+15//3
(a) 69 (b) 517 (c) 175 (d) 65
Ans: (b) 517
15. Identify the invalid SQL aggregate function from the following 1
(a) sum (b) max (c)min (d) add
Ans: (d) add
16. Identify the invalid method to get the data from the result set of query fetched by a cursor object 1
mycursor.
(a) mycursor.fetchone() (b) mycursor.fetchall() (c) mycursor.fetchmany() (d) mycursor.fetchnow()
Ans: (d) mycursor.fetchnow()
17. Pushing an element into stack already having five elements and stack size of 5, then stack becomes
___________
(a) Overflow (b) Crash (c) Underflow (d) User flow
Ans: (a) Overflow
18. How can you execute multiple statements under a single if block in Python?
(a) Separate statements with a semicolon (b) Indent the statements to the same level
(c) Use the and keyword between statements (d) Use the elif keyword

Page 2 of 13
Ans: (b) Indent the statements to the same level
19. Identify the correct syntax of List to add element in given position/index function:
(a) insert(index,element) (b) insert(element,index)
(b) insert(index,element, after index) (d) append(element,index)
Ans: (a) insert(index,element)
Q20 and 21 are ASSERTION AND REASONING based questions. Mark the correct choice as
(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
20. Assertion (A):-global keyword is used inside a function to enable the function alter the value of a global 1
variable.
Reasoning (R):- A global variable can not be accessed by a function without the use of global keyword.
Ans: (a)
21. 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.
Ans: (a)
SECTION B
22. Shraddha wrote the code that, prints the sum of numbers between 1 and the number, for each number 2
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.
Ans:
a. The code will cause infinite loop
b. Correction
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
i=i+1
23. Write two points of difference between star and bus topology. 2
Ans:
Bus Star
In Bus topology all devices are connected to a In star topology each device is connected to a
common backbone wireknown as Bus. All data central node, which is anetworking device like a

Page 3 of 13
is transmitted through the Bus. hub or a switch.
Less easy to find faults in the network Easy to find and rectify fault
Easy to install and configure High initial cost of wires
Failure of bus brings the network down Failure of one line will not bring the entire
network down.

OR
Differentiate Web browser and Webserver.
Ans:
Parameters Web Browser Web Servers
Respond to requests made by web
Function Access and view content on the internet
browsers.
Type of Application Client-side (e.g. computer, mobile, etc.) Server-side
Users interact with the web browser Users interact with web servers
Interaction directly through web browsers
Supported HTTP, HTTPs, and other web
HTML, CSS, JavaScript
Technologies protocol
Firewalls and Intrusion Detection
Security Features Cache and Cookies
System
Google Chrome, Mozilla Firefox,
Examples Microsoft Edge, Apple Safari
Apache, Nginx, IIS, Tomcat, JBoss

a) Write the output of the code snippet.


24. txt = "Time, will it come back?" 2
x = txt.find(",")
y = txt.find("?")
print(txt[x+2:y])
Ans: will it come back
b) The score of a student in a test is stored as a Python tuple. The test had 3 questions, with some
questions having subparts whose scores are recorded separately. Give the output of the code snippet.
score = (6, (5, (2, 1), 8), (4, 3, (1, 3, 2)))
print (score [2][2])
Ans: (1, 3, 2)
25. Which is the correct outcome executed from the following code? Write minimum value of n1 and 2
maximum value of n2.
import random
n1= random.randrange(1, 10, 2)
n2= random.randrange(1, 10, 3)
print (n1,"and",n2)
(a) 2 and 7 (b) 3 and 4 (c) 8 and 10 (d) 8 and 9
Ans: (b) 3 and 4
26. (a) Write the full forms of the following: 2
(i) SMTP (ii) URL

Page 4 of 13
Ans: SMTP→ Simple Mail Transfer Protocol URL→Uniform Resource Locator
(b) Differentiate http and https protocols.
27. Predict the output of the Python code given below: 2
value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value – N
print(value, end="#")
display(20)
print(value)
Ans: 5#5
OR
Predict the output of the Python code given below:
l=[]
for i in range(4):
l.append(2*i+1)
print(l[::-1])
Ans: [7, 5, 3, 1]
28. Differentiate between drop and delete commands in SQL with appropriate example. 2
Ans:
Parameter DROP DELETE
SQL Statement
Data Definitinition Language (DDL) Data Manipulation Language (DML)
Type
DELETE FROM table_name WHERE
Syntax DROP TABLE table_name
condition
It removes entire database objects Removes specific rows of data from a
Purpose
(tables, indexes, views, etc.) table.
Conditional Removes specified rows based on the
Not applicable; removes entire objects.
Deletion specified conditions.
OR
What is the use of order by clause in SQL ? Give example.
Ans:
The order by clause is used to arrange the table based on asc /desc order of a particular field.
Syntax: select fn1,fn2 … from tablename order by fn1 [asc/desc];
Select name,marks from student order by marks asc;
SECTION C
29. Write a function sumcube(L) to test if an element from list L is equal to the sum of the cubes of 3
its digits i.e. 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
Ans:
def sumcube(L):

Page 5 of 13
for i in L:
t=i; s=0
while t:
r=t%10
s=s+r**3
t=t//10
if s==i:
print(i,end=' ')
#main
L=[67,153,311,96,370,405,371,955,407]
sumcube(L)
OR
(ii) (a) Predict the output of the Python code:
nested_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
removed_element = nested_list[2].pop()
print(removed_element)
Ans: 9
(b) a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
c = []
for val in a:
if val not in b:
c.append(val)
print(c)
Ans: [1, 2]
30. print ("Handling exception using try...except...else...finally") 3
try:
numerator=50
denom=int(input("Enter the denominator: "))
quotient=(numerator/denom)
print ("Division performed successfully")
except ___________________: #Statement1
print ("Denominator as ZERO is not allowed")
except ______________: #Statement2
print ("Only INTEGERS should be entered")
else:
print ("The result of division operation is ", quotient)
________: #Statement3
print ("OVER AND OUT")
Fill in the blank exception name.
Ans:
print("Learning Exceptions...")
try:
num1 = int(input("Enter the first number"))
num2 = int(input("Enter the second number"))
quotient = (num1 / num2)
print("Both numbers entered were correct")
except ValueError: # 1 : to enter only integers
print("Please enter only numbers")

Page 6 of 13
except ZeroDivisionError: # 2 : Denominator should not be zero
print("Number 2 should not be zero")
else:
print("Great.. you are a good programmer")
finally: # 3 : to be executed at the end
print("JOB OVER... GO GET SOME REST")
31. Write a Python function which reads a text file “poem.txt” and prints the number of vowels in each line 3
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
Ans:
fr=open('poem1.txt','r')
lines=fr.readlines()
c=0
for line in lines:
c=0
for letter in line:
if letter in 'AEIOUaeiou':
c=c+1
print(c)
fr.close()
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
Ans:
fr=open('poem1.txt','r')
lines=fr.readlines()
c=0
for line in lines:
words=line.split()[::-1]
st=''
for word in words:

Page 7 of 13
print(word[::-1],end=" ")
print()
fr.close()
SECTION C
32 (a) Write the functions to perform the required operations on csv files and call the functions appropriately. 4
(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”
Ans:
import csv
def Newgadget():
fw=open("gadget.csv",'w',newline='')
dev=[]
writer=csv.writer(fw)
writer.writerow(['Deviceno', 'name', 'price', 'brand'])
for i in range(5):
Dno=int(input("Device No : "))
name=input("Device Name : ")
price=float(input("Device Price : "))
brand=input("Brand Name : ")
data=[Dno, name, price, brand]
dev.append(data)
writer.writerows(dev)
fw.close()
def Countgadget():
fr=open("gadget.csv",'r')
reader=csv.reader(fr)
print(reader)
count=0
for i in reader:
if i[3]=='Samsung':
count=count+1
fr.close()
print("No. of Samsund Device : ",count)
Newgadget()
Countgadget()
OR
(b) Write the functions to perform the required operations on csv files and call thefunctions
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
Ans:
import csv
def Namelist():
fw=open("music.csv",'w',newline='')
music=[]
writer=csv.writer(fw)
writer.writerow(['Name', 'class', 'age'])

Page 8 of 13
for i in range(5):
name=input("Student Name : ")
clas=input("Class : ")
ag=int(input("Age : "))
data=[name,clas,ag]
music.append(data)
writer.writerows(music)
fw.close()
def Display():
fr=open("music.csv",'r')
reader=csv.reader(fr)
print(reader)
count=0
next(reader)
for row in reader:
if int(row[2])<15:
print(row[0],row[1],row[2],sep='\t')
fr.close()
Namelist()
Display()
33. In a database School, there are two tables given below: 4
STUDENTS
RNO NAME CLASS SEC ADDRESS ADMNO PHONE
1 MEERA 12 D A-26 1211 3245678
2 MEENA 12 A NULL 1213 NULL
3 KARISH 10 B AB-234 1214 4567890
4 SURAJ 11 C ZW12 1215 4345677
SPORTS
ADMNO GAME COACHNAME GRADE
1215 CRICKET RAVI A
1213 VOLLEYBALL AMANDEEP B
1211 VOLLEYBALL GOWARDHAN A
1214 BASKET TEJASWINI BBALL
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
(iv) a) Select NAME,GAME from STUDENTS S,SPORTS T where S.ADMNNO=T.ADMNNO;
OR
(a) Write the outputs of the SQL queries (i) to (iii) based on the tables VEHICLES andTRAVELS
Table: VEHICLE
VCODE VEHICLETYPE PERKM
V01 VOLVO BUS 150
V02 AC DELUXEBUS 125
V03 ORDINARY BUS 80

Page 9 of 13
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
● PERKM is Freight Charges per kilometer.
● Km is kilometers Travelled
● NOP is number of passengers travelling in vehicle.
(i) SELECT VCODE, COUNT(*) AS NUMTRIPSFROM TRAVELGROUP BY VCODE;
(ii) SELECT CNAME, TRAVEL.VCODE, VEHICLETYPEFROM VEHICLE, TRAVEL WHERE
VEHICLE.VCODE = TRAVEL.VCODE AND NOP >= 30;
(iii) SELECT MAX(TRAVELDATE), MIN(TRAVELDATE) FROM TRAVEL ;
(iv) SELECT VEHICLETYPE FROM VEHICLE WHERE VEHICLETYPE LIKE “%BUS”;
(b) Write the command to view the structure of the table TRAVEL.
34. Vikram has a list containing 10 integers. You need to help him to create a program with separate user 4
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
Ans:
N=[10, 13, 34, 55, 21, 79, 98, 22, 35, 38]
stack=[]
def pushnum():
for i in N:
if i%5==0:
stack.append(i)
print("Stack Elements")
for i in range(len(stack)-1,-1,-1):
print(stack[i])
def pop():
if len(stack)==0:
print("Stack Underflow")
else:
print("Popped element : ",stack.pop())

pushnum()
pop()

Page 10 of 13
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
Ride={'Raghu':389,'Anbu':560,'Siraj':768,'Syed':450 }
INCENTIVE=[]
def push(Ride):
c=0
for i in Ride:
if Ride[i]>400:
INCENTIVE.append(i)
c=c+1
else:
print("Stack Values :")
for i in range(len(INCENTIVE)-1,-1,-1):
print(INCENTIVE[i])
print("The count of Drivers in the stack is ",c)

push(Ride)
35. The code given below inserts the following record in the table Player: 4
PNo – integer
Name – string
NoofGames– int
Goals – integer
Note the following to establish connectivity between Python and MYSQL:
a. Username is root
b. Password is sport
c. The table exists in a MYSQL database named Football.
d. The details (Pno,Name,NoofGames,Goals) are to be accepted from the user.
Write the python code to create function Insert() for add new record and showAll() function display all
record.
Ans:
import mysql.connector as sql
mydb=sql.connect(host= "localhost", user= "root", password= "sport", database= 'Football')
mycur=mydb.cursor()
def Insert():
while True:
pno=int(input("Player No :"))
Name=input("Player Name : ")
Nog=int(input("Enter no of games : "))
G=int(input("Enter Goals : "))
Data=(pno,Name,Nog,G)
Sql="Insert into Player values(%s,%s,%s,%s)"

Page 11 of 13
mycur.execute(Sql,Data)
mydb.commit()
ch=input("Add more records Y/N").upper()
if ch=='N':break

def showAll():
mycur.execute("Select * from Player")
rec=mycur.fetchall()
for i in rec:
print(i)
Insert()
showAll()
SECTION E
36. Aditi is a Python programmer. He has written a code and created a binary file employee.dat with 5
employeeid, ename and salary. The file contains 10 records.
He now has to update a record based on the employee id entered by the user and update the
salary increment 1000. 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.
Ans:
import pickle
def update_data():
rec={}
fin=open("employee.dat","rb")
fout=open(“temp.dat”,”wb”)
found=False
eid=int(input("Enter employee id to update their salary :: "))
while True:
try:
rec=pickle.load(fin)
if rec["Employee id"]==eid:
found=True
rec["Salary"]=int(input("Enter new salary :: "))
pickle.dump(rec,fout)
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()
fin.close()
fout.close()
31 University of Correspondence in Allahabad is setting up the network between its different wings 5
(units). There are four wings named as Science(S), Journalism(J), Arts(A) and HomeScience(H).

Page 12 of 13
Distance between various wings Number of Computers in each wing
Wing A to Wing S 100 m
Wing A to Wing J 200 m Wing A 150
Wing A to Wing H 400 m Wing J 5
Wing S to Wing J 300 m Wing S 10
Wing S to Wing H 100 m Wing H 50
Wing J to Wing H 450 m
(a) Suggest the suitable topology and draw the cable layout to efficiently connectvarious blocks / wings
of network.
Ans: Ans: Star topology
S
S
A 100m 100m
300 m HQ
A
J H
J
(b)Where should the server be housed ? justify your answer.
Ans: Ans:Wing A ,as it has maximum number of computers(1/2 mark for correctwing and ½ mark
for justification)
(c) What kind of network (LAN/MAN/WAN) will be formed?
Ans: LAN
(d)Suggest the fast and very effective wired communication medium to connectanother sub office at
Kanpur, 670 km far apart from above network.
Ans: Optical Fibre
(e) Suggest the placement of the following devices in the network.
i. Hub/ Switch
ii. Repeater
Ans: Hub/Switch In All Wings
Repeater: Between S and J blocks as the distance is > 100m

Page 13 of 13

You might also like