ASSIGNMENT
ASSIGNMENT
ASSIGNMENT
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
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 : 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
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 :
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 :