0% found this document useful (0 votes)
2 views6 pages

Paper01 QP Python FileHandling Stack

This document is a question paper for Class XII Computer Science, covering topics such as Python programming, functions, file handling, and stacks. It consists of 37 questions divided into five sections, with varying marks assigned to each section. The paper includes objective type questions, coding tasks, and long answer questions, all requiring answers in Python.

Uploaded by

mukesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Paper01 QP Python FileHandling Stack

This document is a question paper for Class XII Computer Science, covering topics such as Python programming, functions, file handling, and stacks. It consists of 37 questions divided into five sections, with varying marks assigned to each section. The paper includes objective type questions, coding tasks, and long answer questions, all requiring answers in Python.

Uploaded by

mukesh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Class XII | COMPUTER SCIENCE (083)

Topic: Python Revision (I & II), Functions, File Handling & Stack

Time : 3 Hours Max. Marks : 70

General Instructions:

1. This question paper contains 37 questions.


2. All questions are compulsory. However, internal choices have been provided in some questions. Attempt only ONE
of the choices in such questions.
3. The paper is divided into 5 Sections - A, B, C, D and E.
4. Section A consists of 21 questions (1 to 21), each carrying 1 mark.
5. Section B consists of 7 questions (22 to 28), each carrying 2 marks.
6. Section C consists of 3 questions (29 to 31), each carrying 3 marks.
7. Section D consists of 4 questions (32 to 35), each carrying 4 marks.
8. Section E consists of 2 questions (36 to 37), each carrying 5 marks.
9. All programming questions are to be answered using Python language only.
10. In case of MCQ, the text of the correct answer should also be written.

SECTION - A | OBJECTIVE TYPE QUESTIONS | 21 x 1 = 21 Marks

Q1. State whether the following statement is True or False:


Lists in Python are immutable.
Q2. What will be the output of the following code?
L = ['Sri', 'Chaitanya', 'School']
print(L[0][-1] + L[2][0])
a) iS b) iC c) Si d) SS
Q3. Consider the expression and predict the output:
print(15>20 or 8<10 and not 5==5)
a) True b) False c) None d) Error
Q4. Which of the following is an immutable data type in Python?
a) list
b) dictionary
c) tuple
d) set
Q5. What will be the output of the following code?
s = 'Education'
print(s[-3::-2])
a) iua b) iaE c) iouE d) iauE
Q6. Write the output of the following Python code:
for k in range(5, 25, 5):
print(k, end='*')
Q7. What will be the output of the following Python statement?
print(20 - 2**3**1 + 36/9)
Q8. What is the output of the following code?
try:
x = int('Python')
except ValueError:
print('Value Error!')
except Exception:
print('Some Error!')
a) Value Error! b) Some Error! c) ValueError d) Nothing
Q9. What will be the output of the following code?
d = {'name':'Mukesh', 'subject':'CS'}
print([Link]('class', 'Not Found'))
a) Mukesh b) CS c) None d) Not Found
Q10. What possible output(s) is/are expected at the time of execution of the following code?
import random
L = [11, 22, 33, 44, 55]
lower = [Link](1, 2)
upper = [Link](2, 3)
for k in range(lower, upper+1):
print(L[k], end='#')
a) 22#33# b) 22#33#44# c) 33#44# d) Both (a) and (c)
Q11. What will be the output of the following code?
x = 50
print(x, end='@')
def fun():
global x
x = x + 25
print(x, end='#')
fun()
print(x)
a) 50@75#75 b) 50@50#75 c) 50@75#50 d) 75@75#75
Q12. Which file mode opens a binary file for both reading and writing without truncating?
a) 'rb'
b) 'wb'
c) 'rb+'
d) 'ab'
Q13. What is the output of the given Python code?
s = 'Knowledge is Power'
print([Link]('e'))
a) ['Knowl', 'dg', ' is Pow', 'r']
b) ['Knowl','dge','is','Power']
c) ['Knowledg', 'is Pow', 'r']
d) Error
Q14. Which Python module is used for serializing Python objects into a binary stream?
a) csv
b) pickle
c) os
d) struct
Q15. A Stack data structure follows the principle of:
a) FIFO
b) LIFO
c) Random access
d) Priority order
Q16. The default return value of a function with no return statement is:
a) 0
b) None
c) False
d) Null
Q17. Which method is used to write a list of strings to a text file in a single call?
a) write()
b) writelines()
c) writelist()
d) writeall()
Q18. A stack is implemented using a Python list S. Which statement correctly removes the element from the top of the
stack?
a) [Link](0)
b) [Link]()
c) [Link](S[0])
d) del S[0]
Q19. Which method returns the current position of the file pointer in a file?
a) seek()
b) tell()
c) pos()
d) loc()
Q20 and Q21 are Assertion (A) and Reason (R) based. Mark the correct choice as:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is NOT the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Q20. Assertion (A): The 'with' statement in Python ensures that a file is closed automatically.
Reason (R): The 'with' statement uses a context manager that handles cleanup.
Q21. Assertion (A): In a stack, the element pushed last is popped first.
Reason (R): A stack is a linear data structure that follows the FIFO order.

