SLIP TEST - 2 FILE HANDLING & STACK

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

SLIP TEST - 2

Class : XII
Sub : Computer Science Marks : 25
SECTION A
1. Which of the following mode in file opening statement overwrite the existing content? (1)
(a) a+ (b) r+ (c) w+ (d) None of the above
2. Which of the following functions other than close() writes the buffer data to file . (1)
(a) push() (b) write() (c) writeBuffer() (d) flush()
Q4 and 5 are ASSERTION AND REASONING based questions. Mark the correct choice as
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True
3. Assertion (A): CSV (Comma Separated Values) is a file format for data storage with one record on
each line and each field is separated by comma.
Reason (R): The format is used to share data between cross platform as text editors are available
on all platforms. (1)
4. Assertion(A): Access mode ‘a’ opens a file for appending.
Reasoning(R): The file pointer is at the end of the file if the file exists. (1)
SECTION B
5. A list contains the following records of students: [Student_name, Percentage, State]
Write the following user-defined functions to perform given operations on the stack named
student:
(i) Push_Student(SDetails) - A function to push an object containing the name, percentage,
and state of students who have a percentage greater than 85 into the stack. Also, display
the count of students pushed into the stack.
(ii) Pop_Student() - A function to pop the objects from the stack and display them. If the stack
is empty, display "Stack Empty." (3)
6. Write a method beginA() in Python to read lines from a text file Notebook.TXT, and display those
lines, which are starting with ‘A’.
For example If the file content is as follows:
An apple a day keeps the doctor away.
We all pray for everyone’s safety.
A marked difference will come in our country.
The beginA() function should display the output as:
An apple a day keeps the doctor away.
A marked difference will come in our country. (3)
7. Riya, a computer science teacher at a high school, is managing a database for tracking students'
programming projects. She has created a CSV file named "Projects.csv" with the following
structure: [Proj_ID, Proj_Title, St_Name, Status]
Where:
Proj_ID is the project ID (integer)
Proj_Title is the title of the programming project (string)
St_Name is the student name (string)
Status represents the project status, which can be 'Completed', 'In Progress', or 'Not Started'. Riya
wants to enhance her program by implementing the following user-defined functions:
acceptProject() - To accept a new project record from the user and add it to the "Projects.csv" file.
The column headings should be added at the top of the CSV file. completedProjectsCount() - To
count the number of projects that are marked as 'Completed'. Assist Riya in completing these
functions. (4)
8. (i) Explain the distinctions between ‘a’ and ‘w’ modes in Python file handling. (1)
(ii) Suppose you have a file named "BOOKS.dat" with records [BookTitle, Author, Price].
Create a function, findExpensiveBooks(), that reads the file and returns the titles of books with
prices exceeding Rs. 500. (2)
(iii) Imagine a file, "EMPLOYEES.DAT," structured as [EmpID, EmpName, Salary]. Develop a
function, retrieveHighSalary(), to read the file and display employee names earning more than Rs.
75,000. (2)
9. A text file “PYTHON.TXT” contains alphanumeric text. Write a program that reads this text file
and writes to another file “PYTHON1.TXT” entire file except the numbers or digits in the file. (3)
10. A nested list contains the data of visitors in a museum. Each of the inner lists contains the
following data of a visitor: (3)
[V_no (int), Date (string), Name (string), Gender (String M/F), Age (int)]
Write the following user defined functions to perform given operations on the stack
named "status":
(i) Push_element(Visitors) - To Push an object containing Gender of visitor who
are in the age range of 15 to 20.
(ii) Pop_element() - To Pop the objects from the stack and count and display the
number of Male and Female entries in the stack. Also, display “Done” when
there are no elements in the stack.
For example: If the list of Visitors contains:
[['305', "10/11/2022", “Geeta”,"F”, 35],
['306', "10/11/2022", “Arham”,"M”, 15],
['307', "11/11/2022", “David”,"M”, 18],
['308', "11/11/2022", “Madhuri”,"F”, 17],
['309', "11/11/2022", “Sikandar”,"M”, 13]]
The stack should contain
F
M
M
The output should be:
Female: 1
Male: 2
Done

You might also like