You are on page 1of 12

ASSIGNMENT – FILES

FILE HANDLING – Binary Files


1 Which of the following is a function/method of the pickle module ? 1 2022
(a) reader( ) (b) writer( ) (c) load( ) Term 1
(d) read( )
2 Which of the following statement is incorrect in the context of pickled binary files ? 1 2022
(a) csv module is used for reading and writing objects in binary files. Term 1
(b) pickle module is used for reading and writing objects in binary files.
(c) load() of the pickle module is used to read objects
(d) dump() of the pickle module is used to write objects
3 Which of the following statements is incorrect in the context of binary files? 1 SQP
a. Information is stored in the same format in which the information is held in memory. 2022
b. No end of line (EOL) character translation takes place. Term 1
c. Every line ends with a new line character.
d. pickle module is used for reading and writing.
4 Which of the following statements is true? 1 SQP
a. pickling creates an object from a sequence of bytes. 2022
b. pickling is used for object serialization. Term 1
c. pickling is used for object deserialization.
d. pickling is used to manage all types of files in Python.
Which of the following statements opens a binary file "record.bin" in write mode and writes an 1 SQP
object lst1 = [1,2,3,4] on the binary file? 2022
a. with open('record.bin','wb') as myfile: Term 1
pickle.dump(lst1,myfile)
b. with open('record.bin','wb') as myfile:
pickle.dump(myfile,lst1)
c. with open('record.bin','wb+') as myfile:
pickle.dump(myfile,lst1)
d. with open('record.bin','ab') as myfile:
pickle.dump(myfile,lst1)
Raghav is trying to write an object obj1 = (1,2,3,4,5) on a binary file "test.bin". Consider the 1 SQP
following code written by him. 2022
import pickle Term 1
obj1 = (1,2,3,4,5)
myfile = open("test.bin",'wb')
pickle._______ #Statement 1
myfile.close()
Identify the missing code in Statement 1.
a. dump(myfile,obj1) b. dump(obj1,
myfile)
c. write(obj1,myfile) d.
load(myfile,obj1)
The content of a binary file "employee.dat" is shown below where the Header is not a part of SQP
file content (i.e only Row1 to Row5 are present in the file) 2022
def display(eno): Term 1
f=open("employee.dat","rb")
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
_______________________#Line1
totSum=totSum+R[2]
except:
f.close()
print(totSum)
When the above-mentioned function, display (103) is executed, the output displayed is 190000.
Which of the following statement should be used in the blank space of the line marked as
Line1 to obtain the above output?
a. jump b. break c. continue
d. return
The content of a binary file "employee.dat" is shown below where the Header is not a part 1 SQP
of file content (i.e only Row1 to Row5 are present in the file) 2022
Term 1

def display(eno):
f=open("employee.dat","rb")
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
_________ #Line1
totSum=totSum+R[2]
except:
f.close()
print(totSum)
When the above-mentioned function, display (103) is executed, the output displayed is
190000. Which of the following statement should be used in the blank space of the line
marked as Line1 to obtain the above output?
a. jump b. break c. continue
d. return
A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price]. 5 SQP
2021
i. Write a user defined function CreateFile() to input data for a record and add to Book.dat .
ii. Write a function CountRec(Author) in Python which accepts the Author name as parameter
and count and return number of books by the given Author are stored in the binary file
“Book.dat”
A binary file “STUDENT.DAT” has structure (admission_number, Name, Percentage). Write a SQP
function countrec() in Python that would read contents of the file “STUDENT.DAT” and 2021
display the details of those students whose percentage is above 75. Also display number of
students scoring above 75%
FILE HANDLING – CSV Files
Which of the following is the correct expansion of csv ? 1 2022
(a) Comma Separated Values. (b) Centrally Secured Values. (c) Computerised term 1
Secured Values. (d) Comma Secured Values.
Which of the following is the default character for the new line parameter for a csv file object 2022
opened in write mode in Python IDLE term 1
(a) \n (b) \t (c) , (d) ;
This section consists of 6 Questions (50 - 55). Attempt any 5 questions. Nisha, an intern in 2022
ABC Pvt. Ltd., is developing a project using the csv term 1
module in Python. She has partially developed the code as follows leaving out statements about
which she is not very confident. The code also contains errors in certain statements. Help her in
completing the code to read the desired CSV File named "Employee.csv"
#CSV File Content
ENO,NAME,DEPARTMENT
E1,ROSHAN SHARMA,ACCOUNTS
E2,AASMA KHALID,PRODUCTION
E3,AMRIK GILL,MARKETING
E4,SARAH WILLIAMS,HUMAN RESOURCE

