0% found this document useful (0 votes)
147 views

SQP 03 - QP

Uploaded by

Aadilsha M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

SQP 03 - QP

Uploaded by

Aadilsha M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

PRE-BOARD EXAM– 1

MARKING SCHEME
CLASS - XII MAX. MARKS: 70

SUBJECT : COMPUTER SCIENCE TIME : 3 HRS.

_________________________________________________________________________________________

SECTION A
1. State True or False : 1
Python does not allows same variable to hold different data literals / data types.

Ans : False
2. Which of the following datatype in python is used to represent any real number : 1
(a) int , (b) complex , ( c ) float , (d ) bool

( c ) float
3. 1
Given the following list
place=[ (“State” , ”Sikkim”), (“Population”, ”8 Lakh”) ]
which of the following method will turn the above list place into something like
{ “State” : “Sikkim” , “Population” : “8 Lakh” }
when applied over it :
a. dictionary( )
b. to_dict( )
c. dict( )
d. Items( )

c. dict( )

4. Consider the given Expression : 1


5 == True and not 0 or False
Which of the following will be the correct output if the given expression is evaluated?
a. True
b. False
c. NONE
d. NULL

b. False

5. Select the correct output of the code : 1


n = "Post on Twitter is trending"
q = n.split('t')
print( q[0]+q[2]+q[3]+q[4][1:] )

a. Pos on witter is rending


b. Pos on Twitter is ending
c. Poser witter is ending
d. Poser is ending

d) Poser is ending
6. Which of the following mode in file opening statement does not overwrites the any previous 1
content of the file ?
a. w+ b. r+ c. a+ d. None of the above

c. a+

7. ___________ command is used to a remove a tuple or many tuple(s) from a table / relation 1
in SQL

(a) drop (b)delete (c) remove (d) alter

b. delete
8. Which of the following commands will remove a particular table’s schema along with its data 1
, contained in a MySQL database?
a. DROP DATABASE
b. ALTER TABLE
c. DELETE FROM TABLE
d. DROP TABLE

c. DROP TABLE
9. Which of the following statement(s) would give an error after executing the following code? 1
EM = “Blue Tick will cost $8” # Statement 1
print( EM) # Statement 2
ME = “Nothing costs more than Truth” # Statement 3
EM *= 2 # Statement 4
EM [-1: -3 : -1] += ME[ : 7] # Statement 5

a. Statement 3
b. Statement 4
c. Statement 5
d. Statement 4 and 5

c.Satement 5
10. ……………………is an attribute, which is not a primary key of a table but has a capability of 1
becoming a primary key.

a. Primary Key
b. Foreign Key
c. Candidate Key
d. Alternate Key

c.Candidate Key
11. The seek( 8 ) if applied to a text file stream object moves the read cursor/ pointer : 1

a. 8 characters backwards from its current position


b. 8 characters backward from the end of the file
c. 8 characters forward from its current position
d. 8 characters forwarded from the beginning of the file

d. 8 characters forwarded from the beginning of the file

12. To restrict repeated values from being entered under a column of table, while creating the 1
table in MySQL we take help of which of the following :

a. DESCRIBE
b. NULL
c. PRIMARY KEY
d. DISTINCT

b. PRIMARY KEY
13 ……………………is a communication methodology designed to establish a direct and dedicated 1
communication between an internet user and his/her ISP.

(a) VoIP (b) SMTP (c) PPP (d)HTTP

c. PPP

14. What will the following expression be evaluated to in Python? 1


