Subject: Computer Science
Class XII
Time Allowed: 3 hours
Max. Marks: 70
Q1. Consider the given expression:
True and not False or True
Which of the following will be correct output if the given expression is evaluated?
(a) True (b) False (c) NONE (d) NULL
Q2. Given the following dictionaries
dict_exam={“Exam”. “AISSCE”, “Year”:2023
dict_result={“Total”:500, “Pass_Marks”:165)}
Which statement will merge the contents of both dictionaries?
a. dict_exam.update(dict_result) b. dict_exam + dict result
c. dict_exam.add(dict_result) d. dict_exam.merge(dict_result)
Q3. Out of the following find those identifiers, which cannot be used for naming a variable/functions in a Python program:-
a. Days*Rent b. FOR c. A_price d. 2Clients
Q4. A) Which of the following options can be the output for the following code?
import random
List-“Delhi”,”Mumbai”, “Chennai”,”Kolkata”]
for y in range(4):
x random.randint(1,3)
print(List[x)].end=”#”)
a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
B) What is the output of the following Python Code, Select any one of the following options?
import random
print(int(random.random()*5))
i. Always generate 0
ii. Generate any number between 0 to 4 (including both)
iii. Generate any number between 0 to 5 (including both)
Q5. State True or False “Variable declaration is explicit in’ Python.”
Q6. What is the correct syntax of seek)?
(a) file_object.seek(offset [, reference_point]))
(b) seek{offset, file object)
(c) seek(offset [, reference_point])
(d) seek.file object(offset)
Q7 (a) Given is a Python string declaration:
myexam=”@@ Columbia Foundation@@”
Write the output of: print(myexam|:-2)
(b) Write the output of the code given below:
my_dict= {“emp_name “: “Rohan”, “Salary”: 5000}
my_dict[‘Salary’] = 2700
my_dict[‘address’] = “Mumbai”
print(my_dict.items())
print(my_dict.keys())
(c) Predict the output of the Python code given below:
def DiffN1,N2):
if NI>N2:
return N1-N2
else:
return N2-N1
NUM=[13,67,54,89]
for CNT in range (4,1,-1):
A=NUM[CNT]
B-NUM[CNT-1J
print(DiffA,B),#, end=)
(d).Predict the output of the Python code given below:
tl = (15,14,20,19,25,27)
list1 =list(t1)
new_list =[]
for i%5 =0:
new_list.append(i)
new_tuple = tuple(new_list)
print(new_tuple)
Q8. Write a function ETCount() in Python, which should read each character of a text file DATA.TXT” and then count and display the count of occurrence of alphabets O and U individually (including small cases o and u to0o).
Example: If the file content is as follows:
Today is a pleasant day.
It might rain today.
It is mentioned on weather sites. you are good.
The ETCount() function should display the output as:
O or o: 6
U or u: 1
Q9. Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the function. The function returns another list named ‘indexList’ that stores the indices of all NonZero Elements of L.
For example:
If L contains [0,45,90,0,56]
The indexList will have – [1,2,4]
Q10. A list contains following record of a customer:
[Student_name, City]Write the following user defined functions to perform given opcrations on the stack named s’tatus’:
(i) Push_clement()- To Push an object containing name and City of students who live in Delhi to the stack. (ii) Pop_element() – To Pop the objects from the stack and display them. Also, display “Stack Empty” when there are no elements in the stack.
For example:
If the lists of customer details are:
[“Gurdas”, “Delhi”] [“Julee”, ”Mumbai”] [“Murugan”,”Cochin”] [“Ashmit”,”Goa”]The stack should contain
[“Ashmit”,”Delhi”]The output should be:
[“Ashmit”,”Delhi”]Stack Empty
Q11. What is the advantage of using a csv file for permanent storage?
Q12.Write a Program in Python that defines and calls the following user defined functions:
i) add)- To accept and add data of an employee to a CSV file ‘furdata.csv’. Each record consists of a list with field elements as fid, fname and fprice to store furniture
id, furniture name and furniture price respectively.
(ii) search()-To display the records of the furniture whose price is more than 10000.
Q13. Give any two points of difference between a binary file and text file?
Q14. Rohan 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 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:
print(“No employee with such id is not found”)
fin.close()
fout.close()
i) Which module should be imported in the program? (Statement1)
(ii) Write the correct statement required to open a temporary file named temp.dat. (Statement 2)
(iii) Which statement should Rohan 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?
Q15. What is the difference between readline) and readlines) ?
Q16. Write a function COUNT() in Python to read contents from file REPEATED.TXT”, tocount and display the occurrence of the word “Catholic” or “mother”.
Q17 a) Write a Python statement to reposition the read pointer to 40 bytes back from the current position.
f = open(“Emp.txt”,”rb”)
f.read(40)
f.read(40)
f.read(40)
f.________# reposition read pointer to previous record
f.close)
b) Define pickling and Unpickling in Binary File?
c) From the given path identify the type of each:
(i) C:\mydatalweblresourceslimgJPg
(ii) ..\webldata.conf
d) What is Local Variable and Global Variables? Ilustrate with example
e) What will be the output of following code?
def TotalNumber=10):
Sum=0
for C in range(1,Number+1):
if C%2==0:
continue
Sum+=C
return Sum
print(Total(4))
print(Total())
f) What will be the output of following code?
X= 50
def Alpha(num1):
global X
numl+=X
X+=20
numl = Beta(num1)
return num1
def Beta(num1):
global X
num1 +=X
X+= 10
numl = Gamma(num1)
return num1
def Gamma(num1):
X = 200
Num1 +=X
return num1
num= 100
num= Alpha(num)
print(num,X)
Q18.a) Define seek() function in binary file with an example?
b) Define data Structure and explain any 2 types of data structure?
Q19. Identify the correct output of the following python code:
def display(s):
L len(s)
M = “ “
for i in range(0,L):
if s[i].isupper():
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
elif s[i].isdigit():
m=m+”$”
else
m= m+”*”
print(m)
display(“EXAM20S$21”)
020. A) Now the data of each customer needs to be organised such that the customer can be identified by name followed by the age, item list and bill amount. Choose the appropriate data type that will help Priyank accomplish this task.
a. List b. Dictionary c. Nested Dictionary d. Tuple
B) Your teacher has given you a method/function FilterWords() in python which read lines from a text file NewsLetter.TXT, and display those words, which are lesser than 4 characters. Your teachers intentionally kept few blanks in between the code and asked you to fill the blanks so that the code will run to find desired result. Do the needful with the following python code.
def FilterWords():
c=0
file=open(‘NewslLetter.TXT’,’_______’) #Statement-1
line = file._______ #Statement-2
word= ________ #Statement-3
for c in word:
if ________ : #Statement-4
print(c)
___________#Statement-5
FilterWords()
i. Write mode of opening the file in statement-1?
a. a b. ab c. w d. r
ii. Fill in the blank in statement-2 to read the data from the file.
a. File.Read() b. file.read() C. read.lines() d. readlines()
iii. Fill in the blank in statement-3 to read data word by word.
a. Line.Split() b. Line.split) c. line.split) d. split.word()
iv. Fill in the blank in statement-4, which display the word having lesser than 4 characters’.
a. len(c)==4 b. len(c)<4 > < 4 c. len ()= =3 d. len ()==3
v. Fill in the blank in Statement-5 to close the file.
a. file.close() b. File.Close() c. Close() d. end()