0% found this document useful (0 votes)
98 views44 pages

CBSE Computer Science Class 12 Question Paper 2024 Solutions FREE PDF

Uploaded by

Test Id
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)
98 views44 pages

CBSE Computer Science Class 12 Question Paper 2024 Solutions FREE PDF

Uploaded by

Test Id
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/ 44

CBSE Class 12 Computer Science Question Paper 2024

Set 4 (Code No. 91) Solutions

SECTION - A

1. State True or False. 1

"Identifiers are names used to identify a variable, function in a program'

Ans: True

2. Which of the following is a valid keyword in Python? 1

(a) false (b) return

(c) non_local (d) none

Ans: (b) return

3. Given the following Tuple 1 Tup= (10, 20, 30, 50)

Which of the following statements will result in an error?

(a) print (Tup[0] )

(b) Tup. insert (2, 3)

(c) print (Tup [1 : 2] )

www.vedantu.com 1
(d) print (len (Tup) )

Ans: (b) Tup.insert (2, 3)

4. Consider the given expression:

5<10 and 12>7 or not 7>4

Which of the following will be the correct output, if the given expression is evaluated? 1

(a)True (b) False

(c) NONE (d) NULL

Ans: (a) True

5. Select the correct output of the code: 1

S= "Amrit Mahotsav @ 75"

A=S. partition (“ " )

print (a)

(a) ( 'Amrit Mahotsav' , '@ ' , ' 7 5 ' )


(b) [ 'Amrit' , 'Mahotsav' , ' @ ' 7 5 ' ]
(c) 'Amrit’, ‘Mahotsav @ 75 ' )
(d) ( 'Amrit' , ‘’,'Mahotsav @ 75' )

Ans: (d) ( 'Amrit' , '' , 'Mahotsav @ 75' )

www.vedantu.com 2
6. Which of the following mode keeps the file offset position at the end of the file? 1

(a) r+ (c) w

(b) r (d) a

Ans: (d) a

7. Fill in the blank. 1

function is used to arrange the elements of a list in ascending order.

(a) sort()

(b) arrange ()

(c) ascending()

(d) asort()

Ans: (a) sort()

8. Which of the following operators will return either True or False? 1

(a) += (c) =

(b)! = (d) *=

Ans: (b) !=

www.vedantu.com 3
9. Which of the following statement(s) would give an error after executing the following
code? 1

Stud= {"Murugan":100, "Mithu":95) # Statement 1

print (Stud [95]) # Statement 2

Stud ["Murugan"]=99 # Statement 3

print (Stud.pop()) # Statement 4

print (Stud) # Statement 5

(a) Statement 2 (c) Statement 4.

(b) Statement 4 (d) Statement 2 and 4

Ans: (a) Statement 2

10. Fill in the blanks.

is a number of tuples in a relation.

(a) Attribute

(b) Degree

(c) Domain

(d) Cardinality

Ans: (d) Cardinality

www.vedantu.com 4
11. The syntax of seek is: 1

file_object.seek(offset [, reference_point])

What is the default value of reference_point?

(a) 0 (c) 2

(b) 1 (d) 3

Ans: (a) 0

12. Fill in the blank:

clause is used with SELECT statement to display data in a sorted form with
respect to a specified column. 1

(a) WHERE (c) HAVING

(b) ORDER BY (d) DISTINCT

Ans: (b) ORDER BY

13. Fill in the blank:

is used for point-to-point communication or unicast communication such as


radar and satellite. 1

(a) INFRARED WAVES

(b) BLUETOOTH

(c) MICROWAVES

www.vedantu.com 5
(d) RADIOWAVES

Ans: (c) MICROWAVES

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

print (4+3* 5/3-582) 1

(a) 8.5

(b) 8.0

(c) 10.2

(d) 10.0

Ans: (a) 8.5

15. Which function returns the sum of all elements of a list? 1

(a) count ()

(b) sum ()

(c) total ()

(d) add ()

Ans: (b) sum ()

www.vedantu.com 6
16. fetchall() method fetches all rows in a result set and returns a: 1

(a) Tuple of lists

(b) List of tuples

(c) List of strings

(d) Tuple of strings

Ans: (b) List of tuples

Q. 17 and 18 are ASSERTION (A) and REASONING (R) 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 for (A).

(c) (A) is true but (R) is false.

(d) (A) is false but (R) is true.

17. Assertion (A): To use a function from a particular module, we need to import the
module.

Reason (R): import statement can be written anywhere in the program, before using a
function from that module. 1

Ans: (b) Both (A) and (R) are true and (R) is not the correct explanation for (A).

www.vedantu.com 7
18. Assertion (A): A stack is a LIFO structure.

Reason (R) Any new element pushed into the stack always gets positioned at the index
after the last existing element in the stack 1

Ans: (a) Both (A) and (R) are true and (R) is the correct explanation for (A).

SECTION B

19. Atharva is a Python programmer working on a program to find and return the
maximum value from the list. The code written below has syntactical errors. Rewrite
the correct code and underline the corrections made. 2

def max_num (L):

max-L (0)

for a in L :

if a > max

max=a

return max

Ans:

Corrected code:

def max_num(L):

max1 = 0

for a in L:

www.vedantu.com 8
if a > max1:

max1 = a

return max1

20. (a) Differentiate between wired and wireless transmission. 2

Ans:

Wired Transmission:

• Uses physical cables such as twisted pair, coaxial, or fiber-optic cables.

• Offers higher security as data is transmitted through physical mediums.

• Generally provides faster and more stable connections.

Wireless Transmission:

• Uses radio waves, microwaves, or infrared signals to transmit data.

• More convenient and flexible as it doesn't require physical connections.

• May suffer from interference and generally has a lower speed compared to wired
transmission.

www.vedantu.com 9
OR

(b) Differentiate between URL and domain name with the help of an appropriate
example. 2

Ans:

URL (Uniform Resource Locator): It is the complete address used to access a resource on
the internet. For example, https://www.example.com/index.html is a URL that includes the
protocol (https), domain name (www.example.com), and path (/index.html).

Domain Name: It is a part of the URL that identifies the website. For example, in the URL
https://www.example.com/index.html, the domain name is example.com.

21. (a) Given is a Python list declaration: 1

Listofnames=["Aman", "Ankit", "Ashish", "Rajan", "Rajat"]

Write the output of:

print (Listofnames (-1:-:-1])

Ans:

print(Listofnames[-1::-4:-1])

# Output: ['Raj', 'Rajan', 'Ashish']

www.vedantu.com 10
(b) Consider the following tuple declaration: 1

tup1=(10, 20, 30, (10, 20, 30), 40)

Write the output of:

print (tupl.index (20))

Ans:

print(tupl.index(20))

# Output: 1

22. Explain the concept of "Alternate Key" in a Relational Database Management


System with an appropriate example. 2

Ans: An Alternate Key is a column or set of columns in a table that can uniquely identify a
record, but which is not the primary key. There can be multiple alternate keys in a table.
Alternate keys are also known as candidate keys, and they provide an alternative way to
identify records uniquely apart from the primary key.

23. (a) Write the full forms of the following: 2

(i) HTML

(ii) TCP

Ans:

(i) HTML: HyperText Markup Language


(ii) TCP: Transmission Control Protocol

www.vedantu.com 11
(b) What is the need of Protocols?

Ans: Protocols are needed to establish rules for data exchange over networks. They ensure
that devices can communicate effectively, securely, and reliably. Protocols define the syntax,
semantics, and synchronization of communication and allow different devices from various
manufacturers to work together seamlessly. They also handle error detection, data
compression, and encryption, making data transfer efficient and secure.

24. (a) Write the output of the code given below:

def short sub (1st,n) :

for i in range (0,n):

if len (1st)>4:

1st [i]=1st [i]+1st[i]

else:

1st [i]=1st (i)

subject= ['CS', 'HINDI', 'PHYSICS', 'CHEMISTRY', 'MATHS']

short_sub(subject,5)

print (subject)

Ans:

# ['CSCS', 'HINDIHINDI', 'PHYSICSPHYSICS', 'CHEMISTRYCHEMISTRY',


'MATHSMATHS']

www.vedantu.com 12
OR

(b) Write the output of the code given below: 2

a =30

def call (x):

global a

if a%2= =0:

else:

x-=a

return

x=20

print (call (35), end="#")

print (call (40), end- "@")

Ans:

# 5#70@

www.vedantu.com 13
25. (a) Differentiate between CHAR and VARCHAR data types in SQL with appropriate
example. 2

Ans:

CHAR: CHAR is a fixed-length data type. When a CHAR column is defined with a specific
length, it always reserves that number of characters, regardless of the actual data length. If the
data is shorter than the defined length, the remaining space is padded with spaces.

• Example: CHAR(10) will always use 10 bytes of storage, even if the data is only 3
characters long (e.g., 'abc' will be stored as 'abc ').

VARCHAR: VARCHAR is a variable-length data type. When a VARCHAR column is defined


with a specific length, it only uses as much storage space as the actual data plus one or two
extra bytes for length information. No padding is added.

• Example: VARCHAR(10) will use only as many bytes as needed to store the actual
data (e.g., 'abc' will use 3 bytes).

OR

(b) Name any two DDL and any two DML commands. 2

Ans:

DDL (Data Definition Language) Commands:

1. CREATE: Used to create a new table, database, index, or view.

2. ALTER: Used to modify an existing database object, such as a table.

DML (Data Manipulation Language) Commands:

1. INSERT: Used to add new rows of data to a table.

www.vedantu.com 14
2. UPDATE: Used to modify existing data in a table.

SECTION - C

26. (a) Consider the following tables-LOAN and BORROWER: 1+2

Table: LOAN

LOAN_NO B_NAME AMOUNT

L-170 DELHI 3000

L-230 KANPUR 4000

Table: BORROWER

CUST_NAME LOAN_NO

JOHN L-171

KRISH L-230

RAVYA L-170

How many rows and columns will there be in the natural join of these two tables?

Ans: The natural join of the tables LOAN and BORROWER will be based on the common
column LOAN_NO.

www.vedantu.com 15
Joined Table:

LOAN_NO B_NAME AMOUNT CUST_NAME

L-170 DELHI 3000 RAVYA

L-230 KANPUR 4000 KRISH

• Number of Rows: 2 (since two rows from BORROWER table match with the LOAN
table)

• Number of Columns: 4 (LOAN_NO, B_NAME, AMOUNT, CUST_NAME)

So, the natural join of these two tables will result in 2 rows and 4 columns.

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

TABLE: WORKER

W_ID F_NAME L_NAME CITY STATE

102 SAHIL KHAN KANPUR UTTARPRADESH

104 SAMEER PARIKH ROOPNAGAR PUNJAB

105 MARY JONES DELHI DELHI

106 MAHIR SHARMA SONIPAT HARYANA

107 ATHARVA BHARDWAJ DELHI DELHI

108 VEDA SHARMA KANPUR UTTARPRADESH

www.vedantu.com 16
(i) SELECT F_NAME, CITY FROM WORKER ORDER BY STATE DESC;

Ans:

Output:

F_NAME CITY

SAMEER ROOP NAGAR

MAHIR SONIPAT

SAHIL KANPUR

VEDA KANPUR

MARY DELHI

ATHARVA DELHI

(ii) SELECT DISTINCT (CITY) FROM WORKER;

Ans:

Output:

CITY

KANPUR

ROOP NAGAR

www.vedantu.com 17
CITY

DELHI

SONIPAT

(iii) SELECT F NAME, STATE FROM WORKER WHERE L_NAME LIKE '_HA';

Ans:

Output:

F_NAME STATE

ATHARVA DELHI

(iv) SELECT CITY, COUNT(*) FROM WORKER GROUP BY CITY;

Ans:

Output:

CITY COUNT(*)

KANPUR 2

ROOP NAGAR 1

www.vedantu.com 18
CITY COUNT(*)

DELHI 2

SONIPAT 1

27. (a) Write the definition of a Python function named LongLines ( )

which reads the contents of a text file named 'LINES.TXT' and displays those lines from
the file which have at least 10 words in it. For example, if the content of 'LINES.TXT' is
as follows: 3

Once upon a time, there was a woodcutter

He lived in a little house in a beautiful, green wood.

One day, he was merrily chopping some wood.

He saw a little girl skipping through the woods, whistling happily.

The girl was followed by a big gray wolf.

Then the function should display output as:

He lived in a little house in a beautiful, green wood.

He saw a little girl skipping through the woods, whistling happily.

www.vedantu.com 19
Ans:

def LongLines():

with open('LINES.TXT', 'r') as file:

lines = file.readlines()

for line in lines:

words = line.split()

if len(words) >= 10:

print(line.strip())

# Example content of LINES.TXT:

# Once upon a time, there was a woodcutter

# He lived in a little house in a beautiful, green wood.

# One day, he was merrily chopping some wood.

# He saw a little girl skipping through the woods, whistling happily.

# The girl was followed by a big gray wolf.

# The function should display:

# He lived in a little house in a beautiful, green wood.

# He saw a little girl skipping through the woods, whistling happily.

www.vedantu.com 20
OR

(b) Write a function count_Dwords() in Python to count the words ending with a digit in
a text file "Details.txt".

Example:

If the file content is as follows:

On seat2 VIP1 will sit and

On seat1 VVIP2 will be sitting

Output will be:

Number of words ending with a digit are 4

Ans:

def count_Dwords():

count = 0

with open('Details.txt', 'r') as file:

content = file.read().split()

for word in content:

if word[-1].isdigit():

count += 1

print(f"Number of words ending with a digit are {count}")

www.vedantu.com 21
# Example content of Details.txt:

# On seat2 VIP1 will sit

# On seat1 VIP2 will be sitting

# Output will be:

# Number of words ending with a digit are 4

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

Table: COMPUTER

www.vedantu.com 22
Table: SALES

(i) SELECT MIN (PRICE), MAX (PRICE) FROM COMPUTER;

Ans:

Output:

MIN(PRICE) MAX(PRICE)

200 4300

www.vedantu.com 23
(ii) SELECT COMPANY, COUNT(*) FROM COMPUTER GROUP BY COMPANY
HAVING COUNT(COMPANY) > 1;

Ans:

Output:

COMPANY COUNT(*)

LOGITECH 2

CANON 2

(iii) SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C, SALES S WHERE


C.PROD_ID=S. PROD_ID AND TYPE = 'INPUT';

Ans:

Output:

PROD_NAME QTY_SOLD

MOUSE 3

KEYBOARD 2

JOYSTICK 3

www.vedantu.com 24
(iv) SELECT PROD_NAME, COMPANY, QUARTER FROM COMPUTER C, SALES
S WHERE C. PROD_ID=S. PROD_ID;

Ans:

Output:

PROD_NAME COMPANY QUARTER

LASER PRINTER CANON 1

KEYBOARD LOGITECH 1

JOYSTICK IBALL 2

MOUSE LOGITECH 1

(b) Write the command to view all databases. 1

Ans:

SHOW DATABASES;

29. Write a function EOReplace() in Python, which accepts a list L of numbers.


Thereafter, it increments all even numbers by 1 and decrements all odd numbers by 1.

Example: 3

If Sample Input data of the list is:

L = [10, 20, 30, 40, 35,55]

www.vedantu.com 25
Output will be:

L = [11,21,31,41,34,54]

Ans:

def EOReplace(L):

for i in range(len(L)):

if L[i] % 2 == 0:

L[i] += 1

else:

L[i] -= 1

return L

# Example usage:

L = [10, 20, 30, 40, 35, 55]

print(EOReplace(L)) # Output: [11, 21, 31, 41, 34, 54]

30. (a) A list contains following record of customer: 3

[Customer_name, Room Type]

Write the following user defined functions to perform given operations on the stack
named 'Hotel':

www.vedantu.com 26
(i) Push Cust() To Push customers' names of those customers who are staying in 'Delux'
Room Type.

Ans:

def Push_Cust(customers, stack):

for customer in customers:

if customer[1] == 'Delux':

stack.append(customer[0])

# Example usage:

customers = [("Siddarth", "Delux"), ("Rahul", "Standard"), ("Jerry", "Delux")]

stack = []

Push_Cust(customers, stack)

print(stack) # Output: ['Siddarth', 'Jerry']

(ii) Pop Cust() To Pop the names of customers from the stack and display them. Also,
display "Underflow" when there are no customers in the stack.

For example:

If the lists with customer details are as follows:

["Siddarth", "Delux"]

("Rahul", "standard"]

www.vedantu.com 27
["Jerry", "Delux"]

The stack should contain Jerry

Siddharth

The output should be:

Jerry

Siddharth

Underflow

Ans:

def Pop_Cust(stack):

if len(stack) == 0:

print("Underflow")

else:

print(stack.pop())

# Example usage:

stack = ['Siddarth', 'Jerry']

Pop_Cust(stack) # Output: Jerry

Pop_Cust(stack) # Output: Siddarth

Pop_Cust(stack) # Output: Underflow

www.vedantu.com 28
OR

(b) Write a function in Python, Push (Vehicle) where, Vehicle is a dictionary containing
details of vehicles (Car_Name: Maker). 3

The function should push the name of car manufactured by "TATA' (including all the
possible cases like Tata, TaTa, etc.) to the stack.

For example:

If the dictionary contains the following data:

Vehicle={"Santro": "Hyundai", "Nexon": "TATA", "Safari": "Tata"}

The stack should contain

Safari

Nexon

Ans:

def Push(Vehicle, stack):

for car, maker in Vehicle.items():

if maker.lower() == 'tata':

stack.append(car)

# Example usage:

Vehicle = {"Santro": "Hyundai", "Nexon": "TATA", "Safari": "Tata"}

www.vedantu.com 29
stack = []

Push(Vehicle, stack)

print(stack) # Output: ['Nexon', 'Safari']

SECTION D

31. Quickdev, an IT based firm, located in Delhi is planning to set up a network for its
four branches within a city with its Marketing department in Kanpur. As a network
professional, give solutions to the questions (i) to (v), after going through the branches
locations and other details which are given below:

Distance between various branches is as follows:

www.vedantu.com 30
Number of computers in each of the branches:

(i) Suggest the most suitable place to install the server for the Delhi branch with a
suitable reason. 1

Ans: The most suitable place to install the server for the Delhi branch is Branch D. This
decision is based on the following reasons:

• Number of Computers: Branch D has the highest number of computers (115) among
all branches, which indicates a higher demand for server resources.

• Central Location: Branch D is relatively central compared to the other branches. The
distances from Branch D to other branches are relatively short, which minimizes
latency and ensures better network performance.

www.vedantu.com 31
(ii) Suggest an ideal layout for connecting all these branches within Delhi. 1

Ans: An ideal layout for connecting all branches within Delhi would be a Star Topology. In
this topology, all the branches are connected to a central hub or switch. This allows for
efficient communication and management of the network.

(iii) Which device will you suggest, that should be placed in each of these branches to
efficiently connect all the computers within these branches? 1

Ans:

I would suggest placing Switches in each of these branches. Switches are efficient network
devices that allow multiple computers within a branch to communicate with each other and
with the central hub or switch in a star topology.

(iv) Delhi firm is planning to connect to its Marketing department in Kanpur which is
approximately 300 km away. Which type of network out of LAN, WAN or MAN will be
formed? Justify your answer. (v) Suggest a protocol that shall be needed to provide help
for transferring of files between Delhi and Kanpur branch. 1

Ans:

A WAN (Wide Area Network) will be formed. WAN is suitable for connecting networks over
large geographical distances, such as between cities or even countries. In this case,
connecting Delhi to Kanpur, which is 300 km away, requires a WAN setup.

www.vedantu.com 32
(v). Suggest a protocol that shall be needed to provide help for transferring of files
between Delhi and Kanpur branch.

Answer: The FTP (File Transfer Protocol) would be suitable for transferring files between
the Delhi and Kanpur branches. FTP is specifically designed for transferring files over a
network and is reliable for long-distance communication.

32. (a) What possible output(s) are expected to be displayed on screen at the time of
execution of the following program: 2

import random

M-(5,10,15,20,25,30)

for i in range (1,3):

first=random.randint (2,5)-1

sec=random.randint(3, 6) - 2

third-random.randint (1,4)

print (M[first], M[sec], M[third], sep="#")

(i) 10+25 15

20+25+25

(ii) 5#25#20

25#20 15

(iii) 30#20 20

20+25+25

www.vedantu.com 33
(iv) 10#15 #25#

15#20#104

Ans:

Possible outputs: (i) 10#25#15


(ii) 5#25#20
(iii) 30#20#20
(iv) 20#25#25
(v) 15#20#10

(b) The code given below deletes the record from the table employee which contains the
following record structure:

E_code - String

E_name - String

Sal - Integer

City-String

Note the following to establish connectivity between Python and MySQL:


Username is root
Password is root
The table exists in a MySQL database named emp.
The details (E_code, E_name, Sal, City) are the attributes of the table.

Write the following statements to complete the code:

Statement 1- to import the desired library.

Statement 2- to execute the command that deletes the record with E_code as 'E101'.

www.vedantu.com 34
Statement 3- to delete the record permanently from the database.

import as mysql #Statement 1

def delete():

mydb-mysql.connect (host="localhost", user-"root", passwd="root", database="emp")

mycursor-mydb.cursor()

# Statement 2

#Statement 3

print ("Record deleted") 3

Ans:

import mysql.connector as mysql # Statement 1

def delete():

mydb = mysql.connect(host="localhost", user="root", passwd="root", database="emp")

mycursor = mydb.cursor()

mycursor.execute("DELETE FROM employee WHERE E_code = 'E101'") # Statement 2

mydb.commit() # Statement 3

print("Record deleted")

www.vedantu.com 35
33. (a) Write one difference between CSV and text files. 5

Write a program in Python that defines and calls the following user defined functions:

(i) COURIER_ADD (): It takes the values from the user and adds. The details to a csv
file ‘courier.csv’. Each record consists of a list with field elements as cid, s_name,
Source, destination to store Courier ID, Sender name, Source and destination address
respectively.

Ans:

CSV (Comma-Separated Values): CSV files store tabular data (numbers and text) in plain
text, where each line of the file corresponds to a row in the table, and each field in the row is
separated by a comma.

Text Files: Text files store plain text without any specific structure or formatting rules, so the
data can be any combination of characters.

Python function:

import csv

def COURIER_ADD():

with open('courier.csv', mode='a', newline='') as file:

writer = csv.writer(file)

c_id = input("Enter Courier ID: ")

s_name = input("Enter Sender Name: ")

source = input("Enter Source: ")

www.vedantu.com 36
destination = input("Enter Destination: ")

writer.writerow([c_id, s_name, source, destination])

# Calling the function

COURIER_ADD()

(ii) COURIER SEARCH() Takes the destination as the input and displays all the
courier records going to that destination.

Ans:

Python function:

import csv

def COURIER_SEARCH(destination):

with open('courier.csv', mode='r') as file:

reader = csv.reader(file)

for row in reader:

if row[3] == destination:

print(row)

www.vedantu.com 37
# Example usage:

COURIER_SEARCH("Delhi")

OR

(b) Why it is important to close a file before exiting?

Write a program in Python that defines and calls the following user defined functions:5

(i) Add_Book(): Takes the details of the books and adds them to a csv file 'Book.csv".
Each record consists of a list with field elements as book_ID, B_name and pub to store
book ID, book name and publisher respectively.

Ans:

Python function:

import csv

def Add_Book():

with open('Book.csv', mode='a', newline='') as file:

writer = csv.writer(file)

book_id = input("Enter Book ID: ")

b_name = input("Enter Book Name: ")

pub = input("Enter Publisher: ")

writer.writerow([book_id, b_name, pub])

www.vedantu.com 38
# Calling the function

Add_Book()

(ii) Search Book(): Takes publisher name as input and counts and displays number of
books published by them.

Ans:

Python function:

import csv

def Search_Book(publisher):

count = 0

with open('Book.csv', mode='r') as file:

reader = csv.reader(file)

for row in reader:

if row[2] == publisher:

count += 1

print(f"Number of books published by {publisher}: {count}")

www.vedantu.com 39
# Example usage:

Search_Book("Penguin")

SECTION - E

34. The school has asked their estate manager Mr. Rahul to maintain the data of all the
labs in a table LAB. Rahul has created a table and entered. data of 5 labs.

Based on the data given above answer the following questions:

(i) Identify the columns which can be considered as Candidate keys. 1

Ans: LABNO

(ii) Write the degree and cardinality of the table. 1

Ans:

Degree: 5 (number of columns)

Cardinality: 5 (number of rows)

www.vedantu.com 40
(iii) Write the statements to: 2

(a) Insert a new row with appropriate data.

Ans:

INSERT INTO LAB (LABNO, LAB_NAME, INCHARGE, CAPACITY, FLOOR) VALUES


('L006', 'PHYSICS', 'Dr. Smith', 25, 'III');

(b) Increase the capacity of all the labs by 10 students which are on 'T' Floor.

Ans:

UPDATE LAB SET CAPACITY = CAPACITY + 10 WHERE FLOOR = 'III';

OR

(Option for part (iii) only)

(iii) Write the statements to: 2

(a) Add a constraint PRIMARY KEY to the column LABNO in the table.

Ans:

ALTER TABLE LAB ADD PRIMARY KEY (LABNO);

www.vedantu.com 41
(b) Delete the table LAB.

Ans:

DROP TABLE LAB;

35. Shreyas is a programmer, who has recently been given a task to write a user defined
function named write_bin() to create a binary file called Cust_file.dat containing
customer information - customer number (c_no), name (c_name), quantity (qty), price
(price) and amount (amt) of each customer.

The function accepts customer number, name, quantity and price. Thereafter, it
displays the message Quantity less than 10..... Cannot SAVE", if quantity entered is less
than 10. Otherwise the function calculates amount as price quantity and then writes the
record in the form of a list into the binary file.

import pickle

def write_bin():

bin_file= #Statement 1

while True:

c_no=int(input("enter customer number"}} c_name-input ("enter customer name")

qty=int(input("enter qty"}}

price-int (input("enter price"))

if #Statement 2

www.vedantu.com 42
print ("Quantity less than 10..Cannot SAVE")

else:

amt-price

qty

c_detail=[c_no, c_name, qty, price, amt]

#Statement 3

ans-input ("Do you wish to enter more records y/n") if ans.lower()=='n':

#Statement 4

#Statement 5

#Statement 6

(i) Write the correct statement to open a file 'Cust_file.dat' for writing the data of the
customer. 1

Ans:

bin_file = open('Cust_file.dat', 'wb') # Statement 1

(ii) Which statement should Shreyas fill in Statement 2 to check whether quantity is less
than 10. 1

Ans:

if int(qty) < 10: # Statement 2

www.vedantu.com 43
(iii) Which statement should Shreyas fill in Statement 3 to write data to the binary file
and in Statement 4 to stop further processing if the user does not wish to enter more
records. 2

Ans:

pickle.dump(c_detail, bin_file) # Statement 3

if ans.lower() != 'y': # Statement 4

break

OR

(Option for part (iii) only)

(iii) What should Shreyas fill in Statement 5 to close the binary file named

Cust_ file.dat and in Statement 6 to call a function to write data in binary file? 2

Ans:

bin_file.close() # Statement 5

write_bin() # Statement 6

www.vedantu.com 44

You might also like