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

Unit 1 Python Revision 1

The document is a revised syllabus for the Computer Science curriculum for Grade 12 at Holy Angel CBSE School for the academic year 2025-26. It includes a chapter-wise question bank focusing on Python programming and exception handling, with various types of questions including multiple choice and code output predictions. The syllabus emphasizes the importance of understanding Python syntax, exception handling mechanisms, and best practices in programming.

Uploaded by

holyangelcs25
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)
2 views21 pages

Unit 1 Python Revision 1

The document is a revised syllabus for the Computer Science curriculum for Grade 12 at Holy Angel CBSE School for the academic year 2025-26. It includes a chapter-wise question bank focusing on Python programming and exception handling, with various types of questions including multiple choice and code output predictions. The syllabus emphasizes the importance of understanding Python syntax, exception handling mechanisms, and best practices in programming.

Uploaded by

holyangelcs25
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/ 21

2025-26

REVISED
SYLLABUS

COMPUTER
SCIENCE
CHAPTER WISE
QUESTION BANK
2025-26 TERM-I

GRADE 12
HOLY ANGEL CBSE SCHOOL
Reddiyar Street (west), Near PerumalKoil, RETTANAI-604306
Tindivanam – T.K, Villuppuram –Dist, TamilNadu-India.
Phone: 04145-237214
Email: [email protected]

Subject: COMPUTER SCIENCE Grade: 12 Section: A,B,C

CHAPTER PYTHON REVISION -QUESTION BANK

SUBMISSION DATE 21-JULY -2025

1. Predict the output for the following 1 MARK


def add(n1,n2):
sum(n1+n2)
return(sum)
sum=add(20,30)
print(sum)
a.50
b.0
c. null
d. none

2 Select the correct output of the given python code 1 MARK


a= ― year 2022 at All the Best‖
a=a.split(‗2‘)
b=a[0]+ ―.‖ + a[1]+‖.‖ + a[3]
print(b)
a. year .0. at All the Best
b. year 0. at All the Best
c. year .022. at All the Best
d. Year .0. at all the Best
3 Write the output of the given python code 1 MARK
myexam=‖@@CBSE Examination 2022@@‖
print (myexam[:: -2])

4 write the output for given code: 1 MARK


import random
list1=["Delhi", "Mumbai", "chennai","kolkata"]
for y in range(4):
x=random.randint(1,3)
print(list1[x],end='#')
a. Delhi#Mumbai#mubai#chennai#
b. Mumbai#Mumbai#chennai#kolkata
c. Mumbai#Mumbai#chennai#kolkata#

1 | Page
HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
d. Mumbai#Mumbai#chennai#Delhi#

5 What is the output for the following code: 1 MARK


T=(100)
print(T*2)

6 Predict the output for the following code: 1 MARK


x= ―apple, pear , peach‖
y=x.split(―,‖)
for z in y:
print(z)

7 Predict the output of the given python code: 1 MARK


