Practical Question, CS-2024

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

AISSCE EXAMINATION – 2024

Practical Question Paper (Set-1)


School No-
Date:

Subject: Computer Science (083) Class XII Science


Time: 3:00 Hours Max. Marks: 30
Python program (60% logic + 20% documentation + 20% code quality)
Q – 1 Write the Python code for the following. [4+4=8]
a) Write a function in python that counts no of ‘Me’ or ‘My’ word present in a text
file ‘text1.txt’.

b) Write a program to create a binary file to write 10 integers, read the file and display
the sum of even integers.

Q – 2 Write the SQL queries (a) to (d) based on the relations SENDER and RECIPENT
given below: [1*4=4]

a) Display all sender names those who are belongs from the city Mumbai.
b) Display recID, SenderName, SenderAddress & Recipient City belonging from the tables.
c) Display the records of recipient table in ascending order based on RecID.
d) Display the no of recipient and city name from each city.

Q – 3 Practical Report File 7


Q – 4 Project 8
Q –5 Viva Voce 3

Internal Signature External Signature

Examiner No……….. Examiner No………..


Page 1
PYTHON CODE

Q1(A). Write a function in Python that counts the number of “Me” or “My” (in smaller
case also) words present in a text file.

# SOURCE CODE
def displayMeMy():
num=0
f=open("Mydoc4.txt","r")
N=f.read()
M=N.split()
for x in M:
if x=="Me" or x== "My":
print(x)
num=num+1
print("Count of Me/My in file:",num)
f.close()
filein = open("Mydoc4.txt",'w')
str=" "
n=int(input("enter the no of lines you want to write in a file"))
for k in range(n):
str =input("enter a line")
filein.write(str)
filein.write("\n")
filein.close()
displayMeMy()

# OUTPUT
enter the no of lines you want to write in a file2
enter a lineMe Mee My MMy Myy
enter a lineeMe Me Myy My YMy
Me
My
Me
My
Count of Me/My in file: 4

Q1(B) Write a program to create a binary file to write 10 integers, read the file and display
the sum of even integers.

#SOURCE CODE
def accept_integer(file1):
import pickle
obj=open("file1","wb")
k=0
for k in range(10):
num=eval(input("enter an integer"))
pickle.dump(num,obj)

print("Data has been written into binary file")


print("---------------------------------------")
Page 2
obj.close()

def read_integer(file1):
import pickle
obj=open("file1","rb")
val=0
try:
while True:
num=pickle.load(obj)
if num%2==0:
val+=num
except EOFError :
pass

print("Sum of all even numbers is",val)


print("------------------------------")

obj.close()

file1=input("Enter binary file name")


accept_integer(file1)
read_integer(file1)

#OUTPUT
Enter binary file namekk
enter an integer11
enter an integer23
enter an integer5
enter an integer4
enter an integer9
enter an integer7
enter an integer8
enter an integer12
enter an integer22
enter an integer13
Data has been written into binary file
---------------------------------------
Sum of all even numbers is 46

Page 3

You might also like