Holidays Homework class XII A Computer Science 2025-26
Assignment – 1 (Revision Tour)
1 State True or False:
The Python interpreter handles logical errors during code execution.
2 Identify the output of the following code snippet:
text = "PYTHONPROGRAM"
text=text.replace('PY','#')
print(text)
(A) #THONPROGRAM (B) ##THON#ROGRAM
(C) #THON#ROGRAM (D) #YTHON#ROGRAM
3 Which of the following expressions evaluates to False?
(A) not(True) and False (B)True or False
(C)not(False and True) (D)True and not(False)
4 What is the output of the expression?
country='International'
print(country.split("n"))
(A) ('I', 'ter', 'atio', 'al') (B) ['I', 'ter', 'atio', 'al']
(C) ['I', 'n', 'ter', 'n', 'atio', 'n', 'al'] (D) Error
5 What will be the output of the following code snippet?
message= "World Peace"
print(message[-2::-2])
6 What will be the output of the following code?
tuple1 = (1, 2, 3)
tuple2 = tuple1
tuple1 += (4,)
print(tuple1 == tuple2)
(A) True (B) False (C) tuple1 (D) Error
7 If my_dict is a dictionary as defined below, then which of the following statements will
raise an exception?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
(A) my_dict.get('orange') (B) print(my_dict['apple', 'banana'])
(C) my_dict['apple']=20 (D) print(str(my_dict))
8 What does the list.remove(x) method do in Python?
(A) Removes the element at index x from the list
(B) Removes the first occurrence of value x from the list
(C) Removes all occurrences of value x from the list
(D) Removes the last occurrence of value x from the list
9 What will be the output of the following code?
c = 10
def add():
global c
c=c+2
print(c,end='#')
add()
c=15
print(c,end='%')
(A) 12%15# (B) 15#12% (C) 12#15% (D) 12%15#
1 Assertion (A): Positional arguments in Python functions must be passed in the exact
0 order in which they are defined in the function signature.
Reasoning (R): This is because Python functions automatically assign default values
to positional arguments.
1 If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then
1 (Answer using builtin functions only)
A) Write a statement to count the occurrences of 4 in L1.
B) Write a statement to sort the elements of list L1 in ascending order
C) Write a statement to insert all the elements of L2 at the end of L1.
D) Write a statement to reverse the elements of list L2.
1 Identify the correct output(s) of the following code. Also write the minimum and the
2 maximum possible values of the variable b.
import random
a="Wisdom"
b=random.randint(1,6)
for i in range(0,b,2):
print(a[i],end='#')
(A) W# (B) W#i# (C) W#s# (D) W#i#s#
1 The code provided below is intended to swap the first and last elements of a given
3 tuple. However, there are syntax and logical errors in the code. Rewrite it after
removing all errors. Underline all the corrections made.
def swap_first_last(tup)
if len(tup) < 2:
return tup
new_tup = (tup[-1],) + tup[1:-1] + (tup[0])
return new_tup
result = swap_first_last((1, 2, 3, 4))
print("Swapped tuple: " result)
1 Predict the output of the following code:
4 d = {"apple": 15, "banana": 7, "cherry": 9}
str1 = ""
for key in d:
str1 = str1 + str(d[key]) + "@" + “\n”
str2 = str1[:-1]
print(str2)
1 Predict the output of the following code:
5 line=[4,9,12,6,20]
for I in line:
for j in range(1,I%5):
print(j,’#’,end=””)
print()
1 State True or False:
6 “In a Python program, if a break statement is given in a nested loop,
it terminates the execution of all loops in one go.”
1 What will be the output of the following statement:
7 print(3-2**2**3+99/11)
a. 244 b. 244.0 c. -244.0 d. Error
1 Select the correct output of the code:
8
a. PYTHON-IS-Fun b. PYTHON-is-Fun
c. Python-is-fun d. PYTHON-Is -Fun
1 Which of the following will delete key-value pair for key = “Red” from a
9 dictionary D1?
a. delete D1("Red") b. del D1["Red"]
c. del.D1["Red"] d. D1.del["Red"]
2 Consider the statements given below and then choose the correct
0 output from the given options:
pride="#G20 Presidency"
print(pride[-2:2:-2])
2 Consider the code given below:
1
Which of the following statements should be given in the blank for
#Missing Statement, if the output produced is 110?
2 Assertion(A): List is an immutable data type
2 Reasoning(R): When an attempt is made to update the value of an
immutable variable, the old variable is destroyed and a new variable
is created by the same name in memory
2 Assertion(A): Python Standard Library consists of various modules.
3 Reasoning(R): A function in a module is used to simplify the code and
avoids repetition.
2 Write the output of the code given below:
4 D={‘month’:’DECEMBER’,’exam’:’PREBOARD1’}
D[‘month’]=’JANUARY’
D[‘EXAM’]=’PRE2’
print(D.items())
Assignment – 2 ( Functions)
1 Assertion (A):- If the arguments in a function call statement match the
number and order of
arguments as defined in the function definition, such arguments are
called positional arguments.
Reasoning (R):- During a function call, the argument list first contains
default argument(s)
followed by positional argument(s).
2 The code given below accepts a number as an argument and returns
the reverse number. Observe the following code carefully and rewrite
it after removing all syntax and logical errors. Underline all the
corrections made.
3 Write a function countNow(PLACES) in Python, that takes the
dictionary, PLACES as an argument and displays the names (in
uppercase)of the places whose names are longer than 5 characters.
For example, Consider the following dictionary
PLACES={1:"Delhi",2:"London",3:"Paris",4:"New
York",5:"Doha"}
The output should be:
LONDON
NEW YORK
4 Write a function, lenWords(STRING), that takes a string as an
argument and returns a tuple containing length of each word of a
string.
For example, if the string is "Come let us have some fun", the tuple
will have (4, 3, 2, 4, 4, 3)
5 Predict the output of the following code:
6 Write a python function displaywords( L), where L is the list of words
passed as an argument that will print all the words that are having
length greater than 4.
7 Write a python function dispwords L), where L is the list of words
passed as an argument that will add all the words that are starting
with ‘a’ or ‘A’ in another list named newlist
8 Write a python function countvowel(S) that reads the characters of the
string S passed as argument and count the occurences of vowels
(A,E,I,O,U) in the file.
9 Predict the output of the following code:
1 Predict the output of the Python code given below:
0
1 Write a user defined function palindrom(s) - which takes string ‘s’ as
1 an argument and returns True if it is a palindrome and False if it is not
1 Write a function modifyList(L,n) in python, which accepts a list L of
2 numbers and n is the numeric value, Function should
Add 5 to all the values divisible by n
Subtract 5 from all the values not divisible by n
Display the modified list
Eg. if L=[10,11,13,15,20,2] and n=5 then the function should print
[15,6,8,20,25,-3]
1 Write the output of the following python code.
3 def change (msg):
n = len (msg)
new msg = M
for i in range(0,n):
if not msg[i].isalpha():
new_msg = new msg + '@'
else:
if msg[i].isupper():
new_msg = new_msg + msg[i]*2
else:
new_msg = new_msg + msg[i]
return new_msg
new_msg = change ("15 New Men")
print(new_msg)
1 Ravi a python programmer is working on a project, for some requirement, he has to define a
4 function with name CalculateInterest(), he defined it as:
def CalculateInterest (Principal, Rate=.06,Time): # code
But this code is not working, Can you help Ravi to identify the error in the above function and
what is the solution.
1 What is the difference between a Local Scope and Global Scope ? Also, give a suitable Python
5 code to illustrate both.
1 Define different types of formal arguments in Python, with example
6
1 the elements by 10 if the elements are divisible by 5. Also write a proper call statement
7 for the function.
For example:
If list L contains [3,5,10,12,15]
Then the modilist() should make the list L as
[3,15,20,12,25]
1 Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the
8 function. The function returns another list named ‘indexList’ that stores the indices of all
NonZero Elements of L.
For example: If L contains [12,4,0,11,0,56]
The indexList will have - [0,1,3,5]
1 Write a function LeftShift(Numlist, n) in Python, which accepts a list Numlist 3 of
9 numbers and n is a numeric value by which all elements of the list are shifted to left.
Sample input data of the list Numlist= [10, 20, 30, 40, 50, 60, 70], n=2
Output Numlist-[30, 40, 50, 60, 70, 10, 20]
2 Assertion (A): A variable declared as global inside a function is visible
0 with changes made to it outside the function.
Reasoning (A): All variables declared outside are not visible inside a function
till they are redeclared with global keyword.
2 Write a function UPDATE (L1) where L1 is the list of elements passed
1 as an argument to the function. The function returns another list
named L2 that stores the thrice of elements of L1 if element is even
otherwise twice of elements L1 e.g. if L1 contains [2,5,3,6] then L2 will
have [6,10,6,18]