AISSCE XII Computer Science 083 – Practical Question Paper Set #3 – Download Word File
All India Senior Secondary Certificate Examination
XII Computer Science 083 – Practical Question Paper Set #3
Answer Key of Set 3 Practical Examination Question Paper
Answer Key Set – 3
Q1. LAB TEST [8+4=12]
A. 1) Write a function in Python that counts the number of “Me” or “My” words present in a text file “STORY.TXT” (4)
Answer:
#Creating a Text File - story.txt
fout = open("story.txt", 'w')
fout.write("my me our this that \n")
fout.write("here there me my me \n")
fout.write("my website is www.anjeevsinghacademy.com \n")
fout.close()
# Solution of Que A. 1
#-----------------------------------
#checking and counting "Me" or "My"
fin = open("story.txt", "r")
text = fin.read()
count = 0
for word in text.split():
if word.lower() == 'me' or word.lower() == 'my':
count += 1
print("Number of times 'me' or 'my' are : ", count)
fin.close()
Output:
Number of times ‘me’ or ‘my’ are: 6
2) Write function WritesStudent() to write the Records of Students (admno, name, fee) in a binary file name “stud.dat”, and Write function Display() those records from a binary which fee is less than 1500.
Answer:
# Solution of Que 2
#-----------------------------------
# Binary file
import pickle
def WriteStudent():
fout = open("Stud.dat", "wb") # opening of file
while True:
rec = []
admno = int(input("Enter Admission Number : "))
name = input("Enter Name : ")
fee = float(input("Enter Fee : "))
rec = [admno, name, fee]
pickle.dump(rec, fout) #write one record in a file refered by fout
wish = input("Wish to add more records y/n ")
if wish.lower() != 'y':
break
fout.close()
def Display():
fin = open("Stud.dat", "rb")
try:
while True: # loop is required to read all records
rec = pickle.load(fin) # read only one record
# at a time refered by fin file object
if rec[2] < 1500 :
print(rec[0], rec[1], rec[2])
except:
fin.close()
#__ main ___ block
print("Writing Records in Stud.dat")
WriteStudent()
print("Reading Records from Stud.dat")
Display()
Output:
Writing Records in Stud.dat
Enter Admission Number : 1
Enter Name : Anjeev
Enter Fee : 1500
Wish to add more records y/n y
Enter Admission Number : 2
Enter Name : Ravi
Enter Fee : 1200
Wish to add more records y/n y
Enter Admission Number : 3
Enter Name : Sona
Enter Fee : 500
Wish to add more records y/n n
Reading Records from Stud.dat
2 Ravi 1200.0
3 Sona 500.0
OR
Write a function LShift(Arr, n) in Python, which accepts a list Arr of numbers and n is a numeric value by which all elements of the list are shifted to left. (4)
Sample Input Data of the list : Arr= [ 10,20,30,40,12,11], n = 2
Output : Arr = [30,40,12,11,10,20]
Answer:
# Solution of Que 2 (OR)
#--------------------------
# LShift
Arr = [10, 20, 30, 40, 12, 11]
def LShift(Arr, n):
length = len(Arr)
for i in range(n): # Number of times repeat one LShift
temp = Arr[0]
for j in range(1, length): # One Left Shfit
Arr[j-1] = Arr[j]
Arr[length - 1] = temp
n = 2
print("Before LShift")
print(Arr)
LShift(Arr, n)
print("After LShift",n,"times")
print(Arr)
Output:
Before LShift
[10, 20, 30, 40, 12, 11]
After LShift 2 times
[30, 40, 12, 11, 10, 20]
B. A table Drug is created in the database Medicine. The details of table are given below. (4)
import mysql.connector as sqltor
mycon = sqltor.connect( ___________________ ) #1
cursor = mycon.cursor( )
cursor.execute(______________________ ) #2
data = _________________ #3
for rec in data:
print ( rec )
_____________________ #4
mycon.close( )
a. Complete the statement #1 to write appropriate missing parameter and values.
b. Write the statement #2, to fetch drugName and price from table Drug in descending order of price.
c. Complete the statement #3, to fetch only three records from the resultset.
d. What statement you will write in place of statement #2 to insert one more record in table Drug, as well as in statement #4, to make your changes permanent in the table Drug.
Answer:
a) host = “localhost”, user = “root”, passwd = “123”, database = “Medicine”
b) SELECT drugname, price FROM drug ORDER BY price DESC;
c) cursor.fetchmany(3)
d) Statement#2 -> INSERT INTO drug VALUES (‘R1005’, 5612, ‘BEOCSULE’,25.00, ‘OXFORD’, ‘DELHI’)
Statement#4 -> mycon.commit()