[go: up one dir, main page]

0% found this document useful (0 votes)
20 views13 pages

QP_HLY_XII_2024_25_CS_ANS (1)

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

QP BY SOMNATH PAULCHOUDHURY

CLASS XII SC
SUB: COMPUTER SCIENCE (083)
Time allowed -3 hours Max Marks- 70
==============================================================================
General Instructions:
• Please check this question paper contains 37 questions.
• The paper is divided into 5 Sections- A, B, C, D and E.
• Section A, consists of 21 questions (1 to 21). Each question carries 1 Mark.
• Section B, consists of 7 questions (22 to 28). Each question carries 2 Marks.
• Section C, consists of 3 questions (29 to 31). Each question carries 3 Marks.
• Section D, consists of 4 questions (32 to 35). Each question carries 4 Marks.
• Section E, consists of 2 questions (36 to 37). Each question carries 5 Marks.
• All programming questions are to be answered using Python Language only
Q No Section A 21 Marks
1 State True/False 1
We cannot use the keyword return in a nested for loop which is not a part of any user
defined function.
2 In MySQL a table example stores the attributes fixed of char(10) and attribute variable 1
of varchar(10). Two records are added and displayed as shown.
10,3

Find the output of the following command


mysql> select length(fixed), length(variable) from example;
3 Find the output of the following 1
2**3**2+10//2//5
a) 513.0 b) 65.0 c) 65 d) 513
4 Find the correct option 1
str="Python for Artificial Intelligence"
y=str.split()
newstr="#".join([y[1].upper(),y[3].capitalize()]); print(newstr)
newstr="#".join([y[2].upper()+y[2].capitalize()]);print(newstr)
FOR#Intelligence ARTIFICIAL#Intelligence
a ARTIFICIAL#Artificial b ARTIFICIALIntelligence
FOR#Intelligence ARTIFICIAL#Intelligence
c ARTIFICIALArtificial d ARTIFICIAL#Intelligence
5 If a table P in MySQL database is having 3 rows and 5 columns and the table Q is 1
having 2 rows and 2 columns, the cartesian product of P and Q will have number of
columns and rows as
a) 6, 8 b) 7,6 c) 8,6 d) 7,8
6 Yoyo wants to transfer some pictures from her mobile phone to her friend’s laptop but 1
right now they don’t have access to the Internet. Select the option(s) from below that
will help her to transfer the files immediately
a) Google Drive b) OTG c) Bluetooth d) Email
7 D={1:2,3:4,5:6} is a dictionary we can remove the key value pair 5:6 by, select option(s) 1
a b c d
del D[5] D.pop() del D[6] D.pop(6)
8 Consider the string, spstr= "common circuits" 1
Find the output of, spstr[-8:-4:3] from the options below
a) 'ci o' b) 'cric no' c) 'ci ' d) 'cc'
9 Consider the tuple t in the Python statement, t=(10,20,30,40,50,60) 1
Identify from the options below that will not change the size of the tuple.
a b c d
t + ( t[ 2: ] ,) t + (t[ -3 : -5 ]) t + (t[ 2: ]) t + (t[ -5 : -3 ])
10 Which output(s) cannot be displayed on screen at the time of execution 1
of the program from the following code? Select correct options from below.
import random
arr=['10','30','40','50','70','90','100']
L=random.randint(0,3)
U=random.randrange(3,5)
for i in range(L,U+1):
print(arr[i],"#",end=" ")

a) b)
30 # 40 # 50 # 10 # 30 # 40 # 50 # 70 #

c) d)
10 # 30 # 40 # 50 # 70 # 90 # 50 # 70 # 90 # 100 #

11 In which layer of ISO model, a hub is connected? 1