SECTION - B | 7 x 2 = 14 Marks

Q22. (A) Explain the difference between local variable and global variable in Python with a suitable example.
OR

(B) Explain the difference between mutable and immutable data types in Python with one example each.
Q23. The code below is intended to compute the sum of digits of an integer. However, there are syntax and logical
errors in the code. Rewrite it after removing all the errors. Underline all the corrections made.
Define sum_digits(num):
total == 0
while num > 0
total = total + num%10
num = num/10
return total
Print('Sum =' sum_digits(247))
Q24. (A) Answer using Python built-in methods/functions only:
I. Write a statement to find the index of the first occurrence of 'is' in a string named 'msg'.
II. Write a statement to convert a list L into a tuple.
OR

(B) Predict the output of the following Python code:


txt = 'Class XII Computer Science'
print([Link](' '))
print([Link]('c'))
Q25. (A) Write a function CountVowels() in Python that accepts a string and returns the count of vowels (a, e, i, o, u —
both cases) present in the string.
OR

(B) Write a function AverageMarks() in Python that accepts a list of integers and returns the average of all even
numbers from the list.
Q26. Predict the output of the following Python code:
students = {'Aman':(85,90), 'Bhavya':(70,80),
'Chirag':(95,88), 'Diya':(60,72)}
selected = []
for name in students:
marks = students[name]
avg = (marks[0] + marks[1]) / 2
if avg >= 80:
[Link](name)
print(selected)
Q27. (A) Write suitable Python statements for the following:
I. To open a binary file '[Link]' for appending.
II. To position the file pointer to the beginning of an opened file 'f'.
OR

(B) Differentiate between readline() and readlines() methods of a file object with one example each.
Q28. (A) Define the following terms in one line each, with reference to file handling:
I. Absolute path II. File mode
OR

(B) I. Differentiate between a text file and a binary file.


SECTION - C | 3 x 3 = 9 Marks

Q29. (A) Write a Python function CountVowelLines() that reads a text file '[Link]' and displays the count of lines
that start with a vowel (A, E, I, O, U — any case).
OR

(B) Write a Python function CountWords() that reads a text file '[Link]' and returns the count of words having
more than 4 characters.
Q30. A list contains records of laptops as:
L = [('Dell',45000), ('HP',60000), ('Asus',38000),
('Acer',25000), ('Lenovo',55000)]
Write the following user-defined Python functions to perform operations on a stack named LapStk:
I. Push_element(L, LapStk) - to push items into the stack whose price is greater than 30000.
II. Pop_element(LapStk) - to pop items from the stack and display them; display 'Stack Empty' if the stack is
empty.
Q31. (A) Predict the output of the following Python code:
s1 = 'PY2026'
s2 = ''
i = 0
while i < len(s1):
if s1[i] >= '0' and s1[i] <= '9':
d = int(s1[i]) + 1
s2 += str(d)
elif s1[i].isupper():
s2 += s1[i].lower()
else:
s2 += '*'
i += 1
print(s2)
OR

