Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

BANGALORE SAHODAYA SCHOOLS COMPLEX ASSOCIATION (BSSCA)

Class: XII
PRE-BOARD EXAMINATION (2022-23)
SET 2 ANSWER KEY
DATE : 11.01.23 Max marks : 70
SUBJECT: Computer Science (083) Time : 3 hours

General Instructions:

1. This question paper contains five sections, Section A to E.


2. All questions are compulsory.
3. Section A have 18 questions carrying 01 mark each.
4. Section B has 07 Very Short Answer type questions carrying 02 marks
each.
5. Section C has 05 Short Answer type questions carrying 03 marks each.
6. Section D has 03 Long Answer type questions carrying 05 marks each.
7. Section E has 02 questions carrying 04 marks each. One internal
choice isgiven in Q34 against part c only.
8. All programming questions are to be answered using Python Language
only.

Section A

1. Write the type of the tokens for the following 1


i. 35 ii. ,
Ans: literal and punctuator

2. Given the list beow predict the output


odd_half = [x // 2 for x in range(2, 10) if x % 2 == 1] 1
print (odd_half)

Ans : [1, 2, 3, 4]

3. Find the output for the following 1


birds=["parrot", "owl", "sparrow", "crow", "eagle", "vulture", "pigeon"]
del birds[4]
birds.remove("vulture")
birds.pop(3)
print(birds)
Ans :['parrot', 'owl', 'sparrow', 'pigeon']
4. What value does the following expression evaluate to? 1
>>>2 + 9 * ((3 * 12) – 8) / 10
a. 27
b. 27.2
c. 30.8
d. None of these
Ans : b. 27.2

5. What will be the output of the following Python code? 1

count={}
count[(1,2,4)] = 5
count[(4,2,1)] = 7
count[(1,2)] = 6
count[(4,2,1)] = 2
tot = 0
for i in count:
tot=tot+count[i]
print(len(count)+tot)
A. 16
B. 17
C. 25
D. Tuples can’t be made keys of a dictionary
Ans :- A 16

6. The readlines() method returns ____________ 1


a) str
b) a list of lines
c) a list of single characters
d) a list of integers
Ans: b a list of lines

7. A(n) ____________ in a table represents a logical relationship among a set of


values. 1
a. Tuple
b. Attribute
c. Key
d. Entry
Ans : a. Tuple

8. What does comparing a known value with NULL result into? 1


a) zero
b) a positive value
c) a negative value
d) null
Ans: d null

9. In a Python program, a control structure: 1


a. Defines program-specific data structures
b. Directs the order of execution of the statements in the program
c. Dictates what happens before the program starts and after it terminates
d. None of the above
Ans : b Directs the order of execution of the statements in the program

10. Suppose you have two columns named student_name and student_department inside
table student_details and you are asked to update the value of these two columns
where ID=4 then what statement you will write? 1

a. UPDATE student_details SET Student_name="ram", Student_department='Chemical'


WHERE ID='4';
b. UPDATE table student_details SET column_name Student_name="ram",
Student_department='Chemical' WHERE ID='4';
c. UPDATE student_details SET Student_name="ram" and
Student_department='Chemical' WHERE ID='4';
d. UPDATE table student_details SET Student_name="ram",
Student_department='Chemical' WHERE ID='4';

Ans: a. UPDATE student_details SET Student_name="ram", Student_department =


'Chemical' WHERE ID='4';

11. What happens if no arguments are passed to the seek function? 1


a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error
Ans: d. error

12. Which clause is used to “Modify the existing field of the table”? 1
a) ALTER
b) UPDATE
c) SELECT
d) MODIFY
Ans: a. ALTER

13. Which of the following devices modulates digital signals into analog signals that
can be sent over telephone lines 1
a. Router
b. Gateway
c. Bridge
d. Modem
Ans : d. modem

14. What will be the output of the following Python code? 1


i=5
while True:
if i%0O9 == 0:
break
print(i)
i += 1
a) 5 6 7 8
b) 5 6 7 8 9
c) 5 6 7 8 9 10 11 12 13 14 15 ….
d) error
Ans: d Error

15. Foreign Key in a table is used to enforce 1


a. Data dependency
b. ReferentialIntegrity
c. Views
d. IndexLocations
Ans : b. Referntial Integrity

