12 Computer (2022-23)
12 Computer (2022-23)
Class – 12
Pre-Board Exam – 1
Computer Science
Max. Marks – 70
--------------------------------------------------------------------------------------------------------------------------------------------
SECTION A
( 1 mark × 20 = 20marks)
Q1: Find the invalid identifier from the following:
a. type b. None c. Name d. Pass
Q6: Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90)
print(tup1[-8:-2:2])
a) (20, 30, 40, 50, 60, 70) b) (20,30,40).
c) (20, 40, 60). d) (30,40,50)
Q7: Which of the following options can be used to read the first character of a text file Myfile.txt?
a) myfile = open('Myfile.txt')
myfile.read(1)
b) myfile = open('Myfile.txt','r')
myfile.read(n)
c) myfile = open('Myfile.txt')
myfile.readline()
d) myfile = open('Myfile.txt')
myfile.readlines()
Q8: What is the correct expansion of TSV files?
a) Tab Separable Values b) Tab Separated Values
c) Tab Split Values d) Tab Separation Values
Q9: What will be the output of the following code?
t1=[12,34,(45,67,[56]),78]
t1[2][2][0]=34
print(t1[2][2][0])
a) 56 b) 78 c) 34 d) Error Message
Q11: Consider a declaration L = [(1, 'Python', '3.14')]. Which of the following represents the data type of L?
a) list b) tuple. C) dictionary d). string
Q13: Which of the following components are part of a function call statement in Python?
a. Function Name
b. Return Statement
c. Parameter List
d. Both a and c
Q14: Which of the following method is used to read a binary file in python?
a. read() b. reader() c. load() d. dump()
Q16: What is used to define a block of code (body of loop, function etc.) in Python?
a) Curly braces b. Parenthesis c. Indentation d. Quotation
Q21: Write a user-defined function in python that displays the number of lines starting with ‘H’ in the file
para.txt. Example , if the file contains:
Whose woods these are I think I know
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow
Then the line count should be 2
Q22 :Write a method in python to read lines from a text file DIARY.TXT and display those lines which start
with the alphabet ’K’.
Q24: Write a method/function AEDISP() in python to read lines from a text file WRITER.TXT, and display
those lines, which are starting either with A or starting with E.
For example : If the content of the file is
A CLEAN ENVIRONMENT IS NECESSARY FOR OUR GOOD HEALTH.
WE SHOULD TAKE CARE OF OUR ENVIRONMENT.
EDUCATIONAL INSTITUTIONS SHOULD TAKE THE LEAD.
The method should display:
A CLEAN ENVIRONMENT IS NECESSARY FOR OUR GOOD HEALTH.
EDUCATIONAL INSTITUTIONS SHOULD TAKE THE LEAD
Q25: What is the difference between local and global variables? Explain giving example.
Q26: What is the advantage of using a csv file for permanent storage? Write a Program in Python that defines
and calls the following user defined functions:
a) ADD() – To accept and add data of an employee to a CSV file ‘record.csv’. Each record consists of a
list with field elements as empid, name and mobile to store employee id, employee name and
employee salary respectively.
b) COUNTR() – To count the number of records present in the CSV file named ‘record.csv’.
Q28: Write a function ETCount() in Python, which should read each character of a text file “TESTFILE.TXT”
and then count and display the count of occurrence of alphabets E and T individually (including small
cases e and t too).
Example:
If the file content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites
The ETCount() function should display the output as:
The number of E or e: 6
The number of T or t : 9
Q29: Write a function countmy( )in Python to read the text file “DATA.TXT” and count the number of times
“my” occurs in the file. For example if the file “DATA.TXT” contains:
“This is my website. I have displayed my preferences in the CHOICE section.”
The coutmy() function should display the output as: “my occurs 2 times”.
Q30: Evaluate the following postfix using stack & show the content of the stack after the execution of each: 12,
7,3,-, /,2 ,1 , 5, +, * ,+
Q31: Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for
each step of conversion:
a) A+B-D/X. b) (X+Y)/(Z*Y)-R
Q32: Write a program depending upon user’s choice either pushes or pops an element in A Stack?
MakeInIndia Corporation, an Uttarakhand based IT Training company, is planning to set up training
centers in various cities in next 2 years. Their first campus is coming up in Kashipur district. At Kashipur
campus, they are planning to have 3 different blocks for App development, Web designing and Movie
Editing. Each block has number of computers, which are required to be connected in a network for
communication, data and resource sharing. As a network consultant of this company, you have to suggest
the best network related solutions for them for issues/problems raised in question nos. (i) to (v), keeping
in mind the distance between various blocks/locations and other given parameter.
Block and Distance:
App development to Web designing 28 m
App development to Movie editing 55 m
Web designing to Movie editing 32 m
Kashipur Campus to Mussoorie Campus 232 km
Number of computers:
Block and Number of Computers:
App development 75
Web designing 50
Movie editing 80
(i) Suggest the most appropriate block/location to house the SERVER in the Kashipur campus (out of
the 3 blocks) to get the best and effective connectivity. Justify your answer.
(ii) Suggest a device/software to be installed in the Kashipur Campus to take care of data security.
(iii) Suggest the best wired medium and draw the cable layout (Block to Block) to economically connect
various blocks within the Kashipur Campus.
(iv) Suggest the placement of the following devices with appropriate reasons:
a. Switch / Hub b. Repeater
(v) Suggest the protocol that shall be needed to provide Video Conferencing solution between Kashipur
Campus and Mussoorie Campus.
Q34: 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 uptheir. their salary :: "))
while True:
try:
rec=______________ #Statement 3
if rec["Employee id"]==eid:
found=True
rec["Salary"]=int(input("Enter new salary :: "))
pickle.____________ #Statement 4
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print("The salary of employee id ",eid," has been updated.")
else:
print("No employee with such id is not found")
fin.close()
fout.close()
(i) Which module should be imported in the program? (Statement 1)
(ii) Write the correct statement required to open a temporary file named temp.dat for writing the
updated data. (Statement 2)
(iii) Which statement should Aman fill in Statement 3 to read the data from the binary file, record.dat
and in Statement 4 to write the updated data in the file, temp.dat?