Class 12 Computer Science
Class 12 Computer Science
SECTION A
3. (b) r 1
5. Output: 4 1
6. c) def correct(a=1,b=2,c=3) 1
8. (c) 1
9. (b) 1
SECTION B
10. Ans: 2
“w” is used to write in file from the beginning. If file already exists, then it will
overwrite the previous content.
“a” (append – add at the end ) is also used to write in file. If file already exists
it will write after the previous content i.e. it will not overwrite the previous
content and add new content after the existing content
11. Ans: 2
Output
300 @ 200
300 @ 100
120 @ 100
300 @ 120
13. 2
SECTION C
14. Ans: 3
15. Ans: 3
def COUNTLINES():
file=open('STORY.TXT','r')
lines = file.readlines()
count=0
for w in lines:
if w[0]=="A" or w[0]=="a":
count=count+1
print(“Total lines “,count)
file.close()
or
def displayMeMy():
num=0
f=open("story.txt","rt")
N=f.read()
M=N.split()
for x in M:
if x=="Me" or x== "My":
print(x)
num=num+1
f.close()
print("Count of Me/My in file:",num)
16. Ans: 3
def INDEX_LIST(L):
indexList=[]
for i in range(len(L)):
if L[i]!=0:
indexList.append(i)
return indexList
SECTION D
17. Ans: 4
import csv
def add():
fout=open("furdata.csv","a",newline='\n')
wr=csv.writer(fout)
fid=int(input("Enter Furniture Id :: "))
fname=input("Enter Furniture name :: ")
fprice=int(input("Enter price :: "))
FD=[fid,fname,fprice]
wr.writerow(FD)
fout.close()
def search():
fin=open("furdata.csv","r",newline='\n')
data=csv.reader(fin)
found=False
print("The Details are")
for i in data:
if int(i[2])>10000:
found=True
print(i[0],i[1],i[2])
if found==False:
print("Record not found")
fin.close()
add()
print("Now displaying")
search()
SECTION E
def findBook(price):
with open('BOOK.DAT', 'rb') as file:
while True:
try:
book_record = pickle.load(file)
for item in book_record:
book_price = book_record[item][2]
if book_price >= price:
print(item, book_record[item])
except EOFError:
break
findBook(50)