16. Which attribute is used to return number of rows that are affected by an execute()
method. 1
a. rows()
b. count()
c. rowcount()
d. returncount()
Ans: rowcount()

Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct
appropriate choice.

17. Assertion - A function ends the moment it reaches a return statement or all the
statements in function body have been executed.
Reason – Return statement ends a function execution even if it is in the middle of
the function.
A - Both A and R are true and R is the correct explanation of A.
B - Both A and R are true but R is not the correct explanation of A.
C - A is true but R is false.
D - A is false but R is true.
Ans : A - Both A and R are true and R is the correct explanation of A.

18. Assertion- The open a file one should use the open() function, open() is a built
in function
Reason - The open () functions returns a file object, it is used to read or modify the
file accordingly.
A - Both A and R are true and R is the correct explanation of A.
B - Both A and R are true but R is not the correct explanation of A.
C - A is true but R is false.
D - A is false but R is true.
Ans: B - Both A and R are true but R is not the correct explanation of A.
SECTION B
19. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code 2
def sum(c)
s=0
for i in Range(1, c+1)
s=s+i
return s
print(sum(5)

Ans:
def sum(c):
s=0
for i in range(1, c+1):
s=s+i
return s
print(sum(5))
( ½ mark for each error)

20. Differentiate two pints between PAN and LAN types of networks. 2
Ans :

PAN LAN
PAN is a computer network LAN interconnects some
organized around an individual standalone computers within a
person, where a small network is confirmed physical area up to
formed by connecting various a kilometre.
devices of the individual.
Devices in one PAN network can The network does not contain
establish connection with other more than one subnet because
devices in other PAN network they are controlled by one
when in the same range. administrator.
Example: a laptop, a printer, a Example a LAN inside a
smartphone, digital recorder. Etc University or a LAN inside a
hospital. Etc.
( One mark for each difference )
OR
Write two differences between Packet Switching and Message Switching
Ans :

Packet Switching Message Switching


Message is broken into smaller A complete message is passed
units known as Packets. across a network.
Packet switching places a tight In message switching there is
upper limit on block size.. no limit on block size
packets of the message exist in Message exist only in one
many places in the network. location in the network.
( One mark for each difference )
21. PREDICT THE OUTPUT 2
t1=("Bangalore",[1,2,'3'],'S',(3,4,6),"Centre",10)
print(t1[-2:]+t1[3])
Ans : ('Centre', 10, 3, 4, 6)
( 1 mark for correct anwer)

What will be the output of following program:


my_dict = {}
my_dict[1] = 1
my_dict['1'] = 2
my_dict[1.0] = 4
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
Ans: 6
( 1 mark for correct anwer)

22. What are aggregate and scalar functions in MYSQL? Give one example for each 2
Ans:
Aggregate functions work on multiple tuples’ values for an attribute and return
single summarised value for a group of tuples.
Ex: sum()
The scalar functions work individually with each tuple’s value for an attribute and
return the result for each tuple.
Ex: now(), year(), lcase()
( 1 mark for each correct anwer)

23. Expand the following terminologies. 1+1


i.CDMA ii. XML.

Ans:
i. CDMA. Code division multiple access.
ii. XML. Extensible markup language.
(½ mark for every correct full form)

Write two characteristics of Wi-fi


Ans:
1. Wi-Fi is a broadcast technology with in range of 50m-150m
2. Convenient and anywhere technology
3. Supports secure wireless communication
(½ mark for every correct answer)

24. Predict the output of the Python code given below: 2


def Indirect(temp = 20):
for i in range(10,temp+1, 5):
print(i, end = ' ')
print()
def Direct(num):
num = num + 10
Indirect(num)
print ("Number ", num)

number = 20 # main program


Direct(number)
Ans :
10 15 20 25 30
Number 30
(1 mark for each line of correct output)
OR
Predict the output of the Python code given below:

str1=list("Sn04")
for i in range(len(str1)):
if i==3:
x=int(i)
x+=x-3
str1[i]=x
elif (str1[i].islower()):
str1[i]=str1[i].upper()
else:
str1[i]=str1[i]*2
print(str1)

Ans: ['SS', 'N', '00', 3]


( ½ mark for each value)

25. Differentiate between Candidate key and Primary key in context of RDBMS.
Illustrate with an example. 2
Ans:
Candidate Key: All attribute combinations inside a relation that can serve primary
key are Candidate Keys as they are candidates for the primary key position.
Primary Key: A primary key is a set of one or more attributes that can uniquely
identify tuples within the relations.

Appropriate example to be shown.

(Differences carry 1 mark example carry 1 mark)


OR
What are DDL and DML? Write any two commands of DDL and DML in MYSQL
Ans :
DDL is Data Definition Language which provides statements for creation,
manipulation and deletion of tables.
Ex: CREATE, ALTER, DROP
DML is Data Manipulation Language provides statements to enter, update, delete
data and perform complex queries on the tables
Ex : INSERT, UPDATE, DELETE
SECTION C
26. 1+2
a. Consider the two tables : PRODUCT and CLIENT
Table : PRODUCT

Pid ProductName Manufacturer Price


TP01 Talcom Powder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95

Table : CLIENT

Cid ClientName City Pid


01 Cosmetic Shop Delhi FW05
06 Total Health Mumbai BS01
12 Live Life Delhi SH06
15 Pretty Women Delhi FW12
16 Dreams Bangalore TP01

What will be the output of the following statement?


Ans: Select ClientName, City, ProductName, Price from PRODUCT, CLIENT
where PRODUCT.Pid = CLIENT.Pid
C_id City ProductName Price
01 Delhi Face Wash 45
06 Mumbai Bath Soap 55
12 Delhi Shampoo 120
15 Delhi Face Wash 95
16 Bangalore Talcom Powder 40
b.

Table HOSPITAL
No Name Age Department Dateofadm Charges Sex
1 Arpit 34 Surgery 21/01/04 300 M
2 Anush 60 ENT 11/04/05 250 M
3 Nilofer 45 Orthopedic 19/11/04 500 F
4 Jackie 47 Surgery 20/05/06 600 F
5 Bret 20 ENT 19/04/05 200 M
6 Anthea 46 ENT 23/09/05 200 F
7 Bindu 38 Cardiology 15/08/04 450 F
8 Deepak 25 Cardiology 14/11/05 450 M
9 Zain 9 Nuclear Medicine 14/12/06 700 M
10 Zeba 47 Gynecology 1/1/2006 350 F
i. select name, age, sex from hospital where department like "cardiology";
Ans:
-------- ------ ------
name age sex
+--------+------+------+
| Bindu | 38 | F |
| Deepak | 25 | M |
+--------+------+------+

ii. select name, dateofadm from hospital where department = "ENT" and sex like 'F';

Ans :
+--------+------------+
| name | dateofadm |
+--------+------------+
| Anthea | 2023-09-05 |
+--------+------------+

iii. select department, count(*), min(charges) from hospital group by department


having count(department)>2;

Ans:
+------------ +----------+-------------- +
| department | count(*) | min(charges) |
+------------ +---------- +-------------- +
| ENT | 3| 200 |
+------------ +---------- +-------------- +
iv. select distinct(department) from hospital order by department;
Ans:
+------------------+
| department |
+------------------+
| Cardiology |
| ENT |
| Gynecology |
| Nuclear Medicine |
| Orthopedic |
| Surgery |
+------------------+
( ½ Mark for each correct output)

27. Write a method countcap( ) in python to count the number of upper case alphabets
present in a text file “ARTICLE.txt” 3
Example :
If the file contains the given below content:

A piece of writing other than fiction or poetry that forms a


separate part of a publication (as a Magazine or Newspaper)

Then the countcap( ) has to give output as :


The number of capital case alphabets are : 3

Ans:
def countcap():
file = open('poem1.txt', 'r')
count = 0
chr = file.read()
print(chr)
for i in chr:
if i.isupper():
count+=1
print("Total no.of uppercase alphabets:", count)
file.close()
countcap()
( ½ mark for correctly opening and closing the file
½ for readlines()
½ mar for correct loop
½ for correct if statement
½ mark for correctly incrementing count
½ mark for displaying the correct output)

OR
Write a method RevText() to read a text file “input.txt” and print the text in reverse order.
Example:
If the file content is as follows: I LOVE MY NATION
Output will be: NOITAN YM EVOL I
Ans :
def RevText():
file = open('input.txt', 'r')
for i in file:
print(i[-1::-1])
file.close()
RevText()
( ½ mark for correctly opening and closing the file
½ for readlines()
½ mar for correct loop
½ for correct if statement
½ mark for correctly incrementing count
½ mark for displaying the correct output)

28. a) Write the outputs of the SQL queries (i) to (iv) based on the relations Club and
Coach given below: 3

