Practical Question, CS-2024
Practical Question, CS-2024
Practical Question, CS-2024
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.
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)
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
obj.close()
#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