#incomplete Code with Errors


import CSV
#Statement-l
with open (____, _____, newline='') as File:
#Statement-2
ER = csv.______ #Statement-3
for R in range(ER) : #Statement-4
if _______ == "ACCOUNTS" : #Statement-5
print (____, _____) #Statement-6
Nisha gets an Error for the module name used in Statement-1. What should she write in place 2022
of CSV to import the correct module ? term 1
(a) file (b) csv (c) Csv (d) pickle

Identify the missing code for blank spaces in the line marked as Statement-2 to open the 2022
mentioned file. term 1
(a) "Employee.csv","r" (b) "Employee.csv","w" (c)
"Employee.csv","rb" (d) "Employee.csv","wb"
Choose the function name (with parameter) that should be used in the line marked as 2022
Statement-3. term 1
(a) reader(File) (b) readrows(File) (c)
writer(File) (d) writerows(File)
Nisha gets an Error in Statement-4. What should she write to correct the statement ? 2022
(a) for R in ER: (b) while R in range(ER): (c) for R = ER: term 1
(d) while R == ER:
Identify the suitable code for blank space in Statement-5 to match every row's 3rd property 2022
with "ACCOUNTS" . term 1
(a) ER[3] (b) R[2] (c)
ER[2] (d) R[3]
Identify the suitable code for blank space in Statement-6 to display every Employee's Name 2022
and corresponding Department ? term 1
(a) ER[l], R[2] (b) R[l], ER[2] (c) R[l], R[2]
(d) ER[1], ER[2]
Which of the following python module is imported to store and retrieve objects using the 2022
process of serialization and deserialization ? term 1
(a) csv (b) binary (c) math
(d) pickle
Which of the following characters act as default delimiter in a CSV file? SQP
a. (colon) : b. (hyphen) - c. (comma) 2022
, d. (vertical line) | Term 1
Given below is one way of opening a file Student.csv file in write mode. SQP
myfile = open("Student.csv","w",newline=''). 2022
What is the importance of newline=''? Term 1
a. A new line gets added to the file. b. Empty
string gets appended to the first line.
c. Empty string gets appended to all lines. d. EOL
character translation is suppressed
Consider the following python program. SQP
import csv 2022
fh = open("Student.csv","r") Term 1
stureader = csv.reader(fh)
for rec in stureader:
print(rec)
What will be the data type of rec?
a. string b. list c. tuple
d. dictionary
Which of the following is not a function/method of the csv module in Python? SQP
a. read() b. reader() c. writer() 2022
d. writerow() Term 1
Rohit, a student of class 12, is learning csv module in Python. During the examination, he has SQP
been given a stub Python program (shown below) to create a CSV File "Student.csv" (content 2022
shown below). Help him in completing the code which creates the desired CSV File. Term 1
CSV File
1,AKSHAY,XII,A
2,ABHISHEK,XII,A
3,ARVIND,XII,A
4,RAVI,XII,A
5,ASHISH,XII,A
Incomplete Code
import _____ #Statement-1
fh = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
data = [ ]
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [ _____ ] #Statement-4
data.append(_____) #Statement-5
stuwriter. _____ (data) #Statement-6
fh.close()
Identify the suitable code for blank space in the line marked as Statement-1. SQP
a) csv file b) CSV c) 2022
csv d) csv module Term 1
Identify the missing code for blank space in the line marked as Statement-2. SQP
a) "Student.csv","wb" b) "Student.csv","w" c) 2022
"Student.csv","r" d) "Student.csv","rb" Term 1
Choose the function name (with argument) that should be used in the line marked SQP
as Statement-3. 2022
a) reader(fh) b) reader(MyFile) c) writer(fh) Term 1
d) writer(MyFile)
Identify the suitable code for the blank space in Statement-4. SQP
a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION' b) ROLL_NO, 2022
NAME, CLASS, SECTION Term 1
c) 'roll_no', 'name', 'Class', 'section' d) roll_no,
name, Class, section
Identify the suitable code for blank space in Statement-5. SQP
a) data b) record c) 2022
rec d) insert Term 1
Choose the function name that should be used in the blank space of the line SQP
marked as Statement-6 to create the desired CSV File? 2022
a) dump() b) load() c) Term 1
writerows() d) writerow()
Write the full form of CSV. SQP
2021