print( ( - 33 // 13) * (35 % -2)* 15/3)

a. 10.0
b. -15.0
c. 15.0
d. -10.0
c. 15.0
15. Which function is not an aggregate function ? 1

a. sum()
b. total()
c. count()
d. avg()

b. total( )
16. Which of the following method is needed to create an object using whose method a query 1
is executed from python’s front end connected to a mysql database.
a. cursor( )
b. execute( )
c. Connect( )
d. fetchall( )

a. cursor( )
Q17 and 18 are ASSERTION AND REASONING based questions.
Mark the correct choice as
i. Both A and R are true and R is the correct explanation for A
ii. Both A and R are true and R is not the correct explanation for A
iii. A is True but R is False
iv. A is false but R is True
17. Assertion(A):Key word arguments are related to the function calls 1

Reason(R): When you use keyword arguments in a function call, the caller identifies the
arguments by the parameter name

i. Both A and R are true and R is the correct explanation for A

18. Assertion (A): - The acronym for a CSV File is “ Comma Separated Value” 1

Reasoning (R):- Since the seprator symbols between data elements with a line should
always be a comma hence the name CSV originated.

iii. A is True but R is False


SECTION B
19. Mithilesh has written a code to input a number and evaluate its factorial and then finally 2
print the result in the format : “The factorial of the <number> is <factorial value>” His code
is having errors. Rewrite the correct code and underline the corrections made.

f=0
num = input("Enter a number whose factorial you want to evaluate :")
n = num
while num > 1:
f = f * num
num -= 1
else:
print("The factorial of : ", n , "is" , f)

Ans :

1. f =1 # f is wrongly initialized to 0
2. int( ) must be used with input( )
3. else part of while should be properly indented
4. print("The factorial of : ", n , "is" , f)
Hence the correct code will be :

f=1
num = int(input("Enter a number whose factorial you want to evaluate :"))
org_num = num
while num > 1:
f = f * num
num -= 1
else:
print("The factorial of : ", org_num , "is" , f)

20. 2
Write any one point of difference between
i. Circuit Switching and Packet Switching.
ii. Co-axial cable and Fiber – optic cable
OR
Write two points of difference between Bus and Star Topologies.

1 marks each for any two correct differences

21. a. Given is a Python string declaration: 2


Wish = "## Wishing All Happy Diwali @#$"
Write the output of Wish[ -6 : : -6 ]

Ans : lyli#

b. Write the output of the code given below :


Emp = { "SMITH":45000 , "CLARK":20000 }
Emp["HAPPY"] = 23000
Emp["SMITH"] = 14000
print( Emp.values() )

Ans : dict_values([14000, 20000, 23000]) or [14000,20000,23000]


22. Explain the use of ‘Foreign Key’ for performing table Joins, giving a suitable example to 2
support your answer.
1 mark to make role of Foreign Key clear in joining tables + 1 marks for example

23. a. Write the full form of : 2


 HTML
 VoIP
b. What do you mean by a URL ?

Ans a. HTML – HYPER TEXT MARKUP LANGUALGE (½+½)


VoIP – VOICE OVER INTERNET PROTOCOL
b. URL – UNIFORM RESOURCE LOCATER or Any correct definition award 1 mark.
24. def Compy(N1,N2=10): 2
return N1 > N2

NUM= [10,23,14,54,32]
for VAR in range (4,0,-1):
A=NUM[VAR]
B=NUM[VAR-1]
if VAR > len(NUM)//2:
print(Compy(A,B),'#', end=' ')
else:
print(Compy(B),'%',end=' ')

Ans : False # True # True % False %

OR

tuple1 = ( [7,6], [4,4], [5,9] , [3,4] , [5,5] , [6,2] , [8,4])


listy = list( tuple1)
new_list = list()
for elem in listy :
tot = 0
for value in elem:
tot += value
if elem.count(value) == 2:
new_list.append(value)
tot = 0
else:
print( tuple(new_list) )

Ans : ( 4,4,5,5)
25. Differentiate between ‘WHERE’ clause and ‘HAVING’ clause in MySQL with appropriate 2
example.
OR

Differentiate between DELETE and DROP keywords used in MySQL,giving suitable example
for each
Correct difference one mark
Correct example one mark
SECTION C
26. (a) Consider the following tables – Bank_Account and Branch: 1+2
BANK_ACCOUNT
E_CODE NAME
E01 ASHISH
E02 SURESH

BRANCH
E_CODE LOCATION
E05 MUMBAI

What will be the output of the following statement?


SELECT * FROM Bank_Account, Branch;

Ans :
+--------+--------+--------+----------+
| e_code | name | e_code | location |
+--------+--------+--------+-----------+
| E01 | ASHISH | E05 | MUMBAI |
| E02 | SURESH | E05 | MUMBAI |
+--------+--------+--------+------------+
(1 mark for correct output)

(b) Write the output of the queries (i) to (iv) based on the table, TECHER given below:

TEACHER
TCODE TNAME SUBJECT SEX SALARY
5467 Narendra Kumar Computer Science M 70000
6754 Jay Prakash Accountancy M Null
8976 Ajay Kumar Chemistry M 65000
5674 Jhuma Nath English F 55000
8756 Divya Bothra Computer Science F 75000
6574 Priyam Kundu Physics M Null
3425 Dinesh Verma Economics M 71000

i) SELECT DISTINCT(SUBJECT) FROM TEACHER WHERE SALARY IS NOT NULL;


ii) SELECT SUBJECT , COUNT(*) AS TOT_FACUL FROM TEACHER GROUP BY SUBJECT
HAVING TOT_FACUL > 1
iii) SELECT TNAME FROM TEACHER WHERE SEX = ‘M’ AND
SALARY >= 70000 ORDER BY TCODE
iv) SELECT MAX(SALARY) FROM TEACHER WHERE TCODE IN (5467,8976,3425) AND
SUBJECT LIKE ‘C%’

