0% found this document useful (0 votes)
3 views4 pages

Paper02 QP Python FileHandling Stack 35marks

This document is a question paper for Class XII Computer Science covering topics such as Python functions, file handling, and stacks. It consists of 19 questions divided into five sections, with varying marks assigned to each section. The paper includes objective type questions, programming 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)
3 views4 pages

Paper02 QP Python FileHandling Stack 35marks

This document is a question paper for Class XII Computer Science covering topics such as Python functions, file handling, and stacks. It consists of 19 questions divided into five sections, with varying marks assigned to each section. The paper includes objective type questions, programming 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 : 1½ Hours Max. Marks : 35

General Instructions:
1. This question paper contains 19 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 11 questions (1 to 11), each carrying 1 mark.
5. Section B consists of 4 questions (12 to 15), each carrying 2 marks.
6. Section C consists of 1 question (16), carrying 3 marks.
7. Section D consists of 2 questions (17 to 18), each carrying 4 marks.
8. Section E consists of 1 question (19), 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 | 11 x 1 = 11 Marks

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


Tuples in Python are mutable.
Q2. What will be the output of the following code?
S = 'INFORMATICS'
print(S[2:8:2])
a) NRA b) NOM c) FRA d) FOM
Q3. Consider the expression and predict the output:
print(not 12 < 5 and 7 > 3 or 4 == 5)
a) True b) False c) None d) Error
Q4. Which of the following is a mutable data type in Python?
a) string b) tuple c) dictionary d) int
Q5. What will be the output of the following code?
s = 'Chaitanya'
print(s[::-3])
a) ant b) ayia c) atC d) aiC
Q6. Write the output of the following Python code:
for k in range(20, 5, -4):
print(k, end='@')

Q7. What will be the output of the following Python statement?


print(2 ** 2 ** 3 + 18 // 4 - 7 % 3)
Q8. Which file mode opens an existing text file for reading and writing, and truncates it to zero length?
a) 'r+' b) 'w+' c) 'a+' d) 'rb+'
Q9. What is the output of the following code?
d = {1:'one', 2:'two', 3:'three'}
[Link](2)
print(len(d), [Link](2, 'NA'))
a) 3 two b) 2 NA c) 2 None d) 3 NA
Q10 and Q11 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.
Q10. Assertion (A): The pickle module is used to store Python objects in a binary file.
Reason (R): Pickling converts a Python object into a byte stream that can be written to a binary file.
Q11. Assertion (A): A function in Python can return more than one value.
Reason (R): When multiple values are returned, Python packs them into a tuple.

SECTION - B | 4 x 2 = 8 Marks

Q12. (A) Explain the difference between actual parameters and formal parameters in a Python function,
with a suitable example.
OR
(B) Explain the difference between the readlines() method and the read() method of a file object, with
one example each.
Q13. The code below is intended to count the number of even numbers in a list. However, there are
syntax and logical errors in the code. Rewrite it after removing all the errors. Underline all the
corrections made.
def CountEven(L)
c = 0
for x in L:
if x % 2 = 0
c =+ 1
Return c
print('Even count =', CountEven[2, 5, 8, 11, 14])

Q14. (A) Answer using Python built-in methods/functions only:


I. Write a statement to replace all occurrences of 'a' with '*' in a string named 'word'.
II. Write a statement to return a list of all words in a string 'line' separated by commas.
OR
(B) Predict the output of the following Python code:
txt = 'Computer Science 2026'
print([Link](), [Link]())

Q15. (A) Write a function SumDigits() in Python that accepts an integer and returns the sum of its
digits.
OR
(B) Write a function CountBig() in Python that accepts a list of integers and returns the count of
numbers that are greater than 100.
SECTION - C | 1 x 3 = 3 Marks

Q16. A list contains records of books as:


B = [('Python', 350), ('Maths', 600), ('Science', 280),
('History', 720), ('English', 450)]
Write the following user-defined Python functions to perform operations on a stack named BookStk:
I. Push_book(B, BookStk) - to push items into the stack whose price is greater than 400.
II. Pop_book(BookStk) - to pop and display items from the stack; display 'Stack Empty' if the stack is
empty.

SECTION - D | 2 x 4 = 8 Marks

Q17. (A) A text file '[Link]' contains several lines of text. Write the following user-defined
Python functions:
I. CountDigits() – to read the file and display the total count of digits present in it. [2 Marks]
II. ShortWords() – to read the file and display all words whose length is less than 4 characters. [2
Marks]
OR
(B) Predict the output of the following Python code:
def Convert(s):
r = ''
for ch in s:
if [Link]():
r += '#'
elif [Link]():
r += [Link]()
else:
r += [Link]()
return r
print(Convert('Sri2 CS'))

Q18. Mr. Mukesh is a CS teacher who maintains a CSV file '[Link]' containing student records. The
columns of the CSV file are: Roll, Name, Subject, Score. Help him by writing the following user-defined
Python functions:
I. AddRecord() - to accept a student record from the user and add it to the file '[Link]'.
II. CountPass() - to read the file '[Link]' and return the count of students whose Score is
greater than or equal to 33.

SECTION - E | LONG ANSWER QUESTION | 1 x 5 = 5 Marks

Q19. (A) Sri Chaitanya maintains a binary file '[Link]' that stores records of employees as
dictionaries with the keys: Eid, Ename, Dept and Salary. Write the following user-defined Python
functions:
I. ShowHigh() – to read '[Link]' and display the details of all employees whose Salary is greater
than 50000. [2 Marks]
II. UpdateSalary(eid, newsal) – to search for the employee whose Eid matches the given eid in
'[Link]' and update the Salary to newsal, writing the change back to the file. Display 'Employee
not found' if no such record exists. [3 Marks]
OR
(B) Sri Chaitanya maintains a CSV file '[Link]' with the columns: Iid, Iname, Price, Qty. Write the
following user-defined Python functions:
I. AddItem() – to accept an item record from the user and append it to '[Link]'. [2 Marks]
II. CheapStock() – to read '[Link]' and display the details of all items whose Price is less than 100,
along with the total number of such items. [3 Marks]

***** END OF QUESTION PAPER *****

You might also like