QP_HLY_XII_2024_25_CS_ANS (1)
QP_HLY_XII_2024_25_CS_ANS (1)
QP_HLY_XII_2024_25_CS_ANS (1)
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
a) b)
30 # 40 # 50 # 10 # 30 # 40 # 50 # 70 #
c) d)
10 # 30 # 40 # 50 # 70 # 90 # 50 # 70 # 90 # 100 #
OR
(i) Name the Full-Stack Framework for Python Django
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")
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)
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)
D={} is a dictionary
r#12
i#6
a#a
F#8
e#y
C#14
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.
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
ii. add a new column department of varchar any suitable size. Make sure it cannot
remain a blank entry.
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
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
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)
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
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")
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: "))
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)
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