tup1=(10,20,30,40,50,60,70,80,90)
print(tup1[3:7:2])
a.(40,50,60,70,80)
b.(40,50,60,70)
c.[40,60]
d.(40,60)
8 State True or False : 1 MARK
―In Python, tuple is a mutable data type‖.
9 What will be the output of the following statement? 1 MARK
print(6+5/4**2//5+8)
a. –14.0
b. 14.0
c. 14
d. –14
11 Identify the valid Python identifier from the following: 1 MARK
a. 2user
b. user@2
c. user_2
d. user 2
12 Select the correct output of the code:
S = "text#next"
print(S.strip("t"))
a. ext#nex
b. ex#nex
c. text#nex
d. ext#next
13 What should be the output of the following code?
String = ―India will be a global player in the digital economy‖
Str1= String.title()
Str2=Str1.split()

2 | Page
HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
print(Str2[len(Str2)-1:-3:-1])
a. [‗Digital‘,‘Economy‘]
b. [‗The‘,‘Digital‘,‘Economy‘]
c. [‗economy‘,‘digital‘]
d. [‗Economy‘,‘Digital‘]
14 Observe the given code carefully: 1 MARK
a=20
def change(a):
b=20
a=a+b
change(10)
print(a)
Select the correct output from the given options:
a. 10
b. 20
c. 30
d. Error

15 What will be the output of the following: 2 MARKS


value=50
def display(N):
global value
value=75
if N%7==0:
value=value+N
else:
value=value-N
print(value,end='#')
display(20)
print(value)

16 Write the output for the following code: 2 MARKS


s= "Welcome2cs"
n=len(s)
m= " "
for i in range(0,n):
if (s[i]>= 'a' and s[i] <= 'm'):
m=m+s[i].upper()
elif(s[i]>='n' and s[i]<='z'):
m=m+s[i-1]
elif(s[i].isupper()):
m=m+s[i].lower()
else:
m=m+'&'
3 | Page
HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
print(m)

17 Write the output for the following code: 2 MARKS


tuple=(11,22,33,44,55,66)
list1=list(tuple1)
new_list=[]
for i in the list1:
if i%2==0:
new_list.append(i)
new_tuple=tuple(new_list)
print(new_tuple)

18 Find and write the output of the following python code: 2 MARKS
for Name in [‗peter‘, ‗paul‘ , ‗ken‘, ‗priya‘,‘shirley‘]
print(Name)
if Name[0]==‘K‘:
break
else:
print(‗Finished‘)
print(‗Completed‘)

19 Write the output of the given python code 2 MARKS


my_dict={―name‖:‖Aman‖, ―age‖:26}
my_dict[age]=27
my_dict[‗address‘]=‖Delhi‖
print(my_dict.items())

20 Find the output of the given code 3 MARKS


L1=[500, 800, 600, 200, 900]
START=1
SUM=0
for C in range (START, 4):
SUM=SUM+L1[C]
print (C, ―:‖, SUM)
SUM=SUM + L1 [0]*10
print(SUM)

21 Predict the output of the python code given below [3MARKS]


def Diff(x,y)
if x>y:
return x-y
else:
return y-x
z=[10, 20, 40, 50, 60]

4 | Page
HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
for i in range (4,0,-1):
a=z[i]
b=z[i-1]
print(Diff(a,b), ‗#‘ ,end=‘ ‗)

22. Rao has written a code to input a number and check whether it is 3 MARKS
prime or not. His code is having errors. Rewrite the correct
code
def prime():
n=int(input(―enter the number to check‖)
for i in range (2,n//2):
if n%i=0:
print(―number is not prime\n‖)
break:
else:
print(―number is prime\n‖)

23. what will be the output of the following : 3 MARKS


def my_func(var1=100, var2=200):
var1+=10
var2=var2-10
return var1+var2
print(my_func(50),my_func())

24. Write the output for the following code: 3 MARKS


p=5
def sum(q,r=2):
global p
p=r+q**2
print(p, end= ‗#‘)
a=10
b=5
sum(a,b)
sum(r=5,q=1)

25. Predict the output for the given python code: 3 MARKS
x= ―apple, pear,peach,banana,grapes‖
y=x.split(―,‖)
for z in y:
if z>‘f‘:
print(z.upper())
else:
print(z)

5 | Page
HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
Find the output for the code:
x=2
while x<9:
print(x,end=‖ ―)
x=x + 1

26. list1=[10,15,20,25,30] 3 MARKS


list1.insert(3,4)
list1.insert(2,3)
print(list1)
print(list1[-5])

Find the output:


x=[[10.0,11.0,12.0],[13.0,14.0,15.0]]
y=x[1][2]
print(y)

27. Meera has written a code to input a number and check whether it is prime 3 MARKS
or not. Her code is having errors. Rewrite the correct code and underline
the corrections made.
def prime():
n=int(input("Enter number to check :: ")
for i in range (2, n//2):
if n%i=0
print("Number is not prime \n")
break
else:
print("Number is prime \n‘)
28. Predict the output of the following code : 3 MARKS
d={"IND":"DEL","SRI":"COL","CHI":"BEI"}
str1=""
for i in d:
str1=str1 + str(d[i]) +"@"
str2=str1[ : -1]
print (str2)
29. Predict the output of the following code : 3 MARKS
def Total(Num=10):
Sum=0
for C in range(1, Num+1):
if C%2!=0:
continue
Sum+=C
return Sum
print(Total(4),end="$")

6 | Page
HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
print(Total(),sep="@")

30. Predict the output of the Python code given below: 3 MARKS
def Calc(N1,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [10,23,14,54,32]
for CNT in range (4,0,-1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Calc(A,B),'#', end=' ')

*******

7 | Page
HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
HOLY ANGEL CBSE SCHOOL
Reddiyar Street (west), Near PerumalKoil, RETTANAI-604306
Tindivanam – T.K, Villuppuram –Dist, TamilNadu-India.
Phone: 04145-237214
Email: [email protected]

Subject: COMPUTER SCIENCE Grade: 12 Section: A,B,C

CHAPTER EXCEPTION HANDLING IN PYTHON

SUBMISSION DATE 21-JULY -2025

I. OBJECTIVE TYPE QUESTIONS


SECTION -A
1 What is exception handling in programming? 1
A. A way to handle normal program flow
B. A mechanism to handle runtime errors and exceptional conditions
C. A method to optimize code performance
D. A technique for writing comments in code
2 What is a runtime exception?. 1

A. An error that occurs during compilation


B. An exception that occurs during program execution
C. A logical error in the code
D. A syntax error
3 Which is true about the finally block? 1
A. It is optional in exception handling
B. It must come before catch blocks
C. It can only be used once
D. It requires a catch block
4 What is the purpose of exception handling? 1
A. To make programs run faster
B. To prevent all errors from occurring
C. To handle runtime errors gracefully
D. To create program errors
5 When handling exceptions, what should you avoid? 1
A. Using specific exception types
B. Empty catch blocks
C. Multiple catch blocks
D. Using finally blocks
6 Which keyword is used to begin the exception handling block in 1
most programming languages?
A. handle
B. catch
C. try1
D. except
7 Which of the following is NOT a common type of exception? 1
A. NullPointerException
B. ArrayIndexOutOfBoundsException
C. CompileTimeException
D. ArithmeticException
8 What is the difference between throw and throws? 1
A. They are the same thing
B. throw is used to actually throw an exception, throws declares possible
exceptions
C. throws is used to throw exceptions, throw declares possible exceptions
D. Neither is related to exception handling
9 What happens when multiple catch blocks match an exception? 1
A. All matching blocks execute
B. The first matching block executes
C. The program crashes
D. None of the catch blocks execute
10 In a try-catch block, how many catch blocks can you have? 1
A. Only one
B. Maximum of two
C. Multiple catch blocks
D. None
11 What is a custom exception? 1
A. A built-in system exception
B. An exception defined by the programmer
C. An automatic exception handler
D. A compile-time error
12 Which is a best practice in exception handling? 1
A. Catch all exceptions with a single catch block
B. Never use try-catch blocks
C. Handle specific exceptions before general ones
D. Ignore all exceptions
13 What is the purpose of throwing an exception? 1
A. To improve program performance
B. To indicate an error condition
C. To debug the code
D. To optimize memory usage
14 What is the purpose of the 'finally' block in exception handling? 1
A. To define the type of exception
B. To catch specific exceptions
C. To execute code regardless of whether an exception occurred
D. To terminate the program
15 When should you use a finally block? 1
A. Only when exceptions occur
B. When handling multiple exceptions
C. For cleanup code that must always execute1
D. To catch runtime errors
16. Which of the following is NOT a common type of exception? 1
A. NullPointerException
B. ArrayIndexOutOfBoundsException
C. CompileTimeException
D. ArithmeticException
17. Which is a best practice in exception handling? 1
A. Catch all exceptions with a single catch block
B. Never use try-catch blocks
C. Handle specific exceptions before general ones
D. Ignore all exceptions
18. What is the purpose of throwing an exception? 1
A. To improve program performance
B. To indicate an error condition
C. To debug the code
D. To optimize memory usage
19. What happens when an exception is thrown but not caught? 1
A. The program continues normally
B. The program terminates abnormally
C. The exception is automatically handled
D. The code block is skipped
SECTION -B
19 What is an exception in Python? 2
20 Name two types of errors in Python. 2
21 What is the purpose of the try-except block? 2
22 What does the finally block do in exception handling? 2
23 What is the difference between except and else in a try block? 2
24 What will happen if no exception occurs in the try block? 2
25 Write the syntax of the try-except statement. 2
26 Can you have multiple except blocks for a single try block? 2
27 What does the raise statement do? 2
28 Name any two built-in exceptions in Python. 2
29 What will be the output of the following code? 3
try:
print(10 / 0)
except ZeroDivisionError:
print("Cannot divide by zero")
finally:
print("Done")
30 Write a Python program that handles division by zero. 3
31 Write code to handle an invalid value entered by the user when converting 3
input to an integer.
32 Write a try-except block to handle a file that does not exist. 3
33 Write a program that uses finally to print ―Program Completed‖ no matter 3
what happens.
34 Write a function that raises a ValueError if the input is negative. 3
35 Identify the error: 3
try:
f = open("file.txt")
data = f.read()
except:
print("File error")
f.close()
HOLY ANGEL CBSE SCHOOL
Reddiyar Street (west), Near PerumalKoil, RETTANAI-604306
Tindivanam – T.K, Villuppuram –Dist, TamilNadu-India.
Phone: 04145-237214
Email: [email protected]

Subject: COMPUTER SCIENCE Section: A,B,C

CHAPTER PYTHON -FILE HANDLING Grade: 12

SUBMISSION DATE : 21-JULY-2025

S.NO QUESTIONS MARKS

1 Which mode allows both reading and writing to a file? 1


A. 'rw'
B. 'r+'
C. 'w+'
D. 'a+'
2 How can you check if a file exists before opening it? 1
A. Using os.path.exists()
B. Using file.check()
C. Using file.exists()
D. Using path.verify()
3 What is the primary purpose of file handling in Python? 1
A. To create graphical user interfaces
B. To manage memory allocation
C. To read from and write to files on the computer
D. To handle network connections

4 Which mode opens a file for reading only? 1


A. 'w'
B. 'r'
C. 'a'
D. 'x'
5 What happens when you open a file in write mode ('w') that already 1
exists?
A. The file remains unchanged
B. The existing content is preserved and new content is appended
C. The existing content is deleted and the file is created as new
D. Python raises an error
6 Which method is used to read a single line from a file? 1
A. readline()
B. readlines()
C. read()
D. scan()

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
7 What is the purpose of the 'with' statement in file handling? 1
A. To create multiple files simultaneously
B. To automatically close the file after operations are complete
C. To compress the file contents
D. To encrypt file data
8 Which mode is used to append content to an existing file? 1
A. 'w+'
B. 'r+'
C. 'a'
D. 'x'
9 What method is used to write a string to a file? 1
A. write()
B. append()
C. insert()
D. put()
10 A binary file ―Book.dat‖ has structure [BookNo, Book_Name, Author, 3
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

11 A binary file ―STUDENT.DAT‖ has structure [admission_number, Name, 3


Percentage]. Write a function countrec() in Python that would read
contents of the file ―STUDENT.DAT‖ and display the details of those
students whose percentage is above 75. Also display number of
students scoring above 75%.
12 Write a function in python to search and display details, whose 3
destination is ―Cochin‖ from binary file ―Bus.Dat‖. Assuming the binary
file is containing the following elements in the list:
1. Bus Number
2. Bus Starting Point
3. Bus Destination

13 Write a function addrec() in Python to add more new records at the 3


bottom of a binary file ―STUDENT.dat‖, assuming the binary file is
containing the following structure :
[Roll Number, Student Name]

14 Write a function searchprod( pc) in python to display the record of a 3


particular product from a file product.dat whose code is passed as an
argument. Structure of product contains the following elements
[product code , product price]
15 Write a function routechange(route number) which takes the Route 4
number as parameter and modify the route name(Accept it from the
user) of passed route number in a binary file ―route.dat‖.

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
16 Write a function countrec(sport name) in Python which accepts the 4
name of sport as parameter and count and display the coach name of
a sport which is passed as argument from the binary file ―sport.dat‖.
Structure of record in a file is given below ——————– – [sport
name, coach name]
17 A binary file ―salary.DAT‖ has structure [employee id, employee name, 4
salary]. Write a function countrec() in Python that would read contents
of the file ―salary.DAT‖ and display the details of those employee
whose salary is above 20000.
18 Amit is a monitor of class XII-A and he stored the record of all the 4
students of his class in a file named ―class.dat‖. Structure of record is
[roll number, name, percentage]. His computer teacher has assigned
the following duty to Amit
Write a function remcount( ) to count the number of students who
need remedial class (student who scored less than 40 percent)

19 A binary file ―emp.dat‖ has structure [employee id, employee name]. 4


Write a function delrec(employee number) in Python that would read
contents of the file ―emp.dat‖ and delete the details of those employee
whose employee number is passed as argument.
20 Write a program to read all content of ―student.csv‖ and display 4
records of only those students who scored more than 80 marks.
Records stored in students is in format : Rollno, Name, Marks. Use
functions to get data (getdata()) from the user and displaydata() to
display students scored more than 80 marks.

21 Considering the content stored in file ―Computer.txt‖ 2


A computer is an electronic device.
Charles Babbage first invented the computer.
Computers play an extremely important function in our life.
The machine takes in data as input, processes it, and gives output.
Write the command for the following code and display the
output:
f=
open("Computer.TXT")
sr1 = # to read first line of file
str2 = # to read next line of file
str3 = # to read remaining lines
of file

22 What is the difference between write() and writelines()? 2

23 Considering the content stored in file ―WORLDCUP.TXT‖, write 2


the output
India won the Cricket world cup of 1983
f = open(―WORLDCUP.TXT‖)
print(f.read(2))
print(f.read(2))

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
print(f.read(4))

24 Write a function in python to count the number of lines in 4


―POEM.txt‖ begins from Upper case character.
25 Write a function in python to read lines from file 4
―POEM.txt‖ and count how many times the word ―Corona‖
exists in file.

26 Write a function in python to read lines from file ―NOTES.txt‖ 4


and display all those words, which has two characters in it.

27 Write a function COUNT() in Python to read contents from 4


file ―REPEATED.TXT‖, to count and display the occurrence of
the word ―Catholic‖ or ―mother

28 Write a function dispS() in Python to read from text file 4


―ARTICLE.TXT‖ and display those lines which starts with ―S‖

29 Write a python function ATOEDISP() in Python to read the file 4


―NEWS.TXT‖ and display ―E‖ in place of all the occurrence of ―A‖:
I SELL COMPUTARS. I HAVE A COMPUTAR. I NEED A
COMPUTAR. I WANT ACOMPUTAR. I USE THAT COMPUTAR.
MY COMPUTAR CRASHED.
The function should display

I SELL COMPUTERS. I HEVE E COMPUTER. I NEED E


COMPUTER. I WENT E COMPUTER. I USE THET COMPTUER.
MY COMPUTER CRESHED.

Q30 is Assertion(A) and Reason(R) 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

30 Assertion (A): Positional arguments in Python functions must be passed 2


in the exact order in which they are defined in the function signature.
Reasoning (R): This is because Python functions automatically assign
default values to positional arguments
31 Write a Python function that displays all the words containing @cmail 3
from a text file "Emails.txt".
OR
Write a Python function that finds and displays all the words longer than
5 characters from a text file "Words.txt".

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
32 Surya is a manager working in a recruitment agency. He needs to 5
manage the records of various candidates. For this, he wants the
following information of each candidate to be stored: - Candidate_ID –
integer - Candidate_Name – string - Designation – string - Experience –
float You, as a programmer of the company, have been assigned to do
this job for Surya.
Write a function to input the data of a candidate and append it in a
binary file.
Write a function to update the data of candidates whose experience is
more than 10 years and change their designation to "Senior Manager".
Write a function to read the data from the binary file and display the data
of all those candidates who are not "Senior Manager
33 Write a Python function that displays all the lines containing the 4
word 'vote' from a text file "Elections. bet". For example, if
the file contains : 3
In an election many people vote to choose their representative.
The candidate getting the maximum share of votes stands elected.
Normally, one person has to vote once.
The process of voting may vary with time and region.
Then the output should be :
In an election many people vote to choose their representative.
Normally, one person has to vote once.
34 Write a Python function that displays all the words starting and 4
ending with a vowel from a text file "Report. bet". The consecutive
words should be separated by a space in the output. For example, if the
file contains :
Once there was a wise man in a village.
He was an awesome story-teller.
He was able to keep people anchored while listening to him.
Then the output should be :
Once a a awesome able
35 A csv file "P _record. csv" contains the records of patients in a hospital. 4
Each record of the file contains the following data :
• Name of a patient
• Disease
• Number of days patient is admitted
• Amount
For example, a sample record of the file may be :
["Gunjan","Jaundice",4,15000]
Write the following Python functions to perform the specified operations
on this file :
(i) Write a function read_ data() which reads all the data from the
file and displays the details of all the 'Cancer' patients.
(ii) Write a function count_rec () which counts and returns the
number of records in the file.
*******

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
HOLY ANGEL CBSE SCHOOL
Reddiyar Street (west), Near PerumalKoil, RETTANAI-604306
Tindivanam – T.K, Villuppuram –Dist, TamilNadu-India.
Phone: 04145-237214
Email: [email protected]

Subject: COMPUTER SCIENCE Grade: 12 Section: A, B, C

CHAPTER STACKS – PYTHON

SUBMISSION DATE 21-JULY -2025

Q.No. QUESTIONS MARKS


1. What is a stack in Python? 1
A. A linear data structure that follows LIFO principle
B. A linear data structure that follows FIFO principle
C. A non-linear data structure for storing hierarchical data
D. A hash-based data structure for key-value pairs
2. Which Python list method is used to add an element to the top of a 1
stack?
A. insert()
B. append()
C. add()
D. push()
3. How can you implement a stack in Python? 1
A. Using only dictionaries
B. Using only tuples
C. Using lists
D. Using only sets
4. Which method removes and returns the top element from a stack? 1
A. remove()
B. delete()
C. pop()
D. extract()
5. Which operation checks the top element without removing it? 1
A. peek()
B. top()
C. view()
D. stack[-1]
6. Which data structure is best for implementing a stack? 1
A. Linked List
B. Array
C. Binary Tree
D. Hash Table
7. Which method would return the current size of a stack? 1
A. stack.length()
B. len(stack)
C. stack.size()
D. stack.count()

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
HOLY ANGEL CBSE SCHOOL
Reddiyar Street (west), Near PerumalKoil, RETTANAI-604306
Tindivanam – T.K, Villuppuram –Dist, TamilNadu-India.
Phone: 04145-237214
Email: [email protected]

8. Which of these is NOT a valid stack operation? 1


A. push()
B. pop()
C. sort()
D. peek()
9. Which method would return the current size of a stack? 1
A. stack.length()
B. len(stack)
C. stack.size()
D. stack.count()
10. In Python, what is the initial size of a newly created empty stack? 1
A. 10 elements
B. 1 element
C. 0 elements
D. 16 elements
11. What is Stack? What basic operations can be performed on them? 2

12. Given a bounded stack of capacity 4 which is initially empty, write 2


the stack content after each step:
a) Push ‗1‘ b) Push ‗2‘ c) Push ‗3‘ d) Push ‗4‘ e) Pop f) Pop
g) Push(‗5‘) h)Pop i)Pop j)Pop