Ans:I)
SUBJECT
Computer Science
Chemistry
English
Economics

II)

SUBJECT TOTA_FACUL
Computer Science 2

III)

TNAME
Dinesh Verma
Narendra Kumar

IV)
MAX(SALARY)
70000
( ½ mark for the correct output)
27. Write a function COUNTLINES( ) which reads a text file STORY.TXT and then count and 3
display the number of the lines which starts and ends with same letter irrespective of its
case . For example if the content of the text file STORY.TXT is :

The person has a sent a lovely tweet


Boy standing at station is very disturbed
Even when there is no light we can see
How lovely is the situation

The expected output is :

The Number of lines starting with same letter is 2

Ans :
def COUNTLINES():
fin = open("Story.txt", 'r')
lines = fin.readlines()
count = 0
for line in lines:
if line[0].lower() == line[-1].lower():
count+=1
else:
print("The Number of lines starting with same letter is",count)
fin.close()

( ½ mark for correctly opening and closing the file ½ for readlines() , ½ mark for correct loop
½ for correct if statement, ½ mark for correctly incrementing count , ½ mark for displaying
the correct output)
OR

Write a function VOWEL_WORDS which reads a text file TESTFILE.TXT and then count and
display the number of words starting with vowels ‘a’ or ‘u’ (including capital cases A and U
too)
For example is the text in the file TESTFILE.txt is :

The train from Andaman has earned the name ‘Floating Train’. What is so unique about this
train to receive such a name?

The expected output is :

The Number of words starting with letter ‘a’ is : 3


The Number of words starting with letter ‘u’ is : 1

Ans :
def VOWEL_WORDS():
fin = open("TESTFILE.TXT" , 'r')
content = fin.read()
words = content.split()
acount,ucount = 0,0
for word in words:
if word[0] in "aA":
acount+=1
if word[0] in "uU":
ucount+=1
else:
print("The Number of words starting with letter ‘a’ is :",acount)
print("The Number of words starting with letter ‘u’ is :",ucount)

VOWEL_WORDS()

(½ mark for correctly opening and closing the file, ½ for readlines() , ½ mark for correct
loops, ½ for correct if statement, ½ mark for correctly incrementing counts, ½ mark for
displaying the correct output)
Note: Any other relevant and correct code may be marked

28. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations Event and 3
COMPANY given below:
Table : Event
EventId EventName Date Organizer Budget
101 Wedding 26/10/2019 1004 700000
102 Birthday Bash 05/11/2019 1002 70000
103 Engagement 13/11/2019 1004 200000
104 Wedding 01/12/2019 1003 800000
105 Farewell 25/11/2019 1001 20000
Table : Company
OrganizerId Name Phone
1001 Peter 9745684122
1002 Henry 9468731216
1003 Smith 9357861542
1004 Fred 9168734567

I) SELECT Organizer, min(date) FROM Event GROUP BY Organizer;


ii) SELECT MAX(Date),MIN(Date) FROM Event;
iii) SELECT EventName, Name, Phone FROM Event , Company WHERE Organizer =
OrganizerId AND Budget<100000;
iv) SELECT Name, Date FROM Event, Company WHERE Phone like ‘%5_2’ AND Organizer =
OrganizerId;

(b) Write a command to view names of all database in MySQL server.

Ans : (a) I)
Organizer Min(date)
1004 26/10/2019
1002 05/11/2019
1003 01/12/2019
1001 25/11/2019
( ½ mark for the correct output)
(ii)
Max(date) Min(date)
01/12/2019 26/10/2019
( ½ mark for the correct output)
iii)
EventName Name Phone
Birthday Bash Henry 9468731216
Farewell Peter 9745684122
( ½ mark for the correct output)
iv)
Name Date
Smith 01/12/2019
( ½ x 4 = 2)

(b) SHOW DATABASES ( 1 mark )

29. Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the 3
function. The function returns another list named ‘indexList’ that stores the indices of all
Elements of L which has a even unit place digit.
For example:
If L contains [12,4,15,11,9,56]
The indexList will have - [0,1,5]

def INDEX_LIST(L):
indexList = [ ]
for i in range(0,len(L)):
if (L[i]%10)%2 == 0:
indexList.append(i)
else:
return indexList

(½ mark for correct function header, 1 mark for correct loop , 1 mark for correct if
statement, ½ mark for return statement)
Note: Any other relevant and correct code may be marked

30. A dictionary contains records of a tourist place like : 3


Tour_dict = { ‘Name’: ‘Goa’ , ‘PeakSeason’ : ‘December’ , ‘Budget’ : 15000 ,
‘Famous’:’Beaches’}
Write the following user defined functions to perform given operations on the stack named
‘tour’:
(i) Push_tour( Tour_dict) – To Push a list containing values for Name and PeakSeason where
value of budget is less than 10000 into the tour stack

(ii) Pop_tour() – To Pop the list objects from the stack and display them. Also, display “No
more tours” when there are no elements in the stack.

For example if the following dictionaries are passed to Push_tour( ) function in the following
sequence:
{ ‘Name’: ‘Goa’ , ‘PeakSeason’ : ‘December’ , ‘Budget’ : 15000 , ‘Famous’:’Beaches’}
{ ‘Name’: ‘Nainital’ , ‘PeakSeason’ : ‘May’ , ‘Budget’ : 9000 , ‘Famous’:’Nature’}
{ ‘Name’: ‘Sikkim’ , ‘PeakSeason’ : ‘May’ , ‘Budget’ : 9500 , ‘Famous’:’Mountains’}
{ ‘Name’: ‘Kerala’ , ‘PeakSeason’ : ‘November’ , ‘Budget’ : 15000 , ‘Famous’:’Back Waters’}
{ ‘Name’: ‘Orissa’ , ‘PeakSeason’ : ‘January’ , ‘Budget’ : 8000 , ‘Famous’:’Temples’}

Then the stack ‘tour’ will contain :


[ ‘Orrisa’ , ‘January’]
[‘Sikkim’, ‘May’]
[‘Nainital’ ,’ May’]