Ranjan Kumar of class 12 is writing a program to create a CSV file “user.csv” which SQP
will contain user name and password for some entries. He has written the following 2021
code. As a programmer, help him to successfully execute the given task.
import _____________ # Line 1
def addCsvFile(UserName,PassWord): # to write / add data into the CSV file
f=open(' user.csv','________') # Line 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([UserName,PassWord])
f.close()
#csv file reading code
def readCsvFile(): # to read data from CSV file
with open(' user.csv','r') as newFile:
newFileReader = csv._________(newFile) # Line 3
for row in newFileReader:
print (row[0],row[1])
newFile.______________ # Line 4
addCsvFile(“Arjun”,”123@456”)
addCsvFile(“Arunima”,”aru@nima”)
addCsvFile(“Frieda”,”myname@FRD”)
readCsvFile() #Line 5
(a) Name the module he should import in Line 1. 1
(b) In which mode, Ranjan should open the file to add data into the file 1
(c) Fill in the blank in Line 3 to read the data from a csv file. 1
(d) Fill in the blank in Line 4 to close the file.
1
(e) Write the output he will obtain while executing Line 5. 1

ASSIGNMENT – STACK

2022 SQP : Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a
program, with separate user defined functions to perform
the following operations:
▪ Push the keys (name of the student) of the dictionary into a stack, where the corresponding value
(marks) is greater than 75.
▪ Pop and display the content of the stack.
For example:
If the sample content of the dictionary is as follows:
R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be:
TOM ANU BOB OM

2022 SQP : Alam has a list containing 10 integers. You need to help him create a program with separate user defined
functions to perform the following operations based
on this list.
▪ Traverse the content of the list and push the even numbers into a stack.
▪ Pop and display the content of the stack.
For Example:
If the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be:
38 22 98 56 34 12

SQP 2021 : Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push all numbers
divisible by 5 into a stack implemented by using a list.
Display the stack if it has at least one element, otherwise display appropriate error message.
SQP 2021 : Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers. The function
returns the value deleted from the stack.

SQP 2020 : Write a function in python, MakePush(Package) and MakePop(Package) to add a new Package and delete
a Package from a List of Package Description,
considering them to act as push and pop operations of the Stack data structure.

2020 Comptt: Write functions in Python for PushS(List) and for PopS(List) for performing Push and Pop operations with
a stack of List containing integers.

2020 Comptt: Write functions in Python for InsertQ(Names) and for RemoveQ(Names) for performing insertion and
removal operations with a Stack of List which contains
names of students.

2021 Comptt: Write the definition of a function POP_PUSH(LPop, LPush, N) in Python. The function should Pop out the
last N elements of the list LPop and Push them into
the list LPush. For example :
If the contents of the list LPop are [10, 15, 20, 30] And value of N passed is 2,
then the function should create the list LPush as [30, 20] And the list LPop should now contain [10, 15]
NOTE : If the value of N is more than the number of elements present in LPop, then display the message
"Pop not possible".

