CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Practicing the CBSE Sample Papers for Class 12 Computer Science Set 1 allows you to get rid of exam fear and be confident to appear for the exam.

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Time allowed: 3 Hrs.
Max. Marks: 70

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 is given in Q35 against part C only.
  8. All programming questions are to be answered using Python Language only.

Section-A

Question 1.
State True or False [1]
“Variable declaration is implicit in Python.”
Answer:
True
Explanation: Variable declaration is automatically done in python and is optional.

Question 2.
Which of the following is an invalid datatype in Python? [1]
(a) Set
(b) None
(c) Integer
(d) Real
Ans.
(d) Real
Explanation: There is no data type like Real.

Question 3.
Given the following dictionaries: [1]
dict_exam={“Exam”:”AISSCE”, “Year”:2023)
dict_result={“Total”:500, “Pass_Marks”: 165}
Which statement will merge the contents of both dictionaries?
(a) dict_exam.update(dict_result)
(c) dict_exam.add(dict_result)
(b) dict_exam + dict_result
(d) dict_exam.merge(dict_result)
Answer:
(a) dict_exam.update(dict_result)
Explanation: The update method of a dictionary updates the contents of a dictionary by another, adding new keys and their values.

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Question 4.
Consider the given expression: [1]
not True and False or True
Which of the following will be correct output if the given expression is evaluated?
(a) True
(b) False
(c) NONE
(d) NULL
Answer:
(a) True
Explanation: not True and False or True False and False or True False or True True

Question 5.
Select the correct output of the code: [1]
a = “Year 2022 at All the best”
a = a.split(/2′)
b = a[0] + “. ” + a[1] + “. ” + a[3]
print (b)
(a) Year . 0. at All the best
(c) Year . 022. at All the best
(b) Year 0. at All the best
(d) Year . 0. at all the best
Answer:
(a) Year . 0. at All the best
Explanation: a = a.split(‘2’) Gives :
[‘Year’O’,”,’ at All the best’]
b = a[0] + “. ” + a[l] + ” + a[3] Gives b as:
‘Year . 0. at All the best’

Question 6.
Which of the following mode in file opening statement results or generates an error if the file does not exist?
(a) a+
(b) r+
(c) w+
(d) None of these
Answer:
(b) r+
Explanation: A file that does not exist cannot be opened for reading and writing.

Question 7.
Fill in the blank: [1]
______ command is used to remove primary key from the table in SQL.
(a) update
(b) remove
(c) alter
(d) drop
Answer:
(c) alter
Explanation: Alter table <table> DROP Primary key.

Question 8.
Which of the following commands will delete the table from MYSQL database? [1]
(a) DELETE TABLE
(b) DROP TABLE
(c) REMOVE TABLE
(d) ALTER TABLE
Answer:
(b) DROP TABLE

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Question 9.
Which of the following statement(s) would give an error after executing the following code? [1]
S=”Welcome to class XII” # Statement 1
print(S) # Statement 2
S=”Thank you” # Statement 3
S[0]= ‘<§>’ # Statement 4
S=S+”Thank you” # Statement 5
(a) Statement 3
(b) Statement 4
(c) Statement 5
(d) Statement 4 and 5
Answer:
(b) Statement 4

Fill in the blank: [1]

Question 10.
______ is a non-kev attribute, whose values are derived from the primary key of some other table.
(a) Primary Key
(b) Foreign Key
(c) Candidate Key
(d) Alternate Key
Answer:
(b) Foreign Key

Question 11.
The correct syntax of seek( ) is: [1]
(a) file_object.seek(offset [, reference_point])
(b) seek(offset [, reference_point])
(c) seek(offset, file_object)
(d) seek.file_object(offset)
Answer:
(a) file_object.seek(offset [, reference_point])
Explanation: seek( ) has to be used with a file object and the position , reference with respect to beginning, end, or current, where the file pointer is to be placed.