The output produced when calling pop_tour( ) function should be :


[ ‘Orrisa’ , ‘January’]
[‘Sikkim’, ‘May’]
[‘Nainital’ ,’ May’]
No more tours

Ans :
tour = [ ]
def Push_tour( tour_dict ) :
if tour_dict[‘Budget’] < 10000 :
LstTour = [ tour_dict[‘Name’] , tour_dict[‘PeakSeason’] ]
tour.append( LstTour )

def Pop_tour( ) :
while tour != [ ] :
T = tour.pop( )
print(T)
else:
print( “No more tours”)

(1.5 marks for correct push_element() and 1.5 marks for correct pop_element())
OR

Write a function in Python, Push(stack, SItem) where , SItem is a List containing the details
of stationary items in a format like – [Name , price , Unit , Company , MRP ].
The function should push the company names of those items in the stack whose price is 10
% percent less than its MRP. Also write a function print_stack( ) to display the Item Names
and the count of Items pushed into the stack.
For example:
If following data is passed to the function:
[ ‘Pen’ , 120.00 , ‘Pcs.’ , ‘Reynolds’ , 132.00 ]
[‘Paper’, 345.00 , ‘Rim’ , ‘Camel’, 500.00]
[Eraser , 100.00 , ‘Box’ , ‘IBP’ , 110.00
The stack should contain
Eraser
Pen
The output should be:
The count of elements in the stack is 2

Ans :
def Push(stack , SItem) :
if SItem[ 1] == SItem[4] * 0.90 :
Stack.append(SItem)

def print_stack( ):
Count = len(stack)
while stack != [ ]:
Item = stack.pop()
print( Item[ 0 ] )
else:
print(“Total items present in the stack is :”, count)

(1 mark for correct function header, 1 mark for correct loop, ½ mark for correct If
statement, ½ mark for correct display of count)

SECTION D
31. “VidyaDaan” an NGO is planning to setup its new campus at Nagpur for its web-based 5
activities. The campus has four(04) UNITS as shown below:
i) Suggest an ideal cable layout for connecting the above UNITs.
ii)Suggest the most suitable place i.e. UNIT to install the server for the above
iii)
Which network device is used to connect the computers in all UNITs?
iv)Suggest the placement of Repeater in the UNITs of above network.
v) NGO is planning to connect its Regional Office at Kota, Rajasthan. Which out of
the following wired communication, will you suggest for a very high-speed
Connectivity ?
(a) Twisted Pair cable (b) Ethernet cable (c) Optical Fiber

i. Layout Admin Training

Finance Resource

ii. Admin
iii. SWITCH/HUB
iv. ADMIN & FINANCE
v. (c) Optical Fiber

32. (a) Write the output of the following code : 2+3


R=0
def change( A , B ) :
global R
A += B
R +=3
print(R , end='%')
change(10 , 2)
change(B=3 , A=2)

Ans : 3%6%
(1 mark for 3% and 1 mark for 6%)

(b) The code given below inserts the following record in the table Emp:
EmpNo – integer
EName – string
Desig – string
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
 Username is admin
 Password is 22admin66
 The table exists in a MYSQL database named company.
 The details (EmpNo, EName, Desig and Salary) are to be accepted from the user.
 Write the following missing statements to complete the code:
Statement 1 – to establish a connectivity to the table in the database
Statement 2 - to form the cursor object
Statement 3 – to execute the command that inserts the record in the table Student.

import mysql.connector as mysql


def sql_data():
con1=mysql.___________(host="localhost",user = “admin” , password="22admin66",
database="company") #Statement1
mycursor=_________________ #Statement 2
eno=int(input("Enter Roll Number :: "))
ename=input("Enter name :: ")
desig=input("Enter class :: ")
sal =int(input("Enter Marks :: "))
querry="insert into student values( { },'{ }',’{ }’,{ } )".format(eno,ename,desig,sal)
______________________ #Statement 3
con1.commit( )
print("Data Added successfully")