2021 Comptt: Write a function in Python POPSTACK(L) where L is a stack implemented by a list of numbers. The
function returns the value deleted from the stack.

2022 Comptt: Write separate user defined functions for the following :
(i) PUSH(N) - This function accepts a list of names, N as parameter. It then pushes only those names in the
stack named OnlyA which contain the letter 'A'.
(ii) POPA(OnlyA) - This function pops each name from the stack OnlyA and displays it. When the stack is
empty, the message "EMPTY" is displayed.
For example :
If the names in the list N are
['ANKITA', 'NITISH', 'ANWAR', 'DIMPLE', 'HARKIRAT']
Then the stack OnlyA should store
['ANKITA', 'ANWAR', 'HARKIRAT']
And the output should be displayed as
HARKIRAT ANWAR ANKITA EMPTY

2022 Comptt: Write the following user defined functions :


(i) pushEven(N) - This function accepts a list of integers named N as parameter. It then pushes only even
numbers into the stack named EVEN.
(ii) popEven(EVEN) - This function pops each integer from the stack EVEN and displays the popped value.
When the stack is empty, the message "Stack Empty"
is displayed.
For example:
If the list N contains :
[10,5,3,8,15,4]
Then the stack, EVEN should store
[10,8,4]
And the output should be
4 8 10 Stack Empty
2022 : “Stack is a linear data structure which follows a particular order in which the operations are performed.”
What is the order in which the operations are
performed in a Stack?
Name the List method/function available in Python which is used to remove the last element from a list
implemented stack.
Also write an example using Python statements for removing the last element of the list.
2022 : Write the definition of a user defined function PushNV(N) which accepts a list of strings in the parameter
N and pushes all strings which have no vowels present
in it, into a list named NoVowel.
Write a program in Python to input 5 Words and push them one by one into a list named All. The program
should then use the function PushNV() to create a
stack of words in the list NoVowel so that it stores only those words which do not have any vowel present
in it, from the list All. Thereafter, pop each word
from the list NoVowel and display the popped word. When the stack is empty, display the message
"EmptyStack".
For example:
If the Words accepted and pushed into the list All are
['DRY', 'LIKE', 'RHYTHM', 'WORK', 'GYM']
Then the stack NoVowel should store
['DRY', 'RHYTHM', 'GYM']
And the output should be displayed as
GYM RHYTHM DRY EmptyStack

2022 : Write the definition of a user defined function Push3_5(N) which accepts a list of integers in a parameter
N and pushes all those integers which are divisible by
3 or divisible by 5 from the list N into a list named Only3_5.
Write a program in Python to input 5 integers into a list named NUM. The program should then use the
function Push3_5() to create the stack of the list
Only3_5. Thereafter pop each integer from the list Only3_5 and display the popped value. When the list
is empty, display the message "StackEmpty".
For example:
If the integers input into the list NUM are :
[10,6,14,18,30]
Then the stack Only3_5 should store
[10,6,18,30]
And the output should be displayed as
30 18 6 10 StackEmpty
ASSIGNMENT – NETWORKING

2022 : 1. Expand the following : VoiP, PPP


2. Riya wants to transfer pictures from her mobile phone to her laptop. She uses Bluetooth technology
to connect two devices. Which type of network
(PAN/LAN/MAN/WAN) will be formed in this case?
3. Differentiate between Bus Topology and Tree Topology. Also, write one advantage of each of them.

4. Differentiate between HTML and XML.


5. What is a web browser? Write the names of any two commonly used web browsers.
6. Galaxy Provider Ltd. is planning to connect its office in Texas, USA with its branch at Mumbai. The
Mumbai branch has 3 Offices in three blocks located
at some distance from each other for different operations - ADMIN, SALES and ACCOUNTS.
As a network consultant, you have to suggest the best network related solutions for the
issues/problems raised in (a) to (d), keeping in mind the distances between various locations and
other given parameters.
Layout of the Offices in the Mumbai branch:

Shortest distances between various locations :