Question 12.
Fill in the blank: [1]
The SELECT statement when combined with ______ clause, returns records without repetition.
(a) DESCRIBE
(b) UNIQUE
(c) DISTINCT
(d) NULL
Answer:
(c) DISTINCT

Fill in the blank: [1]

Question 13.
______ is a communication methodology designed to deliver both voice and multimedia communications over Internet protocol.
(a) VoIP
(b) SMTP
(c) PPP
(d) HTTP
Answer:
(a) VoIP
Explanation: VoIP-Voice over internet protocol.

Question 14.
What will the following expression be evaluated to in Python? [1]
print(15.0/4 +(8 + 3.0))
(a) 14.75
(b) 14.0
(c) 15
(d) 15.5
Answer:
(a) 14.75
Explanation: 15.0 / 4 + (8 + 3.0)) = 3.75 +11.0 = 14.75

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Question 15.
Which function is used to display the total number of records from table in a database? [1]
(a) sum(*)
(b) total(*)
(c) count(*)
(d) retum(*)
Answer:
(c) count(*)

Question 16.
To establish a connection between Python and SQL database, connect() is used. Which of the following arguments may not necessarily be given while calling connect() ? [1]
(a) host
(b) database
(c) user
(d) password
Answer:
(b) database

Q. 17 and 18 are Assertion and Reasoning based questions. Mark the correct choice as:
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation of A
(c) A is True but R is False
(d) A is false but R is Ture

Question 17.
Assertion (A): If the arguments in function call statement match the number and order of arguments as defined in the function definition, such arguments are called positional arguments. [1]
Reason (R): During a function call, the argument list first contains default argument(s) followed by positional argument(s).
Answer:
(c) A is true, but R is false.
Explanation: In case of positional arguments , the number of parameters passed must match the number of arguments in the function definition. Default parameters are assigned right to left.

Question 18.
Assertion (A): CSV (Comma Separated Values) is a file format for data storage which looks like a text file. [1]
Reason (R): The information is organized with one record on each line and each field is separated by comma.
Answer:
(a) Both A and R are true and R is the correct explanation of A
Explanation: CSV files are comma separated values file that stores the data just like text files and the values are separated by comma delimiter.

Section-B

Question 19.
Rao has written a code to input a number and check whether it is prime or not. His code is having errors. Rewrite the correct code and underline the corrections made. [2]
def prime( ):
n=int(input(“Enter number to check :: “)
for i in range (2, n//2):
if n%i=0:
print(“Number is not prime \n”)
break
else:
print(“Number is prime \n’)
Ans. def prime( ):
n=int(input(“Enter number to check :: “))
for i in range (2, n//2):
if n%i=0:
print(“Number is not prime \n”)
break
else:
print(“Number is prime \n”)

Question 20.
Write two points of difference between Circuit Switching and Packet Switching. [2]
OR
Write two points of difference between XML and HTML.
Answer:
Difference between Circuit Switching and Packet Switching.

Circuit Switching Packet Switching
1. In circuit switching, each data unit knows the entire path address which is provided by the source. In packet switching, each data unit just knows the final destination address intermediate path is decided by the routers.
2. In-Circuit switching, data is processed at the source system only. In Packet switching, data is processed at all intermediate nodes including the source system.

OR
Difference between XML and HTML.

XML HTML
1. Tags are user defined. Tags are predefined.
2. Tags are case sensitive. Tags are not case sensitive.

Question 21.
(a) Given is a Python string declaration: [1]
myexam=”@@CBSE Examination 2022@@”
Write the output of: print(myexam[::-2])
(b) Write the output of the code given below: [1]
my_dict = {“name”: “Aman”, “age”: 26}
my_dict[‘age’] = 27
my_dict[‘ address’] = “Delhi”
print(my_dict.items())
Answer:
(a) @20 otnmx SC@
The string is displayed starting from the end decrementing by 2 each time.

(b) dict_items([(‘name’, ‘Aman’), (‘age’, 27), (‘address’, ‘Delhi’)])
The age is updated to 27 and a new key ‘address’ has been added with value ‘Delhi’

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Question 22.
Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give example to support your answer. [2]
Answer:
A foreign key is a linking field between two tables and brings corresponding or matching values from the two tables.
Example : Consider the tables Bank_Account and Branch
Table: Bank_Account

ACode Name Type
A01 Amrita Savings
A02 Parthodas Current
A03 Miraben Current

Table: Bramch

ACode City
A01 Delhi
A02 Mumbai
A01 Nagpur

To display the City of Amrita, the Acode field has to be used to link the tables. Acode is the foreign key in Bank_Account table.

Question 23.
(a) Write the full forms of the following: [2]
(i) SMTP
(ii) PPP
(b) What is the use of TELNET?
Answer:
(a) (i) SMTP : Simple Mail Transfer Protocol
(ii) PPP : Point to Point protocol
(b) It is an application protocol to login to a remote server. Such logins can be used to get access to remote data and software resources.

Question 24.
Predict the output of the Python code given below: [2]
def Diff(Nl,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [10,23,14,54,32]
for CNT in range (4,0,—1):
A=NUM[CNT]
B=NUM[CNT-1 ]
print(Diff(A,B)/#’, end= ‘)
OR
Predict the output of the Python code given below:
tuplel = (11, 22, 33, 44, 55, 66)
list1 =list(tuplel) new_list = [ ]
for i in list1:
if i%2=0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
Answer:
22 # 40 # 9 # 13 #
The code picks each element from the list from end and sends the value and value -1 to the function. The function checks the values using a if structure and returns values accordingly.
OR
(22, 44, 66)
The code creates a list from the tuple, picks each element and appends the even elements to a new list.

Question 25.
Differentiate between Count( ) and Count(*) functions in SQL with appropriate example. [2]
OR
Categorize the following commands as DDL or DML:
INSERT, UPDATE, ALTER, DROP
Answer:
Count( ) – counts the NON NULL values in a field.
Count(*) – counts the records in a table.
Example:

ID Name Description
1 Moon Smart
2 Rahi Positive
3
4 Moon Smart

Select Count(*) from student;

Count (*)
4

Select Count(name) from student;

Count(Name)
3

OR
DDL : ALTER, DROP
DML : INSERT, UPDATE

Section-C

Question 26.
(a) Consider the following tables – Bank_Account and Branch: [1+2]
Table: Bank_Account

ACode Name Type
A 01 Amrita Savings
A 02 Parthodas Current
A 03 Miraben Current

Table: Branch

ACode City
A01 Delhi
A02 Mumbai
A01 Nagpur

What will be the output of the following statement?
SELECT * FROM Bank_Account NATURAL JOIN Branch;

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

CID CNAME FEES START DATE TID
C201 Animation and VFX 12000 2022-07-02 101
C202 CADD 15000 2021-11-15 NULL
C203 DCA 10000 2020-10-01 102
C204 DDTP 9000 2021-09-15 104
C205 Mobile Application Development 18000 2022-11-01 101
C206 Digital marketing 16000 2022-07-25 103

(i) SELECT DISTINCT TID FROM TECH_COURSE;
(ii) SELECT TID, COUNT(*), MIN(FEES) FROM
TECH_COURSE GROUP BY TID HAVING COUNT(TID)>1;
(iii) SELECT CNAME FROM TECH_COURSE WHERE
FEES>15000 ORDER BY CNAME;
(iv) SELECT AVG(FEES) FROM TECH_COURSE WHERE
FEES BETWEEN 15000 AND 17000;
Answer:

ACode Name Type City
A01 Amrita Savings Delhi
A02 Parthodas Current Mumbai
A01 Amrita Savings Nagpur

(b) (i)

(TID)
101
NULL
102
103
104

(ii)

TID COUNT(*) MIN (FEES)
101 2 12000

(iii)

CNAME
Digital Marketing
Mobile Application Development

(iv)

AVG (FEES)
15500.00

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Question 27.
Write a method COUNTLINES() in Python to read lines from text file ‘TESTFILE.TXT’ and display the lines which are not starting with any vowel. [3]
Example:
If the file content is as follows:
An apple a day keeps the doctor away.
We all pray for everyone’s safety.
A marked difference will come in our country.
The COUNTLINES ( ) function should display the output as:
The number of lines not starting with any vowel -1
OR
Write a function ETCount( ) in Python, which should read each character of a text file “TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and T individually (including small cases e and t too).
Example:
If the file content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites
The ETCount( ) function should display the output as:
E or e: 6
T or t: 9
Answer:
def countlines( ):
f=open(“TESTFILE.TXT”)
strlines=f.readlines( )
for str in strlines:
if (str[0] not in [‘aeiou’]) or (str[0] not in [‘AEIOU’]):
print(str)
f.close( )
OR
def countEU( ):
f=open(“IMP.TXT”)
e=0
u=0
while True:
1=f.readline( )
if not 1:
break
for i in 1:
if(i=’E’ or i==’e’):
e=e+1
el if (i==’U’ Or i== u’):
u=u+1
print(“E :”, e)
print(“U :”, u)
f.close( )

Questions 28.
(a) Write the outputs of the SQL queries (i) to (iv) based on the relations Teacher and Placement given below: [3]
Table: Teacher

Name Age Department Date_of_join Salary Gender
Arunan 34 Computer Sc. 2019-01-10 12000 M
Saman 31 History 2017-03-24 20000 F
Randeep 32 Mathematics 2020-12-12 30000 M
Samira 35 History 2018-07-01 40000 F
Raman 42 Mathematics 2021-09-05 25000 M
Shyam 50 History 2019-06-27 30000 M
Shiv 44 Computer Sc. 2019-02-25 21000 M
Shalakha 33 Mathematics 2018-07-31 20000 F

Table: Placement

P_ID Department Place
1 History Ahmedabad
2 Mathematics Jaipur
3 Computer Sc. Nagpur

(i) SELECT Department, avg(salary) FROM Teacher GROUP BY Department;
(ii) SELECT MAX(Date_ofJoin), MIN(Date_ofJoin) FROM Teacher;
(iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE T.Department = P.Department AND Salary>20000;
(iv) SELECT Name, Place FROM Teacher T, Placement P WHERE Gender -F’ AND T.Department=P.Department;
(b) Write the command to view all tables in a database.
Answer:
(a) (i)

Department (Salary)
Computer Science 16500
History 30000
Mathematics 25000

(ii)

MAX. (Date_Join) MIN. (Date_Join)
2021-09-05 2017-03-24

(iii)

NAME SALARY DEPARTMENT PLACE
RANDEEP 30000 MATHEMATICS JAIPUR
SAMIRA 40000 HISTORY AHMEDABAD
RAMAN 25000 MATHEMATICS JAIPUR
SHYAM 30000 HISTORY AHMEDABAD
SHIV 21000 COMPUTER SC. NAGPUR

(iv)

NAME PLACE
SAMAN AHMEDABAD
SAMIRA AHMEDABAD
SHALAKHA JAIPUR

(b) Show TABLES;

Questions 29.
Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the function. The function returns another list named ‘indexList’ that stores the indices of all Non-Zero Elements of L. [3]
For example:
If L contains [12,4,0,11,0,56]
The indexList will have – [0,1,3,5]
Answer:
def index_list(L):
indexList=[ ]
for a in range(0,Len(L)):
if not L[a]=0:
indexList. append (a)
return L

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Question 30.
A list contains following record of a customer: [3]
[Customer_name, Phone_number, City]
Write the following user defined functions to perform given operations on the stack named ‘status’:
(i) Push_element( ) – To Push an object containing name and Phone number of customers who live in Goa to the stack.
(ii) Pop_element( ) – To Pop the objects from the stack and display them. Also, display “Stack Empty” when there are no elements in the stack.
For example:
If the lists of customer details are:
[“Gurdas”, “99999999999”,”Goa”]
[“Julee”, “8888888888”,”Mumbai”]
[“Murugan”,”77777777777″,”Cochin”]
[“Ashmit”, “1010101010”,”Goa”]

The stack should contain
[“Ashmit”,”1010101010″]
[“Gurdas”,”9999999999″]

The output should be:
[“Ashmit”,”1010101010″]
[“Gurdas”,”9999999999″]
Stack Empty
OR
Write a function in Python, Push(SItem) where, SItem is a dictionary containing the details of stationary items- [Sname:price], The function should push the names of those items in the stack who have price greater than 75. Also display the count of elements pushed into the stack.

For example:
If the dictionary contains the following data:
Ditem={“Pen”:106/”Pencil”:59/”Notebook”:80,”Eraser”:25}

The stack should contain
Notebook
Pen

The output should be:
The count of elements in the stack is 2
Answer:
(i) def Push_element(custLst):
for rec in custLst:
if rec[2]=”Goa”:
status.append(rec)

(ii) def Pop_element(custLst):
for a in range(-l,-l*len(custLst)-l,-l):
print(custLst[a])
print(“Stack Empty”)
OR
stackltem=[ ]
def Push(SItem):
count=0
for k in SItem:
if (SItem [k] >=75):
stackltem.append(k)
count=count+l
print(“The count of elements in the stack is : “, count)
(1 mark for correct function header
1 mark for correct loop .
1/2 mark for correct if statement
1/2 mark for correct display of count)

Section-D

Question 31.
Makelnlndia Corporation, an Uttarakhand based IT training company, is planning to set up training centres in various cities in next 2 years. Their first campus is coming up in Kashipur district. At Kashipur campus, they are planning to have 3 different blocks for App development, Web designing and Movie editing. Each block has number of computers, which are required to be connected in a network for communication, data and resource sharing. As a network consultant of this company, you have to suggest the best network related solutions for them for issues/problems raised in question nos. (i) to (v), keeping in mind the distances between various blocks/locations and other given parameters.
CBSE Sample Papers for Class 12 Computer Science Set 1 Img 1
Distance between various blocks/locations:

Block Distance
App development to Web designing 28 m
App development to Movie editing 55 m
Web designing to Movie editing 32 m
Kashipur Campus to Mussoorie Campus 232 km

Number of computers:

Block Number of Computers
App development 75
Web designing 50
Movie editing 80

(i) Suggest the most appropriate block/location to house the SERVER in the Kashipur campus (out of the 3 blocks) to get the best and effective connectivity. Justify your answer. [1]
(ii) Suggest a device/software to be installed in the Kashipur Campus to take care of data security. [1]
(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to economically connect various blocks within the Kashipur Campus. [1]
(iv) Suggest the placement of the following devices with appropriate reasons: [1]
(a) Switch/Hub
(b) Repeater

(v) Suggest a protocol that shall be needed to provide Video Conferencing solution between Kashipur Campus and Mussoorie Campus. [1]
Answer:
(i) Movie Editing block, as it has the maximum number of computers.
(ii) Antivirus software and a Firewall
(iii) OFC – Optical fibre cable
Cable Layout
CBSE Sample Papers for Class 12 Computer Science Set 1 Img 2
(iv) Switch/Hub to be placed in all buildings, as all have multiple computers that need to be connected. Repeater to be placed between App Development and Movie Editing blocks as the distance between them is larger.

(v) VoIP – Voice over internet protocol.

Question 32.
(a) Write the output of the code given below: [2+3]
p=5
def sum(q,r=2):
global p
p=r+q**2
print(p, end= ‘#’)
a=10
b=5
sum(a,b)
sum(r=5,q=l)

(b) The code given below inserts the following record in the table Student:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:

  • Username is root
  • Password is tiger
  • The table exists in a MYSQL database named school.
  • The details (RollNo, Name, Clas and Marks) 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 mysql
def sql_data( ):
coni =mysql.connect(host=,Tocalhost”,user=” root”,
password=”tiger”, database=”school”)
mycursor=______ #Statement 1
rno=int(input(“Enter Roll Number :: “)
name=input(“Enter name::”)
clas=int(input(“Enter class::”))
marks=int(input(“Enter Marks:: “))
querry=”insert into student
values({ },'{ }’,{ },{ })”.format(mo,name,clas,marks)
______ #Statement 2
______ # Statement 3
print(“Data Added successfully”)
OR
(a) Predict the output of the code given below:
s=”welcome2cs”
n = len(s)
m='” ”
for i in range(0, n):
if (s[i] >= ‘a’ and s[i] <= ‘m’):
m = m +s[i].upper( )
elif (s[i] >= ‘n’ and s[i] <= ‘z’):
m = m +s[i-l]
elif (s[i].isupper( )):
m = m + s[i].lower( )
else:
m = m +’&’
print(m)

(b) The code given below reads the following record from the table named student and displays only those records who have marks greater than 75:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:

  • Username is root
    (Computer Science) Sample Question Paper – 11
  • Password is tiger
  • The table exists in a MYSQL database named school.

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 students whose marks are greater than 75.
Statement 3- to read the complete result of the query (records whose marks are greater than 75) into the object named data, from the table student in the database, import mysql.connector as mysql
def sql_data( ):
coni =mysql.connect(host=’Tocalhost”,user=”root”,password=”tiger”, database=”school”)
mycursor= #Statement 1
print(“Students with marks greater than 75 are : “)
______ #Statement 2
data=______#Statement 3
for i in data:
print(i)
print( )
Answer:
(a) 105#6#
The function sum( ) is called 1st time with values 10,5
In the 2nd instance it is called with values q=l, r=5. The expression p=r+q**2 is evaluated and p is printed.
Statementl: conl.cursor( )
Statement2:mycursor.execute(querry)
Statement3:conl.commit( )
OR
(a) Output:
sELCcME&Cc
The code picks each character from the string and after checking of the character in a set of values, changes the character and adds it a new string.
The new string is printed.

(b) Statementl: conl.cursor( )
Statement2:mycursor.execute(“Select * from student where marks>75”)
Statement3:mycursor.fetchall()

CBSE Sample Papers for Class 12 Computer Science Set 1 with Solutions

Question 33.
What is the advantage of using a CSV file for permanent storage? [5]
Write a Program in Python that defines and calls the following user defined functions:

(i) ADD( ) – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a list with field elements as empid, name and mobile to store employee id, employee name and employee salary respectively.

(ii) COUNTR( ) – To count the number of records present in the CSV file named ‘record.csv’.
OR
Give any one point of difference between a binary file and a CSV file.
Write a Program in Python that defines and calls the following user defined functions:

(i) add( ) – To accept and add data of an employee to a CSV file ‘furdata.csv’. Each record consists of a list with field elements as fid, fname and fprice to store furniture id, furniture name and furniture price respectively.

(ii) search( )- To display the records of the furniture whose price is more than 10000.
Answer:
A csv file is a simple file like a text file that can store data values separated by comma. It provides a record type structures that can be used in database or dataframe format. Hence it can be used in various applications like python panda data structures, Excel and database applications.

Advantage of a CSV file:

  • It is human readable – can be opened in Excel and Notepad applications.
  • It is just like text file.

Program:
import CSV
def ADD( ):
fout=open (“record.csv”, “a”, newline=”\n”)
wr=csv.writer(fout)
empid=int (input (“Enter Employee id :: “))
name=input(“Enter name::”)
mobile=int(input(“Enter mobile number :: “))
1st=[empid, name, mobile]______1/2 mark
wr.writerow(1st)______1/2 mark
fout.close( )
defCOUNTR( ):
fin=open (“record.csv”, “r”, newline=”\n”)
data=csv.reader(fin)
d=list (data)
print (len (d))
fin.close( )
ADD( )
COUNTR( )
(1 mark for advantage
1/2 mark for importing csv module
1I/2 marks each for correct definition of ADD() and COUNTR()
1/2 mark for function call statements)
OR
Answer:
Binary file : A binary file is stored in binary format and easy, fast for the computer to process.
CSV file – It is a simple text file storing data in text format in a record structure separating data by comma.
Difference between binary file and CSV file: (Any one difference may be given)

Binary File:

  • Extensionis.dat
  • Not human readable
  • Stores data in the form of Os and Is

CSV file:

  • Extension is.csv
  • Human reaidable
  • Stores data like a text file

Program:
(i) 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( )

(ii) 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[l], i[2])
if found=False:
print(“Record not found”)
fin.close( )
add( )
print(“Now displaying”)
search( )
(1 mark for difference
1/2 mark for importing csv module
11/2 marks each for correct definition of add() and search()
1/2 mark for function call statements)

Section-E

Question 34.
Navdeep creates a table RESULT with a set of records to maintain the marks secured by students in Semi, Sem2, Sem3 and their division. After creation of the table, he has entered data of 7 students in the table. [1+1+2]

SNAME SEM1 SEM2 SEM3 DIVISION
KARAN 366 410 402 I
NAMAN 300 350 325 I
ISHA 400 410 415 I
RENU 350 357 415 I
ARPIT 100 75 178 IV
SABINA 100 205 217 II
NEELAM 470 450 471 I

Based on the c ata given above answer the following questions:

(i) Identify the most appropriate column, which can be considered as Primary key.
(ii) If two columns are added and 2 rows are deleted from the table result, what will be the new degree and cardinality of the above table?

(iii) Write the statements to:
(a) Insert the following record into the table Roll No-108, Name- Aadit, Semi- 470, Sem2-444, Sem3-475, Div -1.
(b) Increase the SEM2 marks of the students by 3% whose name begins with ‘N’.
OR
(iii) Write the statements to:
(a) Delete the record of students securing IV division.
(b) Add a column REMARKS in the table with datatype as varchar with 50 characters.
Answer:
(i) ROLL_NO
(ii) Degree : 8 Cardinality : 5
(iii) (a) Insert into RESULT values(108,” Aadit”,470,444,475,”Div -1″);
(b) Update RESULT Set SEM2=SEM2+ SEM*0.03 where SNAME Like “N%”;
OR
(iii) (a) Delete from RESULT where DIVISION=”IV”;
(b) Alter table RESULT ADD column Remarks varchar(50);

Question 35.
Aman is a Python programmer. He has written a code and created a binary file record.dat with employeeid, ename and salary. The file contains 10 records.
He now has to update a record based on the employee id entered by the user and update the salary. The updated record is then to be written in the file temp.dat. The records which are not to be updated also have to be written to the file temp.dat. If the employee id is not found, an appropriate message should to be displayed.
As a Python expert, help him to complete the following code based on the requirement given above:
import ______ #Statement 1
def update_data( ):
rec={ }
fin=open(“record.dat”,”rb”)
fout=open(“______”) #Statement 2
found=False
eid=int(input(“Enter employee id to update their salary :: “))
while True:
try:
rec=______#Statement 3
if rec[“Employee id”]=eid:
found=True
rec[“Salary”]=int(input(‘/Enter new salary :: “))
pickle.______#Statement 4
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print(“The salary of employee id “,eid,” has been updated.”)
else:
print(“No employee with such id is not found”)
fin.close( )
fout.close( )
(i) Which module should be imported in the program? (Statement 1) [1]
(ii) Write the correct statement required to open a temporary file named temp.dat. (Statement 2) [1]
(iii) Which statement should Aman fill in Statement 3 to read the data from the binary file, record.dat and in Statement 4 to write the updated data in the file, temp.dat? [2]
Answer:
(i) pickle
(ii) “temp.dat”,”w”
(iii) pickle.load(fin) pickle.dump(rec,fout)