a) Data Link b) Network c) Physical d) Transport
12 What is stored in s? 1
X=202
def tweet():
global X
X-=180
return X
s=tweet()
a) 180 b) 0 c) 20 d) 22
13 Look at the code below and identify the type of exception that will be thrown from the 1
options after the sentence is entered instead of age
str=int(input("Enter your age :"))
Enter your age : to be able to laugh at yourself is maturity
a) RuntimeError b) IndexError c) OverflowError d) ValueError
14 Identify the FALSE relational database statement from the options below. 1
a) ALTER statement can update a record in a table
b) DROP statement can be used for both tables and databases
c) DESCRIBE statement will display the table structure
d) There can be many Candidate keys in a table.
15 Write True/False 1
In message switching there is no limit on block size.
16 The byte position returned by seek() method in data file program statements indicates 1
position from
f=open('story1.txt','rb') #opening a txt file in binary mode
f.seek(-10,2)
a) Middle b) Start c) End d) Random
Q17 and 18 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
17 Assertion (A): If value of an element of list data is updated the memory address of the 1
element also changes. (a)
Reason (R): List is mutable data in Python.
18 Assertion (A): Importing modules in Python allows access to their defined functions and 1
variables. (a)
Reason(R): When a module is imported using the ‘import’ statement, it grants access to
all the functions, classes, and variables defined within that module.
19 Identify the output of the following code snippet:
text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)
(a) #THONPROGRAM
(b) ##THON#ROGRAM
(c) #THON#ROGRAM
(d) #YTHON#ROGRAM
20 What is the output of the expression?
str='International'
print(str.split("n"))
(a) ('I', 'ter', 'atio', 'al')
(b) ['I', 'ter', 'atio', 'al']
(c) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
(d) Error
21 What will be the output of the following code?
tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)
(a) True
(b) False
(c) tuple1
(d) Error
Section B 14 Marks
22 (i) Expand the following terms: 1+1=
VPN, DNS 2
Virtual Private Network
Domain Name System
(ii) Give one difference between HTML and CSS
HTML provides the basic structure of a webpage. CSS is all about style and
presentation. It controls how web pages look.

OR
(i) Name the Full-Stack Framework for Python Django

(ii) What is an API? Application Programming Interface, APIs enable different


software components to talk to each other. Eg Google Map API

23 The following code consists of errors both syntax and logical errors. Your task is to 2
identify and underline the errors and also write the correction beside.
a=10
b=5
for=3
res=a-c
if a>b
print("a is greater than b")
if a=b:
print("a is equal to b")

for=3 cannot use keyword as identifier


res=a-c, c is not defined will give NameError

if a>b: colon missing


elif a==b: requires comparison operator

Corrected code can be as