ADMIN Block to SALES Block 300m
SALES Block to ACCOUNTS Block 175m
ADMIN Block to ACCOUNTS Block 350m
MUMBAI Branch to TEXAS Head Office 14000 km
Number of Computers installed at various locations are as follows :
ADMIN Block 255
ACCOUNTS Block 75
SALES Block 30
TEXAS Head Office 90
(a) It is observed that there is a huge data loss during the process of data transfer from one
block to another. Suggest the most appropriate networking device out of the following, which
needs to be placed along the path of the wire connecting one block office with another to
refresh the signal and forward it ahead. (i) MODEM (iii) REPEATER (ii)
ETHERNET CARD (iv) HUB
(b) Which hardware networking device out of the following, will you suggest to connect all the
computers within each block?
(i) SWITCH (iii) REPEATER (ii) MODEM (iv) ROUTER
(c) Which service/protocol out of the following will be most helpful to conduct live interactions
of employees from Mumbai Branch and their counterparts in Texas ? (i) FTP
(iii) SMTP (ii) PPP (iv) VolP
(d) Draw the cable layout (block to block) to efficiently connect the three offices of the Mumbai
branch.

2022 Comptt: 1. Expand FTP.


2. Out of the following, which has the largest network coverage area ? LAN, MAN, PAN, WAN
3. Mention any two characteristics of BUS Topology.
4. Differentiate between the terms Domain Name and URL in the context of World Wide Web.
5. Write the names of two wired and two wireless data transmission mediums.
6. The government has planned to develop digital awareness in the rural areas of the nation.
According to the plan, an initiative is taken to set up Digital Training Centers in villages across the country with its
Head Office in the nearest cities. The committee has hired a networking consultancy to create a model of the
network in which each City Head Office is connected to the Training Centers situated in 3 nearby villages. As a
network expert in the consultancy, you have to suggest the best network-related solutions for the issues/problems
raised in (a) to (d), keeping in mind the distance between various locations and other given parameters. Layout of
the City Head Office and Village Training Centers :

Shortest distances between various Centers:


Village 1 Training Center to City Head Office 2 KM
Village 2 Training Center to City Head Office 1.5 KM
Village 3 Training Center to City Head Office 3 KM
Village 1 Training Center to Village 2 Training Center 3.5 KM
Village 1 Training Center to Village 3 Training Center 4.5 KM
Village 2 Training Center to Village 3 Training Center 3.5 KM
Number of Computers installed at various centers are as follows:
Village 1 Training Center 10
Village 2 Training Center 15
Village 3 Training Center 15
City Head Office 100

a) It is observed that there is a huge data loss during the process of data transfer from
one village to another. Suggest the most appropriate networking device out of the
following, which needs to be placed along the path of the wire connecting one
village with another to refresh the signal and forward it ahead. (i) MODEM
(ii) ETHERNET CARD (iii) REPEATER (iv) HUB
b) Draw the cable layout (location-to-location) to efficiently connect various Village
Training Centers and the City Head Office for the above shown layout.
c) Which hardware networking device, out of the following, will you suggest to
connect all the computers within the premises of every Village Training Center ?
(i) SWITCH (ii) MODEM (iii)
REPEATER (iv) ROUTER
d) Which protocol, out of the following, will be most helpful to conduct online
interactions of Experts from the City Head Office and people at the three Village
Training Centers ? (i) FTP (ii) PPP (iii) SMTP
(iv) VoIP

2021 Comptt : 1. Which of the following wireless transmission media is best suited for MAN ? (A)
Microwave (B) Radio Link (C) Infrared (D) Bluetooth
2. Which of the following statements correctly explains the term Firewall in context of
Computer Network Society ?
(A) A device that protects the computer network from catching fire.
(B) A device/software that controls incoming and outgoing network traffic.
(C) Using abusive language on a social network site.
(D) Stealing someone’s text and submitting it as his/her own work.
3. Which of the following protocols allows the use of HTML on the World Wide Web ? (A)
HTTP (B) PPP (C) FTP (D) POP
4. Differentiate between the terms Domain Name and URL in context of web services. Also
write one example of each to illustrate the difference.
5. Expand the following terms in context of Computer Networks : (a) PPP (b) VoIP (c) GSM (d)
WLL
6. A school library is connecting computers in its units in a LAN. The library has 3 units as
shown in the diagram below :