13. A list, NList contains following record as list elements: 3


[City, Country, distance from Delhi]
Each of these records are nested together to form a nested list.
Write the following user defined functions in Python to perform the
specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an argument and
pushes a list object containing name of the city and country, which
are not in India and distance is less than 3500 km from Delhi.
(ii) Pop_element(): It pops the objects from the stack and displays
them. Also, the function should display ―Stack Empty‖ when there
are no elements in the stack.

For example: If the nested list contains the following data:


NList=[["New York", "U.S.A.", 11734], ["Naypyidaw", "Myanmar",
3219], ["Dubai", "UAE", 2194], ["London", "England", 6693], 3 [12]
["Gangtok", "India", 1580], ["Columbo", "Sri Lanka", 3405]]

The stack should contain:


['Naypyidaw', 'Myanmar'], ['Dubai', 'UAE'], ['Columbo', 'Sri Lanka']

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
HOLY ANGEL CBSE SCHOOL
Reddiyar Street (west), Near PerumalKoil, RETTANAI-604306
Tindivanam – T.K, Villuppuram –Dist, TamilNadu-India.
Phone: 04145-237214
Email: [email protected]

The output should be:


['Columbo', 'Sri Lanka']
['Dubai', 'UAE']
['Naypyidaw', 'Myanmar']
Stack Empty
14. Consider STACK=[‗a‘,‘b‘,‘c‘,‘d‘]. Write the STACK content after each 2
operation:
a) STACK.pop( )b) STACK.append(‗e‘) c) STACK.append(‗f‘) d)
STACK.pop( )