Table : Club
Coach-id CoachName Age Sports DateOfApp Pay Sex
1 KUKREJA 35 KARATE 27/03/1996 1000 M
2 RAVINA 34 KARATE 20/01/1998 1200 F
3 KARAN 34 SQUASH 19/02/1999 2000 M
4 TARUN 33 BASKETBALL 01/01/1999 1500 M
5 ZUBIN 36 SWIMMING 12/01/1998 750 M
6 KETAKI 36 SWIMMING 24/02/1997 800 F
7 ANKITA 39 SQUASH 20/02/1998 2200 F
8 ZAREEN 37 KARATE 22/02/1997 1100 F
9 KUSH 41 SWIMMING 13/01/1997 900 M
10 SHAILYA 37 BASKETBALL 19/02/1998 1700 M

Table :Coach
Sports person Sex Coach-id
AJAY M 1
SEEMA F 2
VINOD M 1
TANEJA F 3
VIKRAM M 9

i. SELECT COACHNAME,PAY FROM CLUB WHERE PAY>1500 ORDER BY


DATEOFAPP ASC;
Ans :
COACHNAME PAY
-------------------- ----------
SHAILYA 1700
ANKITA 2200
KARAN 2000

ii. SELECT COACHNAME, AGE, PAY, 15/100*PAY+PAY BONUS FROM CLUB WHERE
DATEOFAPP < '01-JAN-1998';
Ans :
COACHNAME AGE PAY BONUS
-------------------- ---------- ---------- ----------
KUKREJA 35 1000 1150
KETAKI 36 800 920
ZAREEN 37 1100 1265
KUSH 41 900 1035
iii. SELECT COACHNAME, SPORTSPERSON FROM CLUB, CLUBPERSON WHERE
CLUB.SEX LIKE 'M' AND CLUBPERSON.SEX LIKE 'F'AND CLUB.COACHID =
CLUBPERSON.COACHID;
Ans:
COACHNAME SPORTSPERSON
-------------------- --------------
KARAN TANEJA