(B) Predict the output of the following Python code:


subjects = ['Maths', 'Physics', 'Chemistry', 'Biology', 'English']
out = []
for s in subjects:
if s[-1] in 'aeiouAEIOU':
[Link](s[0].lower())
print(out)

SECTION - D | 4 x 4 = 16 Marks

Q32. (A) A text file '[Link]' contains several lines of text. Write the following user-defined Python functions:
I. CountUpper() – to read the file and display the total count of uppercase alphabets present in it. [2 Marks]
II. LongWords() – to read the file and display all words whose length is greater than 5 characters. [2 Marks]
OR

(B) Predict the output of the following Python code:


def Mystery(s):
r = ''
for ch in s:
if [Link]():
r += [Link]()
elif [Link]():
r += [Link]()
else:
r += '#'
return r
print(Mystery('Py 3.12'))
Q33. Mr. Mukesh is a CS teacher who maintains a CSV file '[Link]' containing student records. The columns of
the CSV file are: Roll, Name, Class, Marks. Help him by writing the following user-defined Python functions:
I. AddStudent() - to accept a student record from the user and add it to the file '[Link]'.
II. CountTopper() - to read the file '[Link]' and return the count of students whose Marks are greater
than or equal to 90.
Q34. A list contains the test scores of students as:
M = [78, 92, 45, 88, 60, 95, 34]
Write the following user-defined Python functions to operate on a stack named TopStk:
I. PushMarks(M, TopStk) – to push only those scores which are greater than or equal to 75 onto the stack. [2
Marks]
II. DisplayStack(TopStk) – to display all elements of the stack from top to bottom without removing them; display
'Empty Stack' if the stack is empty. [2 Marks]
Q35. (A) Predict the output of the following Python code:
def Update(d):
t = 0
for k in d:
if d[k] % 5 == 0:
d[k] += 5
t += 1
return t
data = {'a':10, 'b':12, 'c':25, 'd':8}
c = Update(data)
print(data)
print(c)
OR

(B) Predict the output of the following Python code:


def Power(b, e):
if e == 0:
return 1
return b * Power(b, e-1)
print(Power(3, 4))
print(Power(2, 0) + Power(5, 1))

SECTION - E | LONG ANSWER QUESTIONS - II | 2 x 5 = 10 Marks

Q36. Mr. Karthik, a CS teacher, maintains records of his students. Each record contains: Roll (int), Name (str), Class
(str) and Marks (float). Write the following Python functions to operate on a binary file '[Link]':
I. AddStudent() - to input student data from the user and append it to the binary file. [2 Marks]
II. ClassMarks() – Display Marks of all students of class 'XII'. [3 Marks]

Q37. (A) Sri Chaitanya maintains a binary file '[Link]' that stores records of products as dictionaries with the
keys: Pid, Pname, Price and Qty. Write the following user-defined Python functions:
I. ShowCostly() – to read '[Link]' and display the details of all products whose Price is greater than 1000.
[2 Marks]
II. UpdateQty(pid, newqty) – to search for the product whose Pid matches the given pid in '[Link]' and
update its Qty to newqty, writing the change back to the file. Display 'Product not found' if no such product exists.
[3 Marks]
OR

(B) Sri Chaitanya maintains a CSV file '[Link]' with the columns: Pid, Pname, Price, Qty. Write the following
user-defined Python functions:
I. AddProduct() – to accept a product record from the user and append it to '[Link]'. [2 Marks]
II. TotalStock() – to read '[Link]' and display the total value of stock, i.e. the sum of Price multiplied by
Qty for all the products. [3 Marks]

*** END OF QUESTION PAPER ***

You might also like