15. Write a program to implement a stack for the students (studentno, 3


name). Just implement Push.
def add(stk,item):
stk.append(item)
def display(stk):
top = len(stk)
for a in range(top-1,-1,-1):
print(stk[a])
stack=[]
while True:
print("STACK OPERATION:")
print("1.ADD student")
print("2.Display stack")
ch = int(input("Enter your choice(1-4):"))
if ch==1:
rno = int(input("Enter Roll no to be inserted :"))
sname = input("Enter Student name to be inserted :")
item = [rno,sname]
add(stack,item)
elif ch==2:
display(stack)
else:
print("invalid choice")

16. Find the output of the following code: 3


result=0
numberList=[10,20,30]
numberList.append(40)
result=result+ numberList.pop()
result=result+ numberList.pop()
print(result)
print(numberList)

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026
HOLY ANGEL CBSE SCHOOL
Reddiyar Street (west), Near PerumalKoil, RETTANAI-604306
Tindivanam – T.K, Villuppuram –Dist, TamilNadu-India.
Phone: 04145-237214
Email: [email protected]

17. Julie has created a dictionary containing names and marks as key 3
value pairs of 6 students. Write a program, with separate user
defined functions to perform the following operations:
● Push the keys (name of the student) of the dictionary into a stack,
where the corresponding value (marks) is greater than 75.
● Pop and display the content of the stack.
For example: If the sample content of the dictionary is as follows:
R= {"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}
The output from the program should be: TOM ANU BOB OM

R= {"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}


stack=[]
def dpush(d):
for i in d:
if d[i]>72:
stack.append(i)
def dpop():
while True:
if stack==[]:
print("stack is empty")
break
else:
print(stack.pop())
dpush(R)
dpop()
18. Write a function in python, PushEl(e) to add a new element and 3
PopEl(e) to delete an element from a List, considering them to act
as push and pop operations of the Stack data structure.
19. Write a function POP(Book) in Python to delete a Book from a list 3
of Book titles, considering it to act as a pop operation of the Stack
data structure.

*******

HOLY ANGEL CBSE SCHOOL /GRADE XII/DEPARTMENT OF CS/PREPARED BY: Mr.vimalraj R/2025-2026

You might also like