The three units are providing the following services :


1. Teachers Unit : For access of the Library Books by teachers
2. Students Unit : For access of the Library Books by Students
3. Circulation Unit : For issue and return of books for teachers and students
Centre to Centre distances between the 3 units are as follows :
Circulation Unit to Teachers Unit 20 metres
Circulation Unit to Students Unit 30 metres
Teachers Unit to Students Unit 10 metres

Number of computers in each of the units is as follows :


Circulation Unit 15
Teachers Unit 10
Students Unit 10
A. Suggest the most suitable place (i.e. the Unit name) to install the server of this
Library with a suitable reason.
B. Suggest an ideal layout for connecting these Units for a wired connectivity.
C. Which device will you suggest to be installed and where should it be placed to
provide Internet connectivity to all the Units ?
D. Suggest the type of the most efficient and economical wired medium for
connecting all the computers in the network.
E. The university is planning to connect the library with the school principal’s
computer which is in his office at a distance of 50 metres. Which type of
network out of LAN, MAN or WAN will be used for the network ? Justify your
answer.

Comptt 2020 New : 1. Fill in the blanks from questions 1(a) to 1(e).
(a) Computers connected by a network across different cities is an example of
___________ .
(b) ___________ is a network tool used to test the download and upload
broadband speed.
(c) A ____________ is a networking device that connects computers in a
network by using packet switching to receive, and forward data
to the destination.
(d) ___________ is a network tool used to determine the path packets taken
from one IP address to another.
(e) Write the full form of the following abbreviations : (i) POP (ii) VoIP (iii)
NFC (iv) FTP

IP 2021 : 1. Which of the following topologies needs least cable length ? (A) Star
(B) Tree (C) Bus
2. Which of the following is a web browser ? (A) Microsoft Windows (B)
Android (C) Microsoft Edge (D) Ubuntu
3. A __________ is a collection of interconnected _________ designed with a goal in
mind.
(A) webpage, website (B) web browser, webpage (C) server,
client (D) website, webpage
4. In the ___________ field of the e-mail, enter the recipients whose address you want
tohide from other recipients.
(A) Carbon Copy (B) To (C) Blind Carbon Copy
(D) All of the above
5. What do you understand by the term VoIP ? Give two examples of software/apps
based on VoIP.
6. What is the type of network for long distance communication ? (A) LAN (B) MAN
(C) WAN (D) PAN
7. What is the type of network for long distance communication ? (A) LAN (B) MAN
(C) WAN (D) PAN
8. ABC International School, Delhi has different wings as shown in the diagram :

Distance between the wings are as follows :


W3 to W1 70 m
W1 to W2 40 m
W2 to W4 15 m
W4 to W3 100 m
W3 to W2 120 m
W1 to W4 80 m
Number of computers in each of the wings :
W1 125
W2 40
W3 42
W4 60
Based on the above information, answer the following questions :
(a) Suggest the most suitable cable layout for the above connections.
(b) In which wing would you place the server ? Explain the reason for your
selection.
(c) Suggest the kind of network required (out of LAN, MAN, WAN) for
connecting Administrative Wing and Middle Wing.
(d) Suggest the placement of the following devices with justification : (i)
Repeater (ii) Switch/Hub
(e) There is one more branch of ABC International School in Mussoorie. The
schools want to link ABC International School, Delhi with ABC
International School, Mussoorie. Suggest the software(s) or app(s) to share the files
and videos.
9. With reference to computer networking, answer the following questions briefly :
(a) What is the significance of a switch in a computer network ?
(b) Mention the name of any two network topologies.
(c) What is MODEM ?
(d) Explain Gateway briefly.
(e) Expand VoIP.

You might also like