Ans : Statement 1 : Connect


Statement 2 : con1.cursor( )
Statement 3 : mycursor.execute(querry)
(1 mark for each correct answer)

OR

(a) Predict the output of the code given below:


Ans : New string is : iNdiA%****
(1 mark for first 5 characters, 1 mark for next 5 characters)

(b) The code given below reads the following record from the table named product and
displays only those records which have name starting with a specific letters :
PId – integer
PName – string
Price – integer Marks – integer
Note the following to establish connectivity between Python and MYSQL:
 Username is admin
 Password is 22admin66
 The table exists in a MYSQL database named inventory.
Write the following missing statements to complete the code: Statement 1 – to
form the cursor object
Statement 2 – to execute the query that extracts records of those products whose
name starts with a specific letters.
Statement 3- to read the complete result of the query (records whose product
name starts with a specific letters ) into the object named data, from the table
student in the database.

import mysql.connector as mysql


def sql_data( ):
con1=mysql.connect(host="localhost", user="admin”, password="22admin66",
database="inventory")
mycursor=_______________ #Statement 1
startsWith = input(“Enter the starting letter sequence to search a product : ”)
print(“Products starting with the letter sequence”,startsWith, “are :” )
_________________________ # Statement 2
data=__________________ # Statement 3
for i in data:
print( i )
print()

Ans : Statement 1 : con1.cursor( )


Statement 2 : mycursor.execute(“Select * from product where PName Like ‘%” +
startsWith +” ’) ”
Statement 3 : mycursor.fetchall( )
( 1 mark for each correct statement)

33. What is the significance of a delimiter symbol in a csv file? Write a Program in Python that 5
defines and calls the following user defined functions:
 (i) ADD_CONT() – To accept and add data of a contact to a CSV file ‘address.csv’.
Each record consists of a list with field elements as contId, cname and cmobile to
store contact id, contact name and contact number respectively.
 (ii) COUNT_CONT() – To count the number of records present in the CSV file named
‘address.csv’.

Ans: The delimiter symbol is used to separate two data elements within a line of text in the
csv file. By default it is comma but can be set to any other symbol.
import csv
def ADD_CONT( ):
fout=open("address.csv","a",newline="\n")
wr=csv.writer(fout)
contid=int(input("Enter Contact id :: "))
cname=input("Enter Contact name :: ")
cmobile=int(input("Enter mobile number :: "))
lst=[contid, cname, cmobile] ---------1/2 mark
wr.writerow(lst) ---------1/2 mark
fout.close()

def COUNT_CONT( ):
fin=open("address.csv","r",newline="\n")
data=csv.reader(fin)
d=list(data)
print(len(d))
fin.close()

ADD_CONT( )
COUNT_CONT()

(1 mark for advantage ½ mark for importing csv module , 1 ½ marks each for correct
definition of ADD_CONT( ) and COUNT_CONT( ), ½ mark for function call statements )

OR
How csv file is different from a binary file? Write a Program in Python that defines and calls
the following user defined functions:
(i) save() – To accept and add data of watches to a CSV file ‘watchdata.csv’. Each
record consists of a list with field elements as watchid, wname and wprice to store
watch id, watch name and watch price respectively.
(ii) search()- To display the records of the watch whose price is more than 6000.

Ans: CSV file stores data using ASCII Plain Text Format. Or any other correct answer award
one mark.

