0% found this document useful (0 votes)
24 views

class XII CS

Hji Jii Loop Good Hey

Uploaded by

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

class XII CS

Hji Jii Loop Good Hey

Uploaded by

34piyushsaini704
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Unit Test II (2024-25)

Subject : Computer Science (083)


Time: Class :- XII M.M. 50

Note: This question paper contain 30 question. All questions are compulsory.
1.Which of the following operations is NOT a valid operation in a stack?
A) Push C) Peek/Top
B) Pop D) Dequeue
2.Which of the following is the correct order of operations in a stack?
A) LIFO (Last In First Out) C) FILO (First In Last Out)
B) FIFO (First In First Out) D) Both A and C
3.Which of the following is the correct implementation for the Peek operation in a stack?
A) Remove the element at the top of the stack.
B) View the element at the top of the stack without removing it.
C) Add an element to the stack.
D) Clear all elements from the stack.
4.If a stack is implemented using an array of size n, what will happen if we attempt to Pop an element
when the stack is empty?
A) The stack will throw an exception.
B) The stack will remove a random element.
C) The stack will not allow any operation until a new element is added.
D) The stack will give an error but continue operations.
5.When performing a Pop operation on an empty stack, an exception (such as StackUnderflow) will occur,
as there are no elements to remove.
A) The stack has reached its maximum capacity. C) The stack is empty.
B) The stack has only one element. D) All elements in the stack have been removed.
6.In a recursive function, what data structure is often used to keep track of function calls?
A) Queue C) Array
B) Stack D) Linked List
7. Which function is used to open a file in Python?
a) open() c) close()
b) read() d) write()
8. What is the default mode for opening a file in Python if no mode is specified?
a) r+ c) r
b) w d) a
9. Which mode is used to open a file for writing in Python? If the file does not exist, it will be created.
a) r c) a
b) w d) rb
10. What will happen if you try to open a file in write mode (w) and the file does not exist?
a) An error will be raised. c) The program will not open the file.
b) The file will be created. d) The file will open in read mode by default.
11. Which function is used to read the entire content of a file in Python?
a) read() c) readlines()
b) readline() d) write()
12. What is the purpose of the close() function in file handling?
a) To close the file and release any resources used.
b) To open a file.
c) To read from the file.
d) To append data to a file.
13. In Python, which function is used to write data into a file?
a) write() c) read()
b) append() d) save()
14. Which of the following modes is used for appending data to a file?
a) r c) a
b) w d) rb
15. What does the readline() function do in file handling?
a) Reads the entire file. c) Reads one line at a time.
b) Reads the file line by line. d) Writes data to the file.
16. Which of the following functions can be used to read multiple lines of a file into a list?
a) read() c) readline()
b) readlines() d) write()
17. Which of the following will close a file after opening it in Python?
a) open().close() c) open(file).close()
b) file.close() d) open("file").exit()
18. What is the function to check the position of the file pointer in Python?
a) tell() c) position()
b) seek() d) locate()
19. Assertion:
The open() function in Python is used to read from or write to a file.
Reason:
The open() function opens a file in the specified mode (e.g., read, write, append), allowing operations like
reading or writing to the file.
Options:
a) Both Assertion and Reason are correct, and the Reason is the correct explanation for the Assertion.
b) Both Assertion and Reason are correct, but the Reason is not the correct explanation for the Assertion.
c) The Assertion is correct, but the Reason is incorrect.
d) The Assertion is incorrect, but the Reason is correct.
20. Assertion:
A stack can be implemented using a list in Python.
Reason:
A Python list supports operations such as append() (to push) and pop() (to pop), which are used to
implement a stack.
Options:
a) Both Assertion and Reason are correct, and the Reason is the correct explanation for the Assertion.
b) Both Assertion and Reason are correct, but the Reason is not the correct explanation for the Assertion.
c) The Assertion is correct, but the Reason is incorrect.
d) The Assertion is incorrect, but the Reason is correct.
21. Rewrite the following code in a python after removing all syntax error(s). Underline each correction
done in the code.
A = int(input("Enter any number:"))
Ar = 0
for x in range(0,A,2)
Ar+=x
if x%2=0:
Print (x*10)
Else:
Print ©
print (Ar)
22. Write a function in Python to count the number of in a text file ‘story.txt’ which is starting with an
alphabet ‘A’.
23. Write a method/ function displaywords() in Python to read lines from a text file ‘story.txt’ and display
those words, which are less than 4 characters.
24. Write a function countmy() in Python to read the text file ‘story.txt’ and count the number of times
‘my’ or ‘My’ curse in the file.
25. Write a program to read entire data from file data.csv .
26. Write a program to add/ insert record in file ‘data.csv’.Structure of a record in roll number ,name and
class.
27. Write a program to count number of records present in ‘data.csv’ file.
28. A binary file "Book.dat" has structure [BookNo, Book_Name, Author, Price].
1. Write a user defined function CreateFile() to input data for a record and add to Book.dat.
2. Write a function CountRec(Author) in Python which accepts the Author name as parameter and count
and return number of books by the given Author are stored in the binary file "Book.dat.
29.Write a function addrec() in Python to add more new records at the bottom of a binary file
"STUDENT.dat", assuming the binary file is containing the following structure:
[Roll Number, Student Name]
30. What is the difference between rb and wb in Python.

You might also like