iv. SELECT SUM(PAY) FROM CLUB WHERE DATEOFAPP > '31-JAN-1998';


Ans :
SUM(PAY)
----------
5900
( ½ MARK for each correct output)
b. Write an SQL query to view all the tables in a database.
Ans : select * from tab;
(1 mark for correct answer)

29. Write a void function that receives a 4-digit no. and calculates the sum of the
squares of each digit in the number. 3
Example :
Enter a 4-digit no.1234
Sum of squares of digits 30
Ans :
def f(x):
sum1 = 0
while x>0:
dig=x%10
x//=10
sum1+=(dig**2)
print("Sum of squares of digits", sum1)
n = int(input("Enter a 4-digit no."))
f(n)
(½ mark for correct function header
1 mark for correct loop
1 mark for correct sum of squares
½ mark for printing output)

30. Write functions of a program to implement a stack for these book details (bookno,
bookname). That is, now each item of node of stack contains 2 types of information
as a list element. Implement Push and Display operations for the stack of books.
3
Ans :
stk=[bookno,bookname]
def isEmpty(stk):
if stk == []:
return True:
else:
return False:
def Push(stk,item ):
stk.append(item)
top=len(stk)-1
def Display():
if isEmpty(stk):
print(“Stack empty”)
else:
top = len(stk)-1
print(stk[top], “<-” )
for a in range(top-1, -1,-1):
print(stk[a])
(1.5 marks for correct push_element() and 1.5 marks for correct
pop_element())
OR
Write a function in python named PUSH(STACK, SET) where STACK is list of
some numbers forming a stack and SET is a list of some numbers. The function will
push all the EVEN elements from the SET into a STACK implemented by using a
list. Display the stack after push operation.

Ans : def PUSH(STACK,SET):


for i in SET:
if i%2 == 0:
STACK.append()
print(“Updated STACK is “, STACK)

( ½ mark for correct function header


½ mark for ‘for’ loop
½ mark for checking if statement
½ mark for appending the stack
1 mark for displaying the stack)