import csv
def save():
fout=open(“watchdata.csv","a",newline='\n')
wr=csv.writer(fout)
watchid=int(input("Enter Furniture Id :: "))
wname=input("Enter Furniture name :: ")
wprice=int(input("Enter price :: "))
FD=[ watchid, wname, wprice ]
wr.writerow(FD)
fout.close( )

def search():
fin=open(“watchdata.csv","r",newline='\n')
data=csv.reader(fin)
found=False print("The Details are")
for i in data:
if int(i[2])>6000:
found=True
print(i[0],i[1],i[2])
if found==False:
print("Record not found")
fin.close()

save()
print("Now displaying")
search()

(1 mark for difference, ½ mark for importing csv module, 1 ½ marks each for correct
definition of add() and search() , ½ mark for function call statements)

SECTION E
34 Sagar a cloth merchant creates a table CLIENT with a set of records to maintain the client’s 1+1+
order volume in Qtr1, Qtr2, Qtr3 and their total. After creation of the table, he has entered 2
data of 7 clients in the table.
CLIENT
ClientName Client_ID Qtr1 Qtr2 Qtr3 Total
Suraj C120 200 300 400 900
Radha C650 190 356 220 766
Estha C430 200 100 400 700
Karuna C790 130 540 380 1050
Naresh C660 200 400 800 1400
Varun C233 400 300 220 920
Kritika C540 500 100 400 1000

Based on the data given above answer the following questions:


(i) Identify the most appropriate column, which can be considered as Primary key.
(ii) What is the product of degree and cardinality of the above table ?
(iii) Write the statements to:Update a record present in the table with data for
Qtr2 – 200 , Qtr3 = 600 , total – sum of all Qtrs where the Client_ID is C660
OR (option for part iii only )
(iii) (a) Delete all records where total is between 500 to 900
(b) Add a column RATINGS with datatype integer whose value must lie
between 1 to 5

Ans :
(i ) Client_ID (1 mark for correct answer)
(ii) 6x7 = 42 ( 1 Marks for correct answer)
(iii) Update Client set Qtr2 = 200 , Qtr3- 600 , total = 1000 where Client_ID = 660;
( 2 marks for fully correct answer / 1 mark for partially correct
answer)
OR
(iii) (a) Delete From Client where total between 500 and 900; ( 1 mark )
(b) ALTER TABLE Client ADD Ratings int CHECK ( Ratings between 1 and 5)
( 1 mark for use of ALTER and 1 mark for CHECK Constraint )

35. Vaishanavi is a budding Python programmer. She has written a code and created a binary 4
file phonebook.dat with contactNo, name and blocked [ Y/ N ]. The file contains 10 records
as a dictionary like {‘contactNo’ : 32344455 , ‘name’: ‘kamal kant’ ,’blocked’ : “Y” }

She now wants to shift all the records which have blocked = ‘Y’ status from phonebook.dat
to a binary file blocked.dat also all records which have blocked = ‘N’ status from
phonebook.dat to unblocked.dat. She also wants to keep count and print the total number
of blocked and unblocked records. As a Python expert, help her to complete the following
code based on the requirement given above:

import _____________ #Statement 1


def shift_contact( ):
fin = open(“phonebook.dat”,’rb’)
fblock = open( ___________________ ) #Statement 2
funblock = open( ___________________ ) #Statement 3
while True :
try:
rec = __________________ # Statement 4
if rec[“blocked”] == ‘Y’:
pickle.__________________ #Statement 5
if rec[“blocked”] == ‘N’:
Pickle. ________________ # Statement 6
except:
break

(i) Which module should be imported in the program? (Statement 1)


(ii) Write the correct statement required to open a blocked.dat and unblocked.dat
binary files (Statement 2 and 3)
(iii) which statement should Vaishnavi use in statement 4 to read the data from the
binary file, phonebook.dat
(iv) which statement should Vaishnavi use in statement 5 and 6 to write data to the
blocked.dat and unblocked.dat

Ans :
(i) pickle ( 1 mark)
(ii) open( “blocked.dat” , “wb”) ; open(“unblocked.dat”,”wb”) ( ½ + ½ )
(iii) pickle.load(fin) ( 1 Mark)
(iv) pickle.dump(rec,fblock);pickle.dump(rec , funblock) ( ½ + ½ )

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy