Sure Shot Questions 2024-25 Final
Sure Shot Questions 2024-25 Final
CHANDA
SURE-SHOT QUESTIONS
SUBJECT: COMPUTER SCIENCE (083)
CLASS-XII
SESSION 2024-25
1 MARK QUESTIONS
11. Write name of python module which is to be imported in program to use the
following functions:
i) ceil ( )
ii) date( )
12. Name the python library need to be imported to invoke following functions:
i) randint( )
ii) date( )
16. Suppose a tuple Tup is declared as Tup = (12, 15, 63, 80)
Which of the following is incorrect?
a) print(Tup[1]) b) Tup[2] = 90
c) print(min(Tup)) d) print(len(Tup))
a) 7 b) 6 c) 3 d) 5
a) True b) 4 c) 14 d) -1
a) <class ‘tuple’>
b) <class ‘int’>
c) <class ‘str’>
d) <class ‘list’>
26. 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 the above
32. Which of the following statement(s) would give an error after executing the
following code?
G=10,20,30,40 #statement-1
print(G**2) #statement-2
G[1]=35 #statement-3
R=G+(22,) #statement-4
print(R) #statement-5
33. Which of the following statement(s) would give an error after executing the
following code?
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
36. A result set is extracted from the database using a cursor object by giving the
following statement:
records=mycursor.fetchall( )
What will be the data type of ‘records’ after the execution of above statement?
37. Which among the following is correct output after evaluation of the given
expression:
import math
math.ceil(-6.6)
a) -6 b) -7 c) 6.6 d) -5
38. Which among the following is correct output after evaluation of the given
expression:
>>> 12 - (3 % 4) // 2 + 6 ** 2
a) 46.5 b) 36 c) 12 d) 47
a) 8 b) 4 c) 1 d) 3
42. Which command is used for counting the number of rows in a database?
a) count b) fetchmany c) rowcount d) countrecord
43. readlines( ) method reads the data from the file and returns it into:
a) string b) list c) tuple d) file
46. Which function in SQL is used to count the total number of records regardless of
NULL from table in a database?
a) sum(*)
b) total(*)
c) count(*)
d) count( )
47. 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() ?
a) host
b) database
c) user
d) password
48. After executing any DML command from Python in Python-MySQL connectivity,
following is necessary to execute in order to make the changes permanent in
MySQL:
a) save()
b) store()
c) commit()
d) update()
51. Ravish created a database namely BUSINESS. Now he wants to create a table in it.
For this he needs to open the database that he has created. Write SQL command
to open the database that is created by Ravish.
56. Which among the following transmission mediums provide efficient and the fastest
communication:
a) Twisted pair Cable
b) Optical Fiber Cable
c) Co-axial Cable
d) Telephone cable
65. Which of the following operators will return either True or False ?
a) += b) = c) != d) *=
66. Which of the following statement(s) would give an error after executing
the following code ?
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 b) Statement-3
c) Statement-4 d) Statement-2 and 4
72. Which among the following python modules has fabs() function:
(a) random (b) statistics (c) pickle (d) math
76. Python uses __________ data type for creating and managing stack:
(a) tuple (b) list (c) dictionary (d) None of them
82. Which of the following python statement will bring the read pointer to 10
position backward from end of the file containing 90 characters, if file opened in
binary mode:
a) File.seek(10,0) b) File.seek(-10,2)
c) File.seek(-10,1) d) File.seek(10,2)
85. Which among the following keywords is used to catch exceptions in Python?
a) try b) except c) catch d) finally
a) pickle.write(file) b) file.writer(csv)
c) csv.dump(file) d) csv.writer(file)
95. Which SQL command can change the degree of an existing relation?
96. In which datatype the value stored is padded with spaces to fit the specified length.
(A) DATE (B) VARCHAR (C) FLOAT (D) CHAR
97. Which aggregate function can be used to find the cardinality of a table?
(A) sum() (B) count() (C) avg() (D) max()
98. Which switching technique breaks data into smaller packets for transmission,
allowing multiple packets to share the same network resources.
99. Consider the statements given below and then choose the correct output from the
given options:
pride="General Elections@2024"
L=pride.split(‘e’)
print(L[::-2])
105. The degree and cardinality of a table named SONG are 2 and 4, respectively. The
degree and cardinality of another table named SINGER are 3 and 5, respectively.
There is one common field in both tables. After performing the Cartesian product
of both tables, what will be the new degree and cardinality of the resultant table?
A. 4 and 20 B. 5 and 20
C. 5 and 9 D. 4 and 9
106. Which function in SQL is used to count the total number of records regardless of
NULL from table in a database?
a) sum(*)
b) total(*)
c) count(*)
d) count( )
107. Which error occurs when a variable is used before being initialized in python?
112. A result set is extracted from the database using a cursor object by giving the
following statement:
records=mycursor.fetchall( )
What will be the data type of records,after the execution of above statement?
A. tuple B. string
C. dictionary D. list
1. 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.
Reason(R):- During a function call, the argument list first contains default
argument(s) followed by positional argument(s).
2. Assertion (A): CSV (Comma Separated Values) is a file format for data storage which
looks like a text file.
Reason (R): The information is organized with one record on each line and each field
is separated by comma.
3. Assertion (A): Function invoked by its name.
Reason (R): A function is a named block of statements.
4. Assertion (A): The csv files can only take comma as delimiter.
Reason (R): The comma is the default separator character but other popular
delimiters include the tab (\t), colon (:) and semi-colon (;)
5. Assertion (A): Inside a function if we make changes in a string it will reflect back to
the original string.
Reason (R): String is an immutable datatype and it is called by value.
Mark the correct choice as :
6. Assertion (A): Identifiers are the fundamental building blocks of a program.
Reason (R) : Identifiers always start with digit or underscore.
str=list("Python Program@2021')
for Y is range(len(str)-1):
if Y==7:
str[Y]=str*2
elif(str[Y].isupper():
str[Y]=str*3
elif(str[Y].isdigit()):
str[Y]='D'
print(str)
3. Following code is having some errors. Rewrite the code after correcting and
underlining each correction:
x == 20
def printme():
y = x + 10
sum = 0
for i in range(x,y)
if i%3=0:
sum=sum+i+1
Elseif:
sum += 2
return(sum)
4. The code provided below is intended to swap the first and last elements of a given
tuple. However, there are syntax and logical errors in the code. Rewrite it after
removing all errors. Underline all the corrections made.
def swap_first_last(tup)
if len(tup) < 2:
return tup
new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
return new_tup
result = swap_first_last((1, 2, 3, 4))
print("Swapped tuple: " result)
def Linear_Search(L)
item=int(input("Enter the value that you want to search: ")
for i in range(len(L)):
if L[i]==item:
print("Element found at index: " i)
break
else:
print("Element not found")
Linear_Search([25,78,45,36,21,10])
6. What possible output(s) are expected to be displayed on screen at the time of
execution of the program from the following code? Also specify the minimum values
that can be assigned to each of the variables BEGIN and LAST.
import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint (1, 3)
LAST = random.randint(2, 4)
for I in range (BEGIN, LAST+1):
print (VALUES[I], end = "-")
7. Identify the correct output(s) of the following code. Also write the minimum and the
maximum possible values of the variable b.
import random
a="Wisdom"
b=random.randint(1,6)
for i in range(0, b, 2):
print(a[i],end='#')
a) 6 # 7 # 12 # 13 # b) 5 # 11 # 8 # 11 #
c) 4 # 7 # 12 # 14 # d) 9 # 15 # 8 # 6 #
a) apple*banana* b) banana*banana*
c) orange*apple* d) apple*apple*
10. How is a mutable object different from an immutable object in Python? Identify one
mutable object and one immutable object from the following: (1,2), [1,2], {1:1,2:2},
‘123’
11. Define Operator Associativity. Write the following operators in descending order of
their operator precedence:
or, **, and, +, *, ==, ()
ii.
A. Write a statement to insert all the elements of L2 at the end of L1.
OR
B. Write a statement to reverse the elements of list L2.
13. If M1=[10,20,30,……] and M2=[3,6,9,12, …….], then
Write the Python statements for each of the following tasks using BUILT-IN
functions/methods only:
i.
A. To delete an element 20 from the list M1.
OR
B. Write a statement to add an element in M2 between 9 and 12.
ii.
A. Write a statement to sort the elements of list M1 in descending order.
OR
B. Write the statement to delete the last element of list M2.
14. Consider a string message= “Programming develops critical thinking and problem-
solving skills”
Write the Python statements for each of the following tasks using BUILT-IN
functions/methods only:
i.
A. Write a statement to convert the complete string in capital letters.
OR
B. To check whether a string named as message starts with “Th” or not.
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 17
ii.
A. Write a statement to convert the string into a list.
OR
B. Replace the word ‘thinking’ with the word ‘analysis’ in given string.
15. i.
A. What constraint should be applied on a table column so that duplicate values
are not allowed in that column, but NULL is allowed?
OR
B. What constraint should be applied on a table column so that NULL is not
allowed in that column, but duplicate values are allowed.
ii.
A. Write an SQL command to remove the Primary Key constraint from a table,
named MOBILE. M_ID is the primary key of the table.
OR
B. Write an SQL command to make the column M_ID the Primary Key of an
already existing table, named MOBILE.
16. i.
A. Define degree and cardinality of a relation in RDBMS.
OR
B. Define the term keys in DBMS.
ii.
A. Ravish created a database namely BUSINESS. Now he wants to create a
table in it. For this he needs to open the database that he has created. Write
SQL command to open the database that is created by Ravish.
OR
B. Write any two advantages of DBMS.
17. i.
A. Differentiate between count() and count(*) functions in SQL with
appropriate example.
OR
B. Categorize the following commands as DDL and DML: INSERT, UPDATE,
ALTER, DROP
ii.
29. Define constraint. Write syntax to add primary key constraint in existing table.
37. Explain the use of ‘Foreign Key’ in a Relational Database Management System. Give
example to support your answer.
03 MARKS QUESTIONS
1. Write a function LenFourWord(L), where L is the list of elements (list of words)
passed as argument to the function. The function returns another list named
‘indexList’ that stores the indices of all four lettered word of L.
For example:
If L contains [“DINESH”, “RAMESH”, “AMAN”, “SURESH”, “RAVI”]
The output should be:
The indexList will have [2, 4]
2. Write a function Replace_Word(M), where M is the list of elements (list of fruits)
passed as an argument to the function. The function should replace those fruits which
start with any vowel, with the length of the word and display the updated list.
For example:
If list M contains ["mango", "apple", "Avocado", "banana", "orange"]
The output should be:
['mango', 5, 7, 'banana', 6]
3. Write a function Assess_Risk(weight, height, age) to calculate BMI and assess the
risk level of an individual based on their Body Mass Index (BMI) and age. Where
weight in kilograms, height in meters and age in years.
𝑤𝑒𝑖𝑔ℎ𝑡
Calculate BMI as per given formula : ℎ𝑒𝑖𝑔ℎ𝑡 2
The function should calculate the BMI and display the corresponding risk level of an
individual according to the following criteria:
4. Write a user defined function in Python named Puzzle (W,N) which takes the
argument W as an English word and N as an integer and returns the string where
every Nth alphabet of the word W is replaced with an underscore ("_").
9. Write a function Count_UpperWord() that counts number of words which start with
uppercase letter in a text file “Novels.txt”.
18. Write a function CountDigits( ) in python which reads the content of a text file
“MyData.TXT” and counts number of digits present in the text file.
Example:
If the contents in “MyData.TXT” are as follows:
In 2023 we 22 students will appear in exam for 5 subjects
def Diff(N1,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:
tuple1 = (11, 22, 33, 44, 55 ,66)
list1 =list(tuple1)
new_list = []
for i in list1:
if i%2==0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
def ChangeString(s):
m="" #empty string
for i in range(0,len(s)):
if(s[i].isupper()):
m=m+s[i].lower()
elif s[i].islower():
m=s[i].upper()+m
else:
if i%2==0:
m=m+s[i-1]
else:
m="%"+m
print(m)
ChangeString('Try2Solve@')
OR
Predict the output of the Python code given below:
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 24
p=4
def CheckData(y):
global p
print(p+2)
r=y
p=r+8
print(p)
CheckData(12)
print(p)
c=FindOutput(q=5,r=7,p=4)
a,b=10,12
c=FindOutput(b,a,c)
print(a,"@",b,"@",c)
OR
What will be the output of the following code:
def Value2New(M, N=10):
M=M+N
N = N*2
if N%10==0:
N=N/5
return(M,N)
P,Q = Value2New(100,20)
print(P,’#’,Q)
P,Q = Value2New(50)
print(P,’#’,Q)
OR
Predict the output of the following code:
def convert(p,q=10):
p=p/q
q=p%q
return p
a=150
b=5
a=convert(a,b)
print(a,b,sep="#")
b=convert(b)
print(a,b,sep="$")
26. Predict the output of the code given below :
def makenew(mystr):
newstr= “” #empty string
count=0
for i in mystr:
if count%2!=0:
newstr=newstr+str(count)
else:
if i.islower():
newstr=newstr+i.upper()
else:
newstr=newstr+i
count+=1
print(newstr)
makenew ( "Car@6")
27. A.
Consider a dictionary named Books which contains name of books as key and price
as value.
Write the following user defined functions in python and perform the specified
operations on a stack named Book_Name.
i. Push_BName() : It checks price of the book from the dictionary Books and
pushes name of such books which have price more than 350 rupees, into the
stack, Book_Name.
ii. Pop_BName(): It deletes the name of books from stack Book_Name and
displays them. The function should also display “Stack is Empty” message when
there is no more book left in the stack.
i. Traverse the content of the list and push the even numbers into a stack.
28. You have a stack named MovieStack that contains records of movies. Each movie
record is represented as a list containing movie_title, director_name, and
release_year.
Write the following user-defined functions in Python to perform the specified
operations on the stack MovieStack:
i. add_movie(MovieStack, new_movie): This function takes the stack MovieStack
and a new movie record new_movie as arguments and pushes the new movie
record onto the stack and display the stack.
ii. remove_movie(MovieStack): This function removes the topmost movie record
from the stack and returns it. If the stack is already empty, the function should
display "Underflow".
iii. view_top(MovieStack): This function displays the topmost element of the stack
without deleting it. If the stack is empty, the function should display 'None'.
OR
Stationery_Item is a dictionary containing the details of stationary items.
Write a user defined function PUSH_DATA(Stationery_Item), to push the name of
those items into the stack named as PriceStack which have price more than 75 and
display stack. Also display the number of elements pushed into the stack.
For example: If the dictionary contains the following data:
Stationery_Item={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
The stack should contain
['Pen', 'Notebook']
The output should be:
Number of elements in stack: 2
30. Consider a list named Space which contains the terms related to space.
Write the following user defined functions in python and perform the specified
operations on a stack named MyStack.
i. Push_Term(): It checks every term from the list Space and pushes all such
terms which have 5 or more characters into the stack, MyStack.
ii. Pop_Term(): It pops the terms from stack, MyStack and displays them. The
function should also display “Stack is Empty” when there are no more
elements left in the stack.
OR
B.
Write the definition of a user-defined function `push_even(N)` which accepts a list of
integers in a parameter `N` and pushes all those integers which are even from the
list `N` into a Stack named `EvenNumbers`.
i. Write function pop_even() to pop the topmost number from the stack and
returns it. If the stack is already empty, the function should display "Empty".
ii. Write function Disp_even() to display all element of the stack without deleting
them. If the stack is empty, the function should display 'None'.
For example:
If the integers input into the list `VALUES` are: [10, 5, 8, 3, 12] Then
the stack `EvenNumbers` should store: [10, 8, 12]
32. A.
Ravina has created a list of integer elements. Create user defined functions to
perform the following operations:
i. Create a function Push_Number(L) which will insert the number into the stack
which is divisible by 5.
ii. Define a function Pop_Number( ) from the stack and display the value of TOP
after deletion of the element.
ii. Delete the element from the stack and display the stack after deletion of the
element.
04 MARKS QUESTIONS
1. Consider the table ORDERS as given below:
O_Id C_Name Product Quantity Amount
1001 Jitendra Laptop NULL 12000
1002 Mustafa Smartphone 2 10000
1003 Dhwani Headphone 1 1500
1008 Sonali Laptop 3 40000
1025 Jayra Headphone NULL 22000
1231 Varun Laptop 5 90000
TABLE: ELECTRONICS
Item_ID IName Manufacturing_Date Make Qty Price
Table: BOOKS
TABLE: PLAYER
Pcode Pname Gender DOB State Game Age
401 Ravita F 2000-10-09 Punjab Cricket 22
402 Gauravi F 2001-01-22 Bihar Football 21
403 Rakesh M 2000-11-29 Haryana Hockey 22
404 Divya F 2002-05-12 Rajasthan Hockey 20
405 Hemali F 2000-09-21 Gujarat Cricket 22
406 Ashok M 2000-12-12 Rajasthan Hockey 21
Table: Garment
GCode GName Rate Qty CCode
G101 Saree 1250 100 C03
G102 Lehanga 2000 100 C02
G103 Plazzo 750 105 C02
G104 Suit 2000 250 C01
G105 Patiala 1850 105 C01
Table: Cloth
CCode CName
C01 Polyester
C02 Cotton
C03 Silk
C04 Cotton-Polyester
TABLE: EMPLOYEE
EMPNO NAME DATE_OF_ JOINING SALARY CITY
5001 SUMIT SINGH 2012-05-24 55000 JAIPUR
5002 ASHOK SHARMA 2015-10-25 65000 DELHI
5003 VIJAY SINGH 2009-09-09 85000 JAIPUR
5004 RAKESH VERMA 2020-12-21 60000 AGRA
5006 RAMESH KUMAR 2011-01-22 72000 DELHI
TABLE: GAME
Gcode Gname no_of_players Gtype
01 Tennis 1 Outdoor
02 Cricket 11 Outdoor
03 Badminton 1 Indoor
Ms. Ragini wants to write the following user defined functions in python:
i. Save_Data( ) : To accept details of equipment/parts from the user and add
it to a csv file “parts.csv”.
ii. Delete_Data( ) : To accept a part ID from user and removes the record of
a part from the file “parts.csv” with given part ID. If part ID not found then
it should display a relevant message “Part ID is not found”. Before removing
the record of a part, it should display name of part.
12. Mr. Ankit is a python programmer working in a software company. He has to develop
a simple inventory management system of all employees working in an educational
institute. He has created a csv file named record.csv, to store the details of
employees. The structure of record.csv is:
[employee_id, emp_name, salary]
Mr. Ankit wants to write a Program in Python that defines and calls the following
user defined functions:
i. ADD() – To accept and add data of 6 employees to a CSV file ‘record.csv’.
ii. COUNTR() – To count the number of records present in the CSV file named
‘record.csv’.
Ms. Mamta wants to write a Program in Python that defines and calls the following
user defined functions:
i. add() – To accept and add data of a furniture to a CSV file ‘furdata.csv’.
ii. search()- To display the records of the furniture which has price more than
10000.
14. Write a program in Python that defines and calls the following functions:
i. Insert() – To accept details of clock from the user and stores it in a csv file
‘watch.csv’. Each record of clock contains following fields – ClockID,
ClockName, YearofManf, Price. Function takes details of all clocks and stores
them in file in one go.
ii. Delete() – To accept a ClockID and removes the record with given ClockID
from the file ‘watch.csv’. If ClockID not found then it should show a relevant
message. Before removing the record it should print the record getting
removed.
15. Write a program in Python that defines and calls the following functions:
ii. search() – To accept two prices and displays details of those equipments
which has price between these two values.
16. Aman has been entrusted with the management of Law University Database. He
needs to access some information from FACULTY and COURSES tables for a survey
analysis. Help him extract the following information by writing the desired SQL
queries as mentioned below.
Table: FACULTY
F_ID FName LName Hire_Date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
i. To display complete details (from both the tables) of those Faculties whose
salary is less than 12000.
ii. To display the details of courses whose fees is in the range of 20000 to 50000
(both values included).
iii. To increase the fees of all courses by 500 which have "Computer" in their
Course names.
iv. (A) To display names (FName and LName) of faculty taking System Design.
OR
(B) To display the Cartesian Product of these two tables.
17. Ms. Nishi has been entrusted with the bank Database. She needs to access some
information from LOAN and BORROWER tables for a survey analysis. Help her to extract
the following information by writing the desired SQL queries as mentioned below.
Table: LOAN
loan_number branch_name Amount
L123 Nagpur 45000
L456 Pune 60000
L347 Delhi 80000
L987 Delhi 25000
L901 Pune 45000
Table : BORROWER
customer_name loan_number
Ajit Das L456
Rohan Yadav L901
Suman Verma L123
Ayesha Tiwari L987
Saurav L347
i. To display customer name and branch name of those customers who have
taken loan from Delhi branch.
ii. To display loan number, customer name and amount of those customers who
have taken loan more than 40000.
iii. To display branch name and average amount of that branch which has given
average loan amount more than 50000.
iv.
A. To display customer name and amount in descending order of amount.
OR
Field Type
itemNo int(11)
itemName varchar(15)
price float
qty int(11)
21. 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
● 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.
22. The code given below inserts the following record in the table Employee:
Emp_id – integer
Ename – string
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 41
Date_of_Birth – date
Salary – float
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is computer
The table exists in a MYSQL database named Employee.
The details (Emp_id, Ename, Date_of_Birth, Salary) are to be accepted from the
user.
Write the following missing statements to complete the code:
i. Statement 1 – to form the cursor object
ii. Statement 2 – to execute the command that inserts the record in the table
Employee.
iii. Statement 3- to add the record permanently in the database
23. The code given below extract and display the following record from the table
Employee.
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is computer
The table exists in a MYSQL database named Employee.
The details (Emp_id, Ename, Date_of_Birth, Salary) are present in table.
Write the following missing statements to complete the code:
i. Statement 1 – to form the cursor object
ii. Statement 2 – to retrieve all records from result set object as per query.
iii. Statement 3 - sequence object in the loop to display the records
05 MARKS QUESTIONS
1. Surya is a manager working in a recruitment agency. He needs to manage the
records of various candidates. For this, he wants the following information of each
candidate to be stored: -
- Candidate_ID – integer
- Candidate_Name – string
- Designation – string
- Experience – float
You, as a programmer of the company, have been assigned to do this job for Surya.
i. Write a function to input the data of a candidate and append it in a binary file.
ii. Write a function to update the data of candidates whose experience is more
than 10 years and change their designation to "Senior Manager".
iii. Write a function to read the data from the binary file and display the data of
all those candidates who are not "Senior Manager".
2. Mr. Mohit is working on a school project to manage student records using Python.
The student data is stored in a binary file named STUDENT.DAT. The binary file
STUDENT.DAT contains each record in given format:
{“Admn_No”:admn, “SName”:name, “Marks”:marks}
Where
● Admn_No: Admission Number (integer)
● SName: Student Name (string)
● Marks: Marks (integer)
You as a programmer, help him to write following python functions:
i. ADD_Data() : To write 7 records in binary file STUDENT.DAT by taking the
values for each record from user.
ii. Display_Data() : Read all records from binary file and display them.
iii. Modify_Marks() that updates the marks of a student in the file
STUDENT.DAT based on the admission number provided by the user. If the
admission number does not exist in the file, display an appropriate message.
3. “XYZ Travels Pvt. Ltd.” is a tour and travel management company that maintains the
data of various buses. To store data of buses the company uses a binary file named
“BUS.DAT”. The file contains records in the given format:
You as a programmer, help them to write following user defined python functions:
i. Write_Record() : Write n numbers of records in binary file by taking values
for each record from the user.
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 43
ii. Show_Data() : Read all records from binary file and display them.
iii. Write a user defined function Search_Bus() in python to search and display
details of those buses, which have "Ajmer" as destination from the binary file
"BUS.DAT". If no bus has the destination as “Ajmer” in the file, display an
appropriate message.
9. “Topper Books Inc.” is a retail company that manages a large inventory of books
through a digital inventory management system. The company maintains
detailed records of its book inventory in binary file named as “BOOK.DAT” for
efficient storage and retrieval. Each record in binary file “BOOK.DAT” has the
following structure:
[BNo, BName, Qty, Price]
The company's marketing team has decided to run a promotion focusing on high-
value books. To facilitate this promotion, the team needs to extract records of all
books priced above Rs. 400 from the existing binary file BOOK.DAT and save
them into a new file named NEWBOOK.DAT.
You as a programmer, help them to write a user defined function Copy_Book( ),
that copies records of all books whose price is more than 400 from “BOOK.DAT”
to “NEWBOOK.DAT”.
10. A binary file “PEOPLE.DAT” has the following structure:
[Adhaar_number, Name, Gender, Age]
ii. Write a function Show_Record( ) in Python that would read contents of the file
“PEOPLE.DAT” and display the details of those people whose age is above 45.
11. Event Horizon Enterprises is an event planning organization. It is planning to set up
its India campus in Mumbai with its head office in Delhi. The Mumbai campus will
have four blocks/buildings - ADMIN, FOOD, MEDIA, DECORATORS. You, as a network
expert, need to suggest the best network-related solutions for them to resolve the
issues/problems mentioned in points (I) to (V), keeping in mind the distances
between various blocks/buildings and other given parameters.
Number of Computers:
Block Number of Computers
App Development 75
Web Designing 50
Movie Editing 80
Jaipur Campus
Marketing Mumbai
HR
Head Office
Technical
HR BLOCK 10
MARKETING BLOCK 45
(ii) Which device will you suggest to be procured by the company for connecting all
the computers within each of their offices out of the following devices?
● Switch/Hub
● Modem
● Bridge
(iii) Suggest network type (out of LAN, MAN, WAN) for connecting each of the
following set of their offices:
⮚ HR & Marketing Block
⮚ Head Office and Jaipur Office
(iv) Which of the following communication medium, you will suggest to be procured
by the company for connecting their local offices in Jaipur for very effective and fast
communication?
● Telephone cable
● Optical fiber
● Ethernet cable
(v) Suggest and draw the cable layout (Block to Block) to connect various offices
within the Jaipur Campus.
i. Suggest the most appropriate location of the server inside the Nagpur Campus
to get the best connectivity for maximum number of computers. Justify your
answer.
ii. Suggest and draw the cable layout to efficiently connect various buildings
within the Nagpur campus for connecting the computers.
iii. Which of the following will you suggest to establish the online face-to-face
communication between the people in the ADMIN office of Nagpur Campus
and Mumbai Head office?
a) Cable TV
b) E-mail
c) Video Conferencing
d) Text Chat
15. Deccan Tech Services is planning to set up its India campus at Delhi with its Head
Office at Mumbai. The Delhi campus has 4-main blocks-BUSINESS, TECHNOLOGY,
LAW and HR. You as a network expert have to suggest the best network related
solutions for their problems raised in (i) to (v).
MUMBAI
Head Office
TECHNOLOGY
BUSINESS
HR
i. Suggest the most appropriate location of the server inside the DELHI campus
(out of the 4 blocks), to get the best connectivity for maximum number of
computers. Justify your answer.
ii. Suggest and draw the cable layout to efficiently connect various blocks within
the DELHI campus for connecting the computers.
iii. Which hardware device will you suggest to be procured by the company to be
installed to protect and control the internet uses within the campus?
iv. Suggest network type (out of LAN, MAN, WAN) for connecting each of the
following set of their offices:
⮚ Law & Technology Department
16. “India Computer Ltd.” is a software services provider company. It is planning to start
its offices in four major cities in India to provide regional IT infrastructure. The
company has planned to setup their head office in New Delhi at three locations and
have named their New Delhi offices as “Sales Office”, “Head Office” and “Tech
Office”. The company’s regional offices are located in “Bengaluru”, “Kolkata” and
“Ahmedabad”. A rough layout of the same is as follows:
You as a networking expert need to suggest solutions to the questions in part (i) to
(v), keeping in mind the distances and other given parameters:
ii. Which block in New Delhi should host the server? Justify your answer.
iii. Which wired communication media, you will suggest to be used by the
company to connect its local offices in New Delhi for very effective and fast
communication?
iv. Suggest and draw a cable/wiring layout for connecting the local offices located
in New Delhi for connecting the digital devices.
v. In New Delhi Campus, in between which offices repeater should be installed?
Justify the answer.
17. 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:
By: Vikash K.Yadav, PGT-CS, PM SHRI KV O.F. Chanda Page | 53
print("No employee with such id is not found")
fin.close()
fout.close()
18. Alok Kumar of class 12 is writing a program to create a CSV file “project.csv” which
will contain student name and project name for some entries. He has written the
following code. As a programmer, help him to successfully execute the given task.
def write(ino,qty):
F = open(____________) #Mark 2
L= _______________ #Mark 3
L.append([ino,qty])
F.close()
F=open('inventory.dat','wb')
pickle.dump(L,F)
F.close()
def Receive(ino,qty):
F=open(“inventory.dat”,”rb”)
L=pickle.load(F)
F.close()
for i in range(len(L)):
if L[i][0] == ino:
L[i][1] += qty
F=open("inventory.dat",'wb')
pickle.dump(L,F)
________________ #Mark 4
def Sent(ino,qty):
with open(“inventory.dat”, “rb”) as F:
L=pickle.load(F)
for i in range(len(L)):
if L[i][0] == ino:
L[i][1] -= qty
with open("inventory.dat",'wb') as F:
pickle.dump(L,F)
i. Write statement to open the file at Mark 2 to read records from the file.
ii. Write statement at Mark 3 to read the content of binary file in list L.
iii. Write statement at Mark 4 to close the file. Why there is no need to close the
file in function Sent()?
BY:
VIKASH KUMAR YADAV
PGT-COMPUTER SCIENCE
PM SHRI K.V. O.F. CHANDA