SECTION D
31. Intelligent Hub India is a knowledge community aimed to uplift the standard of
skills and knowledge in the society. It is planning to setup its training centres in
multiple towns and villages pan India with its head offices in the nearest cities.
They have created a model of their network with a city, a town and 3 villages as
follows:
As a network consultant, you have to suggest the best network related solutions for
their issues/problems raised in (i) to (v), keeping in mind the distances between
various locations and other given parameters. 5
i. Suggest the most appropriate location of the SERVER in the YHUB (out of the
4 locations), to get the best and effective connectivity. Justify your answer. 1

ii. Suggest the best wired medium and draw the cable layout (location to location)
to efficiently connect various locations within the YHUB. 1

iii. Suggest a device/software to be installed in the Kashipur Campus to take care of


data security. 1

iv. Which hardware device will you suggest to connect all the computers within
each location of YHUB? 1

v. Which service/protocol will be most helpful to conduct live interactions of


Experts from Head Office and people at YHUB locations? 1

Ans :

i.
YTOWN
Justification
Since it has the maximum number of computers.
It is closest to all other locations.
(½ mark for naming the server block and ½ mark for correct reason.)

ii. Optical Fiber


iii. Firewall
(1 mark for the correct answer)
iv. Switch OR Hub
(1 mark for the correct answer)
v. Videoconferencing OR VoIP
(1 mark for the correct answer)

32.
a. Predict the output of the code given below 2+3

def Display(str):
m=" "
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"#"
print(m)
Display('CBSE@dec22')

Ans :
cbseDEC#
(1mark for first 4 characters and 1 mark for last 4 characters)

b. The code given below inserts the following record in the table Student:
rno – integer
Name – string
cls – integer
Mks – integer
Note the following to establish connectivity between Python andMYSQL:
 Username is root
 Password is tiger
 The table exists in a MYSQL database named class12.
 The details (rno, name, cls and mks) are to be accepted from the user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table
Student.
Statement 3 – to add the record permanently in the database

import mysql.connector as m
def connecting():
con1=m.connect(host="localhost",user="root", password="tiger",
database="class12")
mycursor= ________________#Statement 1
rno=int(input("Enter Roll Number :: "))
name=input("Enter name :: ")
cls=int(input("Enter class :: "))
mks=int(input("Enter Marks :: "))
querry="insert into student values({},'{}',{},{})".format(rno,name,cls,marks)
____________________#Statement 2
____________________# Statement 3
print("Data Added successfully")

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

OR
a. Predict the output of the following program
X = 100
def Change(P=10, Q=25):
global X
if P%6==0:
X+=100
else:
X+=50
print(P,'#',Q,'$')
Change()
Change(18,50)
Ans :

10 # 25 $
18 # 50 $
( 1 mark for each line)

b. The code given below reads the following record from the table named Book and
displays only those records with the book price greater than 250 rs.:
BNo – integer
BName – string
BPrice – integer

Note the following to establish connectivity between Python andMYSQL:


 Username is root
 Password is tiger
 The table exists in a MYSQL database named Library.

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 books


which are priced greater than 250rs.

Statement 3- to read the complete result of the query (records of books priced
greater than 250rs.) into the object named content from the table
book.
import mysql.connector as ms
def book_data():
con1=ms.connect(host="localhost", user="root",password="tiger",
database="library")
mycursor= #Statement 1
print("Books priced greater than rs.250 are :")
_______________________ #Statement 2
content = #Statement 3
for i in content:
print(i)
print()
Ans:
Statement 1: con1.cursor()
Statement 2: mycursor.execute("select * from book where BPrice >250")
Statement 3: mycursor.fetchall()

(1mark for each correct answer)

33. Write differences in the file opening mode “a” and “w”? 5

Abhisar is making a software on “Countries & their Capitals” in which various


records are to be stored/retrieved in CAPITAL.CSV data file. Write a python program
that defines and calls the following user defined functions

def AddNewRec(Country,Capital): A function to read and add a new record in CSV


file CAPITAL.CSV. Each record consists of the name of the country and its
capital as the fields.
def ShowRec(): A function to count and display all the records from CSV file
Ans:
“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.
import _CSV
def AddNewRec(Country,Capital): # Fn. to add a new record in CSV file
f=open(“CAPITAL.CSV”, a)
fwriter=csv.writer(f)
fwriter.writerow([Country,Capital])
f.close()

def ShowRec():
with open(“CAPITAL.CSV”,”r”) as NF:
NewReader=csv.reader
c=0
for rec in NewReader:
print(rec[0],rec[1])
c=c+1
print( c)

(1 mark for advantage


½ mark for importing csv module
1 ½ marks each for correct definition of ADD() and
COUNTR()
½ mark for function call statements )
OR

What is the difference in write() and writelines()?

A binary file “STUDENT.DAT” has structure (admission_number, Name,


Percentage).
i. Write a function addrec() in Python that would read contents of the file
“STUDENT.DAT”
ii. Write function countrec() to display the details of those students whose
percentage is above 75. Also display number of students scoring above 75%

Ans :

import pickle
def addrec():
fobj=open("STUDENT.dat","ab")
AdmnNo=int(input("Admission Number : "))
StdName=input("Name :")
Per = input("Percentage:" )
rec=[AdmnNo,StdName,Per]
pickle.dump(rec,fobj)
fobj.close()
countRec():
fobj=open("STUDENT.DAT","rb")
num = 0
try:
while True:
rec=pickle.load(fobj)
if rec[2] > 75:
print(rec[0],rec[1],rec[2],sep="\t")
num = num + 1
except: fobj.close()
return num

34. Prashanth has created a database for all the items available in his shop as interiors.
Table : Interiors 4

No Item Name Type DateofStock Price Discount


1 Red rose Double bed 23/02/02 32000 15
2 Soft touch Baby cot 20/01/02 9000 10
3 Jerry’s home Baby cot 19/02/02 8500 10
4 Rough wood Office Table 01/01/02 20000 20
5 Comfort zone Double bed 12/01/02 15000 20
6 Jerry look Baby cot 24/02/02 7000 19
7 Lion king Office Table 20/02/02 16000 20
8 Royal tiger Sofa 22/02/02 30000 25
9 Park sitting Sofa 13/12/01 9000 15
10 Dine Paradise Dining Table 19/02/02 11000 15
11 White Wood Double bed 23/03/03 20000 20
12 James 007 Sofa 20/02/03 15000 15
Based on the above data given answer the following queries.

i. Define Degree? Write the degree of table Interior


Ans : The number of attributes or columns in a relation is called the Degree of
the relation.
Degree of the above table is 6

ii. If NO is the primary key, which can be the alternate key?


Ans : ItemName

iii. Write statements to :


a. To insert a record into the table as
13 Tom Look Baby Cot 21/02/03 7000 10
Ans:
insert into Interiors values(13,'Tom Look','Baby Cot', '21/02/03', 7000,
10);
b. To increase the price by 1000 to all the items whose discount is 20.
Ans : Update interiors set price= price+1000 where discount = 20;
OR (Option for Part iii only)
iii. Write the statements to:
a. Delete the record of interiors whose type is ‘Office Table”
Ans : delete from interiors where type like Office Table
b. To modify the Price column so that it has default value as 5000.
Ans : alter table Interiors modify( price default 5000);

35. Preethi Shah is learning to work with binary files in Python using a process
known pickling/ unpickling. Her teacher has given her the following
incomplete code, which is creating a binary file namely Mydata.dat and then
opens, reads and displays the content of this created file,

_______________ #fill_line1
sqlist = list( )
for k in range(10):
sqlist.append(k*k)
fout = ______________ #fill_line2A
_________________ #fill_line3
fout.close( )
fin = _______________ #fill_line2B
___________________ #fill_line4
fin.close( )
print (“Data from file :”, mylist)

Help her complete the above code as per the instructions given below:
a. Complete fill_line1 so that required python library becomes available to
the program
b. Complete fill_line2A so that the above-mentioned binary file is opened
for writing in the file object fout
c. Similarly complete fill_line2B, which will open the same binary file for
sending in the file object fin.
d. Complete fill_line3 so that the list created in the code, namely sqlist, is
written in the open file.
e. Complete fill_line4 so that the contents of the open file in the file handle
fin are read in a list namely mylist.
Ans:
import pickle
Sqlist = list()
for k in range (10):
sqlist.append(k*k)
fout = open(“mydata.dat”,’wb’)
pickle.dump(sqlist,fout)
fout.close( )
fin=open(“mydata.dat”,’rb’)
mylist = pickle.load(fin)
fin.close( )
print(“Data from file:”, mylist)
(fill_line1 -1Mark
fill_line2A and fill_line2B – ½ mark each
fill_line3 – 1 mark
fill_line4 – 1 mark)

You might also like