a=10
b=5
c=3
res=a-c
if a>b:
print("a is greater than b")
elif a==b:
print("a is equal to b")
24 CBG is a dictionary that is storing the name of the country and their respective Central 2
Banks Governor’s name as shown below.
CBG={"Germany":"JoachimNagel","France":"FrançoisVilleroy de
Galhau","India":"ShaktikantaDas","UnitedKingdom":"AndrewBailey","UnitedStates":"Jer
ome Powell"}
Write a function getNames(CBG) that will take the dictionary as its parameter and will
display only those country names if the Governor’s name has both the characters ‘e’
and ‘i’ present.

CBG={"Germany":"JoachimNagel","France":"FrançoisVilleroy de
Galhau","India":"ShaktikantaDas","UnitedKingdom":"AndrewBailey","UnitedStates":"Jer
ome Powell"}
def getNames(CBG):
for k,v in CBG.items():
if v.find('e')>=0 and v.find('i')>=0:
print(k)

getNames(CBG) #function call and output below


Germany
France
UnitedKingdom

OR
Consider the string G20 below
G20="African Union is a new member of the G20"
Write a function lenWords(G20) that takes the string as it’s parameter and return the
length of each word of the string as a tuple in descending order in the tuple.
G20="African Union is a new member of the G20"
def lenWords(G20):
L=[]
str=G20.split()
for i in str:
L.append(len(i))
L.sort(reverse=True)
return tuple(L)

lenWords(G20)
(7, 6, 5, 3, 3, 3, 2, 2, 1)

25 Find the output of the code 2


S="eComPhyMat"
L=["C","a","r","e","e","r","F","a","i","r"]
for i in range(len(S)):
if i%2==0:
D[L.pop()]=S[i]
else:
D[L.pop()]=i+5

for x,y in D.items():


print(x,y,sep="#")

D={} is a dictionary

r#12
i#6
a#a
F#8
e#y
C#14

26 Using built in functions 2


i. add another alphabet ‘e’ after the alphabet ‘e’ in the list

L=['a','e','i']
n=L.index('e')
n
1
L.insert(n+1,'e')
L
['a', 'e', 'e', 'i']

ii. Check if the string S="ePalZor" ends with the alphabet ‘r’

S="ePalZor"
S.endswith('r')
True

OR
Consider the string mystr,
mystr="Referential Integrity is enforced by the Alternate keys"
Write code in Python to find the number of unique alphabets present in the string.

mystr="Referential Integrity is enforced by the Alternate keys"


c=[]
for i in mystr:
c.append(i)

c
['R', 'e', 'f', 'e', 'r', 'e', 'n', 't', 'i', 'a', 'l', ' ', 'I', 'n', 't', 'e', 'g', 'r', 'i', 't', 'y', ' ', 'i', 's', ' ', 'e', 'n', 'f',
'o', 'r', 'c', 'e', 'd', ' ', 'b', 'y', ' ', 't', 'h', 'e', ' ', 'A', 'l', 't', 'e', 'r', 'n', 'a', 't', 'e', ' ', 'k', 'e', 'y', 's']
c=set(c)
len(c)
21
c
{'f', 'A', 'I', 'g', 'l', 'n', 'o', 'h', 'y', 'a', 'i', 's', 'R', ' ', 't', 'b', 'k', 'r', 'c', 'e', 'd'}

27 In the existing MySQL table admin with the fields code, gender, designation add the 2
primary key icode of integer type in the beginning.

ALTER TABLE admin ADD COLUMN icode INT PRIMARY KEY FIRST;

OR
From the MySQL table admin with the fields icode, code, gender, designation
i. drop the field designation

ALTER TABLE admin DROP COLUMN designation;

ii. add a new column department of varchar any suitable size. Make sure it cannot
remain a blank entry.

ALTER TABLE admin ADD COLUMN department VARCHAR(50) NOT NULL;

28 Find the output of the following 2


def anher(x,y=10):
x=x/y
y=x%y
return x

m=200
n=20
m=anher(m,n)
print(m,n,sep="#")
n=anher(n)
print(m,n,sep="#",end="$$$")

10.0#20
10.0#2.0$$$
Section C 9 Marks
29 Find the output of the Python code below 3
ATA-*34

30 Consider the table itemmast below, write the output of the MySQL queries 3

i. select count(distinct suppdate) from itemmast; 2


ii. select itemname, stock from itemmast where itemprice>100 and itemname like
'%gm';
itemname stock
amul butter 500 gm 40
amul paneer 200 gm 105

iii. select itemname, stock from itemmast where suppdate<'2024-09-17' and stock
between 40 and 100;

itemname stock
amul butter 500 gm 40
amul paneer 100 gm 60

OR

Look at the table structure of itemmast table and write the MySQL queries

i. Drop the Primary key


ALTER TABLE itemmast DROP PRIMARY KEY;
ii. Increase itemprice for each by 10%
UPDATE itemmast set price=price*1.1;
iii. Delete the records where itemprice is more than 200
DELETE FROM itemmast where price>200;
31 Code in Python to read a text file Gratitude.txt and displays those lines that contains 3
the string ‘thank’

e.g. gratitude.txt file in working directory

import os
os.chdir(r'c:\py01')
file=open("gratitude.txt","r")
s=file.read()
s=s.splitlines()
s
["Gratitude is a humble heart's radiant glow, A timeless gift to thank ", "that nurtures and
bestows. It's the appreciation for the love we're", "shown, In moments big and small, it's
truly known, thank you for the", 'warmth that fills our days, For kindness shared in
countless ways.']
for i in s:
if 'thank' in i.lower():
print(i)

Gratitude is a humble heart's radiant glow, A timeless gift to thank


shown, In moments big and small, it's truly known, thank you for the

OR
Write a function VowelC() that counts the number of vowels from the text file
Gratitude.txt and displays the total vowel count.

def VowelC():
import os
os.chdir(r'c:\py01')
file=open("gratitude.txt","r")
s=file.read()
c=0
for i in s:
if i in 'aeiouAEIOU':
c+=1
return c

VowelC()
73

Section D 16 Marks
32 Write a Python program that reads a text file and copies all the words in another file if 4
the word starts with a vowel letter.
import os
os.chdir(r'c:\py01')
file=open("gratitude.txt","r")
file1=open("vowelswords.txt","w")
s=file.read()
s=s.split()
s
['Gratitude', 'is', 'a', 'humble', "heart's", 'radiant', 'glow,', 'A', 'timeless', 'gift', 'to', 'thank',
'that', 'nurtures', 'and', 'bestows.', "It's", 'the', 'appreciation', 'for', 'the', 'love', "we're",
'shown,', 'In', 'moments', 'big', 'and', 'small,', "it's", 'truly', 'known,', 'thank', 'you', 'for',
'the', 'warmth', 'that', 'fills', 'our', 'days,', 'For', 'kindness', 'shared', 'in', 'countless', 'ways.']
for i in s:
if i[0] in 'AEIOUaeiou':
file1.write(i+' ')

file.close()
file1.close()
file1=open("vowelswords.txt","r")
ss=file1.read()
ss
"is a A and It's appreciation In and it's our in "

OR

I. When is ZeroDivisionError exception raised in Python?

If we try to divide a number by Zero


9/0
ZeroDivisionError: division by zero

II. Give an example code to handle ZeroDivisionError? The code should display
the message "Division by Zero is not allowed" in case of ZeroDivisionError
exception, and the message "Some error occurred" in case of any other
exception.

try:
import random
m=5
n=random.randint(0,1)
print(m/n)
print(menoka)
except ZeroDivisionError:
print("Division by Zero is not allowed")
print(n)
except:
print("Some error occurred")

5.0
Some error occurred
try:
import random
m=5
n=random.randint(0,1)
print(m/n)
print(menoka)
except ZeroDivisionError:
print("Division by Zero is not allowed")
print(n)
except:
print("Some error occurred")

Division by Zero is not allowed


0

33 A list, items contain following record as list elements [itemno, itemname, stock]. 4
Each of these records are nested to form a nested list.
Write the following user defined functions to perform the following on a stack reorder
i. Push(items) it takes the nested list as its argument and pushes a list object
containing itemno and itemname where stock is less than 10
ii. Popitems() It pops the objects one by one from the stack reorder and also
displays a message ‘Stack empty’ at the end.

reorder=[]
items=[[101,'mouse',3],[102,'keyboard',5],[103,'PC',100]]
def Push(items):
for i in items:
if i[2]<10:
reorder.append([i[0],i[1]])

Push(items)
reorder
[[101, 'mouse'], [102, 'keyboard']]
def Popitems():
try:
while True:
print(reorder.pop())
except IndexError:
print("Stack empty")

Popitems()
[102, 'keyboard']
[101, 'mouse']
Stack empty
34 A csv file hardware.csv stores details as [h_id, h_name, price] where 4
h_id is hardware id(integer)
h_name is hardware name(string)
price is hardware price(integer)
Write functions as
add() : to accept from user and add to the csv file hardware.csv
ccount() : to count no of records in hardware.csv having price less than 5000

import os
os.chdir(r'c:\py01')
import csv
csv_file="hardware.csv"
def add():
try:
h_id = int(input("Enter hardware ID: "))
h_name = input("Enter hardware name: ")
price = int(input("Enter hardware price: "))

with open(csv_file, 'a', newline='') as csvfile:


writer = csv.writer(csvfile)
writer.writerow([h_id, h_name, price])
print("Record added successfully!")
except ValueError:
print("Invalid input. Please enter valid integer values for ID and price.")

add()
Enter hardware ID: 101
Enter hardware name: AC External Unit
Enter hardware price: 26000
Record added successfully!
add()
Enter hardware ID: 102
Enter hardware name: Stabilizer
Enter hardware price: 2300
Record added successfully!

def ccount():
try:
count = 0
with open(csv_file, 'r') as csvfile:
reader = csv.reader(csvfile)
#next(reader) # Skip header row if you have one
for row in reader:
if int(row[2]) < 5000:
count += 1
print(f"Number of records with price less than 5000: {count}")
except FileNotFoundError:
print(f"File '{scv_file}' not found. Please create the file first.")

ccount()
Number of records with price less than 5000: 1

35 Write a Python program using mysql connector to display all columns from a table 4
itemmast under item database (both exists) and display all records from itemmast. The
program will update the table by changing the price of an item and finally display the
altered updated records.

import mysql.connector
spcdatabase=mysql.connector.connect(
user='root',
host='localhost',
database='item',
password='hahanana'
)
spccur=spcdatabase.cursor()
spccur.execute("select * from itemmast")
for i in spccur:
print(i)

(100, 'amul butter 500 gm', 40, 238, '2024-09-16')


(101, 'amul butter 100 gm', 60, 48, '2024-09-16')
(102, 'amul gold 1 litre', 100, 85, '2024-09-17')
(103, 'amul paneer 200 gm', 105, 105, '2024-09-17')
spccur.execute("update itemmast set price=49 where itemno=101")
spcdatabase.commit()
spccur.execute("select * from itemmast")
for i in spccur:
print(i)

(100, 'amul butter 500 gm', 40, 238, '2024-09-16')


(101, 'amul butter 100 gm', 60, 49, '2024-09-16')
(102, 'amul gold 1 litre', 100, 85, '2024-09-17')
(103, 'amul paneer 200 gm', 105, 105, '2024-09-17')
Section E 10 Marks
36 CPS.DLROW is a research facility in Aurach in Kitzbühel Austria that pioneers in 1*5=5
promoting world class electronic gadgets that can withstand subfreezing temperature
and can be installed in remote facilities throughout the world.

A rough sketch of the campus is shown here with some additional parameters. You
have to answer the subsequent queries based on it

Distance in meters
LAB1 to LAB2 68 m , LAB1 to WAREHOUSE 28 m , LAB1 to PRODUCTION 45 m
LAB2 to PRODUCTION 100 m , LAB2 to WAREHOUSE 18 m
WAREHOUSE to PRODUCTION 95 m

NO of Interconnected devices (as PCs etc)


PRODUCTION 24 , LAB1 88 , LAB2 20 , WAREHOUSE 16
a. Where can we place the Server? LAB1
b) Draw a star topology in connecting the campus emanating from the place where
Server is housed. Drawing in the diagram shown
c) What device can be used to connect the PCs in any of the facilities? Switch
d) How to connect economically this campus in Austria with the one located in
Germany? Use 5G Internet Services from a service provider in Austria
e) Where the firewall should be placed in the campus? LAB1
37 Write the MySQL queries for i to iii and outputs for iv and v taking into consideration the 5
tables shown below

i. To drop the column rem in orders table


ALTER TABLE orders DROP COLUMN rem;
ii. To find the sum of the totval for the day 2022/11/26
SELECT SUM(totval) AS total_value
FROM orders
WHERE order_date = '2022-11-26';
iii. Display all suppname from suppliers having the alphabet ‘o’
SELECT suppname
FROM suppliers
WHERE suppname LIKE '%o%';
iv. select distinct suppid from suppliers natural join orders;
suppid
-------
101
102
103
104
v. select orddt from orders order by orddt desc;
orddt
---------
2022/11/26
2022/11/26
2022/11/25
2022/11/25
2020/11/24

You might also like