ComputerScience SQP Set3 MS

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

Sample Question Paper - III

Class: XII Session: 2024-25


Computer Science (083)
Marking Scheme
SECTION A
1. State whether True or False: 1
Variable names can begin with the _ symbol.
Ans: True
2. Identify which of the following is an invalid data type in Python: 1
(a) int (b) float (c) super (d) None
Ans: super
3. Consider the following code: 1
dict1 = {‘Mohan’: 95, ‘Ram’: 89, ‘Suhel’: 92, ‘Saritha’: 85}
What suitable code should be written to return a list of values in dict1 ?
Ans: dict1.values
4. Consider the following expression: not True and False or not False 1
Which of the following will be the output:
a) True b) False c) None d) NULL
Ans: a) True
5. Select the correct output of the following code: 1
>>>str1 = ‘India is a Great Country’
>>>str1.split(‘a’)
a) [‘India’,’is’,’a’,’Great’,’Country’] b) [‘India’, ’is’, ’Great’, ’Country’]
c) [‘Indi’, ’is’, ’Gre’, ’t Country’] d) [‘Indi’, ’is’, ’Gre’, ’t’, ‘Country’]
Ans: c) ['Indi', ' is ', ' Gre', 't Country']
6. Which of the following is an invalid access mode for text files: 1
(a) W (b) a+ (c) ab (d) r
Ans: c) ab
7. Fill in the blanks: 1
command is used to add a new column in the table in SQL.
Ans: ALTER
8. Which of the following will display all the tables in a database: 1
a) SELECT * FROM <tablename>; b) DISPLAY TABLES;
c) SHOW TABLES; d) USE TABLES;
Ans: c) SHOW TABLES;
9. Which of the following will be the output of the code: 1
mySubject = “Computer Science”
print(mySubject[:3] + mySubject[3:])
a) Com b) puter Science
c) Computer Science d) Science Computer
Ans: c) Computer Sciecne
10. Choose the correct option: 1
is the number of columns in a table and is the number of rows in the table.
a) Cardinality, Degree b) Degree, Cardinality
c) Domain, Range d) Attribute, Tuple
Ans: b) Degree, Cardinality
11. The correct syntax of load( ) is: 1
a) <objectvariable>=pickle.load(<fileobject>) b) pickle.load(<fileobject>, <objectvariable>)
c) <fileobject>.load(<objectvariable>) d) <objectvariable> = <fileobject>.load( )
Ans: a) <objectvariable>=pickle.load(<fileobject>)
12. The clause is used to display result of an SQL query in ascending or descending order 1

Page 1 of 12
with respect to specified attribute values
Ans: ORDER BY
13. Fill in the blank: 1
is the protocol used for transferring files from one machine to another.
a) HTTP b) FTP
c) SMTP d) VOIP
e) Ans: b) FTP
14. How will the following expression be evaluated in Python? 1
2 + 9 * ( ( 3 * 12) – 8 ) / 10
a) 29.2 b) 25.2
c) 27.2 d) 27
Ans. c) 27.2
15. Which function is used to display the sum of values in a specified column ? 1
a) COUNT(column) b) TOTAL(column)
c) SUM(column) d) ADD(column)
Ans: c) SUM(column)
16. To open a connector to the MySQL database, which statement is used to connect with MySQL ? 1
a) Connector b) connect c) password d) username
Ans: b) connect
17. Which of the following statement(s) would give an error after executing the following 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
18. Consider the following operation performed on a stack of size 5.
Push(1)
Pop()
Push(2)
Push(3)
Pop()
Push(4)
Pop()
Pop()
Push(5)
After the competition of all operation, the number of elements present is stack are
(a) 1 (b) 2 (c) 3 (d) 4
Ans: (a) 1
19. Which keyword is used to catch exceptions in Python?
a) try (b) catch (c) except (d) d) handle
Ans: except
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) : A variable defined outside any function or any block is known as a global variable. 1
Reason (R) : A variable defined inside any function or a block is known as a local variable.

Page 2 of 12
Ans: (b) Both A and R are true and R is not the correct explanation for A
21. Assertion (A) : The tell( ) method returns an integer that specifies the current position of the file 1
object in the file.
Reason (R) : Offset can have any of the three values – 0, 1 and 2
Ans: A is True but R is False
SECTION B
22. Observe the following Python code very carefully and rewrite it afterremoving all syntactical errors 2
with each correction underlined.
DEF result_even( ):
x = input(“Enter a number”)if (x % 2 = 0) :
print (“You entered an even number”)else:
print(“Number is odd”)
even ( )
Ans:
def result_even( ):
x = input(“Enter a number”)
if (x % 2 == 0) :
print (“You entered an even number”)
else:
print(“Number is odd”)
result_even ( )
23. Write two points of difference between LAN and WAN. 2
(OR)
Write two points of difference between HTTP and SMTP.
24 (a) Given is a Python string declaration: 1
str1="!!Welcome to Python!!"
Write the output of: 1
print(str1[::-2])
(b) Write the output of the code given below:
dict1 = {"name": "Suman", "age": 36}
dict1['age'] = 27
dict1['address'] = "Chennai"
print(dict1.keys())
Ans: (a) !nhy teolW! (b) dict_keys(['name', 'age', 'address'])
25. Write a Python program that executes division and handles an Arithmetic Error exception if there is 2
an arithmetic error.
Ans:
def division(dividend, divisor):
try:
result = dividend / divisor
print("Result:", result)
except ArithmeticError:
print("Error: Arithmetic error occurred!")
dividend = float(input("Input the dividend: "))
divisor = float(input("Input the divisor: "))
division(dividend, divisor)
Note: Student can use another example
26. (a) Expand the following: 1
i) XML ii) HTML
(b) What is the use of PPP in computer networks? 1
Ans: (a) (i) eXtensible Markup Language (1/2 mark)

Page 3 of 12
(ii) HyperText Markup Language (1/2 mark)
(b) Point to Point Protocol is the Internet standard for transmission ofIP packets over serial
lines. It is the best solution for dial-up Internet connections.
27. (a) Write two points of difference between LAN and WAN 2
(OR)
(b) Write two points of difference between HTTP AND SMTP
Ans:
(a) LANs connect devices within a limited area, such as an office, while WANs connect devices
that are spread across a large area, such as an entire country or even the world.
(b) SMTP is used to transfer emails between mail servers, while HTTP is used to transfer data from
a web server to a web client
28. (a) Differentiate between COUNT(*) and SUM( ) functions in SQL with appropriate example. 2
(OR)
Categorize the following commands as DDL or DML: CREATE, DROP, UPDATE, INSERT
Ans: (a) The COUNT(*) function returns the number of non-empty cells in a range while SUM( ) is
doing the mathematical sum.
(b) DDL:- CREATE, DROP DML:- UPDATE, INSERT
SECTION C
29. Write a function in python to count the number lines in a text file ‘Country.txt’ which is starting 1+2
with an alphabet ‘W’ or ‘H’. If the filecontents are as follows:
Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.
The output of the function should be:W or w : 8
H or h : 13
Ans:
def count_W_H():
f = open ("Country.txt", "r")
W,H = 0,0
r = f.read()
for x in r:
if x[0] == "W" or x[0] =="w":
W=W+1
elif x[0] == "H" or x[0] == "h":
H=H+1
f.close()
print ("W or w :", W)
print ("H or h :", H)
count_W_H()
(OR)
Write a user defined function countwords( ) to display the total number of words present in the text
file “Quotes.Txt”. If the text file has the following data written in it:

Living a life you can be proud of doing your best


Spending your time with people and activities that are important to you
Standing up for things that are right even when it’s hard
Becoming the best version of you

The countwords() function should display the output as:


Total number of words : 40

Page 4 of 12
Ans:
def countwords():
s = open("Quotes.txt","r")
f = s.read()
z = f.split()
count = 0
for I in z:
count = count + 1
print ("Total number of words:", count)
s.close( )
countwords()
30. A list, NList contains following record as list elements: 3
[City, Country, distance from Delhi]
Each of these records are nested together to form a nested list. Write the following user defined
functions in Pythons to perform the specified operations on the stack named travel.
(a) Push_element(travel,NList): It takes the nested list as an argument and pushes a list object
containing name of the city and country, which are not in India and distance is less than 3500 km
from Delhi.
(b) Pop_element(travel): It pops the objects from the stack and displays them. Also, the function
should display "Stack Empty: when there are no elements in the stack.
(c) peep(travel): This function displays the topmost element of the stack without deleting it. If the
stack is empty, the function should display ‘None’.
For example:
If the nested list contains the following data:
NList=[["New York", "USA",11734],["Naypyidaw","Myanmar", 3219], ["Dubai","UAE",2194],
["London","England",6693], ["Gangtok","India",1580], ["Columbo","Sri Lanka",3405]]
The stack should contain:
["Naypyidaw","Myanmar"]
["Dubai","UAE"]
["Columbo","Sri Lanka"]
The output should be:
["Columbo","Sri Lanka"]
["Dubai","UAE"]
["Naypyidaw","Myanmar"]
Stack Empty
Ans:
NList=[["New York", "USA",11734],
["Naypyidaw","Myanmar", 3219],
["Dubai","UAE",2194],
["London","England",6693],
["Gangtok","India",1580],
["Columbo","Sri Lanka",3405]]
travel=[]
def Push_element(NList):
for L in NList:
if L[1]!='India' and L[2]<3500:
travel.append([L[0],L[1]])
def Pop_element(travel):
if travel==[]:
print("Stack Empty")

else:

Page 5 of 12
print(travel.pop())
def peep(travel):
if travel==[]:
print("Stack empty")
else:
L=len(travel)
print(travel[-1])
OR
Write a function in Python(SItem) where, SItem is a dictionary containing the details of stationary
items - {Sname:Price}.
(a) Push(SItem, Price): The function should push the names of those items in the stack who have
price greater than 75. Also display the count of elements pushed into the stack.
(b) Pop(Price): this function pops the topmost book record from the stack and returns it. If the stack
is already empty, the function should display “None”
(c) Traverse(SItem) : This function is show all element of the stack. If the stack is empty, the
function should display “Empty Stack”

For example:
If the dictionary contains the following data:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
The stack should contain
Notebook
Pen
The output should be
The count of elements in the stack is 2
Ans:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
SItem=[]
def Push(SItem,Price):
count=0
for k in Ditem:
if (Ditem[k]>=Price):
print(k)
SItem.append(k)
count=count+1

print("The count of elements in the stack is : ", count)


def Pop(SItem):
if len(SItem)==0:
print("None")
else:
print(SItem.pop())
def traverse(SItem):
if len(SItem)==0:
print("None")
else:
for i in range(len(SItem)-1,-1,-1):
print(SItem[i])

31. Predict the output of the following Python code: 3


def Bigger(N1,N2):
if N1>N2:

Page 6 of 12
return N1
else:
return N2
L=[32,10,21,54,43]
for c in range (4,0,-1):
a=L[c]
b=L[c-1]
print(Bigger(a,b),'@', end=' ')
Ans: 54 @ 54 @ 21 @ 32 @
(OR)
Predict the output of the following Python code:
tup1 = ("George", "Anderson", "Mike", "Luke", "Amanda")
list1 =list(tup1)
list2 = []
for i in list1:
if i[-1]=="e":
list2.append(i)
tup2 = tuple(list2)
print(tup2)
Ans: ('George', 'Mike', 'Luke')
SECTION D
32. As part of Fit India Campaign, Suresh has started a juice shop that serveshealthy juices. As his 1+1+2
database administrator, answer the following questions based on the data given in the table below.
Table : HEALTHYDRINKS

(i) Insert the following record into the table


DrinkCode – 107, Dname – Santara Special, Price – 25.00, Calorie – 130
Ans: INSERT INTO HEALTHDRIKS VALUES(107,’Santara Special’, 25.00,130);
(ii) Increase the price of the juices by 3% whose name begins with ‘A’.
Ans: UPDATE HEALTHDRINKS SET PRICE =PRICE+PRICE*0.03 WHERE DNAME LIKE
‘A%’;
(iii) Delete the record of those juices having calories more than 140.
Ans : DELETE FROM HEALTHDRIKS WHERE CALORIES>140;
(iv) Add a column Vitamins in the table with datatype as varchar with 20 characters.
Ans : ALTER TABLE HEALTHDRIKS ADD VITAMINS VARCHAR(20);
OR
(b) Write the output of the queries (i) to (iv) based on the table given below:
Table: Activity
PID PARTICIPANT GRADE EVENT POINTS EVENTDATE HOUSE
101 Ajay Devgan A Running 200 2022-02-03 Gandhi
102 John Abraham Hopping Bag 300 2021-12-02 Bose
103 Sunny Deol B Skipping 200 2019-09-23 Gandhi
104 Akshay Kumar A Bean Bag 250 2020-11-14 Bhagat
105 Juhi Chawla A Obstacle 350 2022-03-17 Bose

Page 7 of 12
106 MadhuriDixit Egg & Spoon 200 2021-10-15 Bose
(i) SELECT PARTICIPANT, POINTS FROM Activity ORDER BY POINTS DESC;
Ans:
PARTICIPANT POINTS
Juhi Chawla 350
John Abraham 300
Akshay Kumar 250
Ajay Devgan 200
Sunny Deol 200
MadhuriDixit 200
(ii) SELECT HOUSE, COUNT(PARTICIPANT) FROM Activity GROUPBY HOUSE;
Ans:
HOUSE COUNT(PARTICIPANT)
Gandhi 2
Bose 3
Bhagat 1
(iii) SELECT DISTINCT POINTS FROM Activity;
Ans:
POINTS
200
300
250
350
(iv) SELECT PID,EVENTDATE FROM Activity WHERE EVENT=”Running” OR
EVENT=”Skipping”;
Ans:
PID EVENTDATE
101 2022-02-03
103 2019-09-23
33. Write a function def display( ) in Python to read all the records from the file Inventory.csv which 4
stores the records of various products such as Television, Refrigerator, Air-conditioner, etc. under
different fields as mentioned below:
Code Item Company Price Quantity
T01 Television LG 43000 15
T02 Television Sony 55000 20
F01 Refrigerator LG 35000 10
(i) Now display the details of all televisions of various comparisons from the file.
(ii) Count the number of records those item quantity more than 20.

Ans:
import csv
def display():
fr=open(“Inventory.csv”, ‘r’)
reader=csv.reader()
next(reader)
count=0
print(“Code”, “Item”, “Company”, “Price”, “Quantity”, sep= “\t”)
for row in reader:
if row[1]== ‘television’:
print(row[0],row[1],row[2],row[3],row[4], sep=’\t’)
if row[4]>20:

Page 8 of 12
count=count+1
print(“the number of records those item quantity more than 20”, count)
fr.close()
34. In a Database Company, there are two tables given below: 4
Table: SALES
SALESMANID NAME SALES LOCATIONID
S1 ANITA SINGH ARIRA 250000 102
S2 Y.P. SINGH 1300000 101
S3 TINA JAISWAL 1400000 103
S4 GURDEEO SINGH 1250000 102
S5 SIMI FAIZAL 1450000 103
Table: LOCATION
LOCATIONID LOCATIONNAME
101 Delhi
102 Mumbai
103 Kolkata
104 Chennai
Write SQL queries for the following :
(i) To display SalesmanID, Name of salesman, LocationID with corresponding location names.
Ans: Select SalesmanID, Name, LocationID from Sales, Location Where
Sales.LocationID=Location.LocationID;
(ii) To display name of salesmen, sales and corresponding location names who have achieved Sales
more than 1300000.
Ans: Select Name,Sales, LocationName from Sales, Location Where
Sales.LocationID=Location.LocationID and Sales>1300000 ;
(iii) To display names of those salesmen who have ‘SINGH’ in their names.
Ans: Select Name from Sales where Name like ‘%Singh%’;
(iv) (A) Identify Primary key in the table SALES. Give reason for your choice.
Ans: SalesmanID is a primary key because Sales man information generate by Sales man ID and it is
not duplicate.
OR
(B) Write SQL command to change the LocationID to 104 of the Salesman with ID as S3 in the table
‘SALES’.
Ans: Update Sale SET LocationID=104 where SalesmanID=’S3’;
35. The code given below inserts_and_show() the following record in the table Employee: 4
Empid – integer
Name – string
salary-float
Note the following to establish connectivity between Python and MYSQL:
• Username is root
• Password is tiger
• The table exists in a MYSQL database named Empolyee.
• The details (Empid, Name, salary) are to be accepted from the user.
Ans:
import mysql.connector
def inserts_and_show():
Mydb= mysql.connector.connect(host=’localhost’, user= ‘root’, passwd= ‘tiger’,
database= ‘Employee’)
mycur=Mydb.cursor()

Page 9 of 12
sql= “Insert into Employee values (101, ‘Narain Ji Srivastava’, 50000)”
mycur.execute(sql)
Mydb.commit()
mycur.execute(“Select * from Employee”)
rows=mycur.fetchall()
for row in rows:
print(row)
mycur.close()
Mydb.close()
SECTION E
36. Python University is setting up its academic blocks at Chennai 5
and is planning to set up a network. The University has 3 academic blocks and one Human Resource
Center as shown in the diagram below:

Center to Center distances between various blocks/center is as follows:

No. of computers in each block/center is given above.


a) Suggest the most suitable place (i.e., Block/Center) to install the server ofthis University with
a suitable reason.
Ans: Ans. Most suitable place to install the server is HR center, as this centerhas maximum
number of computers.
b) Suggest an ideal layout for connecting these blocks/centers for a wired connectivity.
Ans:

c) Which device will you suggest to be placed/installed in each of these blocks/centers to


efficiently connect all the computers within these blocks/centers.
Ans.Hub / Switch
d) Suggest the placement of a Repeater in the network with justification.

Page 10 of 12
Ans. Repeater may be placed when the distance between 2 buildings is more than 100 meters.
e) The university is planning to connect its admission office in Delhi, whichis more than 1250km
from university. Which type of network out of LAN, MAN, or WAN will be formed? Justify
your answer.
Ans.WAN, as the given distance is more than the range of LAN andMAN.
37. A binary file players.dat, containing records of following list format: [code, name, country and total 5
runs]
(i)Write a python function that display all records where player name starts from 'A'
(ii)Write a python function that accept country as an argument and count and display the number of
players of that country.
(iii)Write a python function that add one record at the end of file.
Ans:
import pickle

def search():
file = open("players.dat","rb")
try:
while True:
record = pickle.load(file)
if record[1][0] == 'A':
print(record)
except EOFError:
pass
file.close()

def countRec(Country):
file = open("players.dat","rb")
count = 0
try:
while True:
record = pickle.load(file)
if record[2]==Country:
count+=1
except EOFError:
pass
return count
file.close()

def createFile_append():
file = open("players.dat","ab")
Code = int(input("Enter player code: "))
Name = input("Enter player Name: ")
Country =input("Enter player country: ")
Total_Runs = int(input("Enter total runs of player: "))
record = [Code, Name, Country, Total_Runs]
pickle.dump(record, file)
file.close()

def testProgram():
while True:
createFile_append()

Page 11 of 12
choice = input("Add more record (y/n)? ")
if choice in 'Nn':
break
print("the number of players whose name starts with A:",search())
Country = input('Enter country name to search: ')
n = countRec(Country)
print("No of players are",n)

testProgram()

Page 12 of 12

You might also like