Holiday Homework
Subject- Computer Science
Class-XII
Qno. 1
1 Which of the following is a valid arithmetic operator in Python?
(i) // (ii) ? (iii) < (iv) and
2 Which of the following operator(s) are valid logical operators?
(i) Like (ii) and (iii) or (iv) is
3 What will be the output of following expressions?
(i) 7/2 (ii) 7//2
4 If given A=20, B=15, C=30, What will be the output of following expression:
print((A>B) and (B>C) or (C>A))
5 What will be the output of following expressions?
(i) 15//2 (ii) 15%2
6 What will be the output of following expression?
2**2**4 2^8=256
7 Write the type of tokens from the following.
(i) If (ii) roll_no
8 Identify the valid identifier(s) from the given list:
Marks1, $Roll, Avg Marks, IF, _sales2008, while, name
9 Identify the invalid identifiers from the given list:
Average, RegNo. , break, Sales_Q1
10 Write the datatype of following literals:
(i) 100 (ii) False
11 Write the datatype of following literals:
(i) 50.7 (ii) “India”
12 What will be the output of following code:
print(print(10))
13 Name the Python Library module which need to be imported to invoke the following function:
(i) floor() (ii) bar() (iii) randint() (iv) sin()
(v) linspace() (vi) connect() (vii) dump() (viii) insort()
14 Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
30=To
for K in range(0, To)
IF k%4==0:
print (K*4)
Else:
print (K+3)
15 Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the code:
a=5 work=true
b=hello c=a+b
FOR i in range(10)
if i%7=0:
continue
16 for Name in [Ramesh ,Suraj, Priya] IF
Name[0]='S':
print(Name)
17 Rewrite the following code in python after removing all syntax error(s). Underline each correction done in the
code:
a=b=10
c=a+b While
c=<20:
print(c,END="*") c+=10
18 Find and write the output of the following python code:
msg = "Technology 2025"
print(msg[3:])
print(msg[:4],msg[4:])
print(msg[::-1])
print(msg[0:4],msg[11:10])
19 Find and write the output of the following python code:
def display(s): l =
len(s) m=””
for I in range(0,l):
if s[i].isupper():
m=m+s[i].lower()
elif s[i].isalpha():
m=m+s[i].upper()
elif s[i].isdigit():
m=m+”$”
else:
m=m+”*”
print(m) display(“EXAM20@cbse.com”)
20. Find and write the output of the following python code:
Msg="CompuTer"
Msg1='' “
for i in range(0, len(Msg)):
if Msg[i].isupper():
Msg1=Msg1+Msg[i].lower()
elif i%2==0:
Msg1=Msg1+'*'
else:
Msg1=Msg1+Msg[i].upper()
print(Msg1)
21. Find and write the output of the following python code:
P=6 Q=5
while P<=25:
Q+=10
P+=5
print(P)
print(Q)
23 Find and write the output of the following python code:
for i in range(1,6):
for j in range(1,6): if
i==j:
break
print(j, end='')
print()
24 How many times will the following for loop execute and what’s the output?
for i in range(1,3,1):
for j in range(i+1):
print(„*‟)
25 What will be the output of the following code: def
JumbleUp(mystr):
L = len(mystr)
str2=''
str3=''
for i in range(0,L,2):
str2=str2 + mystr[i+1]+mystr[i] for ch in
str2:
if ch>='R' and ch<='U':
str3+='$'
else:
str3+=ch.lower()
return str3
mystr="HARMONIOUS"
mystr=JumbleUp(mystr)
print(mystr)
26 Find the write the output of the following code: def Change(P
,Q=30):
P=P+Q
Q=P-Q
print( P,"#",Q)
return (P)
R=150
S=100
R=Change(R,S)
print(R,"#",S)
S=Change(S)
27 Find and write the output of following python code: def
Alter(M,N=50):
M= M +NN =
M -N
print(M,"@",N)
return M
A=200
B=100
A = Alter(A,B)
print(A,"#",B)
B = Alter(B)
28 Find and write the output of following python code: def
Total(Number=10):
Sum=0
for C in range(1,Number+1): if
C%2==0:
continue Sum+=C
return Sum
print(Total(4))
print(Total(7))
print(Total())
29 Find and write the output of following python code:
X = 100
def Change(P=10, Q=25): global
X
if P%6==0:
X+=100
else:
X+=50
Sum=P+Q+X
print(P,'#',Q,'$',Sum) Change()
Change(18,50)
Change(30,100)
30 Find and write the output of following python code: def
Func1(A,B):
if A % B == 0:
return 10
else:
return A + Func1(A,B-1) val =
Func1(20,15)
print(val)
31 What possible outputs(s) are expected to be displayed on screen at the time of execution of the program
from the following code? Also specify the maximum values that can be assigned to each of the variables
FROM and TO.
import random
AR=[20,30,40,50,60,70];
FROM=random.randint(1,3)
TO=random.randint(2,4)
for K in range(FROM,TO+1): print
(AR[K],end=”#“)
(i) 10#40#70# (ii) 30#40#50#
(iii) 50#60#70# (iv) 40#50#70#
32 What possible outputs(s) are expected to be displayed on screen at the time of execution of the program
from the following code? Also specify the maximum values that can be assigned to each of the variables
BEGIN and END.
import random
RUNS = [40,55,60,35,70,50]
BEGIN = random.randint(0,2)
END = random.randint(1,3)
for i in range(BEGIN,END+1):
print(RUNS[i],end='#')
(i) 60#35# (ii) 60#35#70#50#
(iii) 35#70#50# (iv) 40#55#60#
33. Differentiate between Syntax Error and Run time Error. Also write a suitable example in Python to illustrate
both.
Qno. 2
1 What do you understand by the term Iteration?
2 What is the purpose of “break‟ keyword in Loop?
3 What is the difference between List and Tuple?
4 What are the different ways to give comment in Python?
5 What are the correct ways to generate numbers from 0 to 20
(i) range(20) (ii) range(0,21) (iii) range(21) (iv) range(0,20)
6 Name any 2 data types of Python
7 What are the different loops available in Python?
8 What do you understand by the term Recursion?
9 Give any 1 difference between Loop and Recursion
10 What is Mutable data type? Give any example of Mutable data type.
11 Which is the correct form of declaration of dictionary?
(i) Day={1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟}
(ii) Day=(1;‟monday‟,2;‟tuesday‟,3;‟wednesday‟)
(iii) Day=[1:‟monday‟,2:‟tuesday‟,3:‟wednesday‟]
(iv) Day={1‟monday‟,2‟tuesday‟,3‟wednesday‟]
12 Choose the correct declaration from following code:
Info = ({“roll‟:[1,2,3],‟name‟:[„amit‟,‟sumit‟,‟rohit‟]})
(i) List (ii) Dictionary (iii) String (iv) Tuple
13 Which is the valid dictionary declaration?
i) d1={1:'January',2='February',3:'March'}
ii) d2=(1:'January',2:'February',3:'March'}
iii) d3={1:'January',2:'February',3:'March'}
iv) d4={1:January,2:February,3:March}
14 Given the following dictionary declaration: Myd = {„empno‟:1,‟name‟:‟Vikrant‟,‟salary‟:50000}
write python statement to print the message: Vikrant@50000
15 What is/are not true about Python‟s Dictionary?
(i) Dictionaries are mutable
(ii) Dictionary items can be accessed by their index position
(iii) No two keys of dictionary can be same
(iv) Dictionary keys must be of String data type
16 Given the following declaration:
Myd ={„empno‟:1,‟name‟:‟Vikrant‟,‟salary‟:50000}
Raj, Python programmer wants to print all the keys of dictionary and values stored in dictionary, Help
Raj by filling the blanks given in print() statement to achieve the task:
print( )
print( )
17 Identify the valid declaration of L:
L = [1, 23, “hi”,6].
(i) list (ii) dictionary (iii) array (iv) tuple
18 Identify the correct option to print the value 80 from the list L=[10,20,40,80,20,5,55]
(i) L[80] (ii) L[4] (iii) L[L] (iv) L[3]
19 Identify the valid declaration of Rec:
Rec=(1,‟Vikrant,50000)
(i)List (ii) Tuple (iii) String (iv) Dictionary
20 Given String STR=”COMPUTER”, choose the correct option(s) to print reverse of string.
(i) STR[::-1] (ii) STR[0,LEN(str)]
(ii) STR[-1:-1:0] (iv) STR[-1:-len(STR)-1:-1]
21 What will be the output of following python code:
for i in range(1,12):
if i%2==0:
continue
print(i)
22 What will be the output of following python code:
for i in range(1,12):
if i%6==0:
break
print(i)
23 x="abAbcAba"
for w in x:
if w=="a":
print("*")
else:
print(w)
24 What will be the output of following python code:
num=1
while num==1:
print(num)
num+=1
print(num*10)
25. Find and write the output of following python code: a=100
def show():
global a
a=200
def invoke():
global a
a=500
show()
invoke()
print(a)
27 Find and write the output of following python code:
def drawLine(ch,time=3):
print(ch*time)
drawLine('@',5)
drawLine(chr(65))
29 What do you understand the default argument in function? Which function parameter must be given
default argument if it is used? Give example of function header to illustrate default argument
30 What are the different types of Passing parameters in Python? Give example of anyone.
31 Output?
a=1
def f():
a = 10
print(a)
32 Which file must be present inside a directory to be considered by Python as a library?
33 Convert the following using while loop
for k in range (10,20,5):
print(k)
34 Give Output
colors=["violet", "indigo", "blue", "green", "yellow", "orange", "red"] del
colors[4]
colors.remove("blue")
colors.pop(3) print(colors)
35 Rewrite the following Python program after removing all the syntactical errors (if any), underlining
each correction:
def checkval:
x = input("Enter a number")
if x % 2 = 0:
print x, "is even" else if
x<0:
print x, "should be positive" else;
print x, "is odd"
36 Output?
def myfunc(a):
a=a+2
a=a*2
return a
print(myfunc(2))
37 Output?
def example(a):
a =a+ '2'
a = a*2
return a
example("hello")
Qno 3
1 If L1= [1,2,3,2,1,2,4,2, . . .], and L2= [10,20,30, . . .], then
(Answer using built-in functions only)
A) Write a statement to count the occurrences of 4 in L1.
OR
B) Write a statement to sort the elements of list L1 in ascending order.
2 A) Write a statement to insert all the elements of L2 at the end of L1.
OR
B) Write a statement to reverse the elements of list L2.
3 A file “MYDATA.TXT” is opened as
file1 = open(“MYDATA.TXT”)
Write a Python statement to close this file.
4 What is the different in file opening mode “a” and “w” ?
5 What is the significance of adding „+‟ with file opening mode, with context to „r+‟ ?
6 What is the difference between readline() and readlines() ?
7 Write the output of following statements –
f = open("CORONA.TXT")
sr1 = ____________ # to read first line of file
str2 = ___________ # to read next line of file
str3 = ___________ # to read remaining lines of file
8 Considering the content stored in file “WORLDCUP.TXT”, write the output
India won the Cricket world cup of 1983
f = open(“WORLDCUP.TXT”)
print(f.read(2))
print(f.read(2))
print(f.read(4))
9 Write a function in python to read lines from file “POEM.txt” and display all those
words, which has two characters in it.
For e.g. if the content of file is
O Corona O Corona
Jaldi se tum Go na
Social Distancing ka palan karona
sabse 1 meter ki duri rakhona
Lockdown me ghar me ho to
online padhai karona
O Corona O Corona
Jaldi se tum Go na
Output should be : se Go na ka ki me me ho to se Go na
10 Write a python function ATOEDISP() for each requirement in Python to read the file “NEWS.TXT” and
(I) Display “E” in place of all the occurrence of “A” in the word COMPUTER.
(II) Display “E” in place of all the occurrence of “A”:
I SELL COMPUTARS. I HAVE A COMPUTAR. I NEED A COMPUTAR. I WANT A
COMPUTAR. I USE THAT COMPUTAR. MY COMPUTAR CRASHED.
The function should display
(I) I SELL COMPUTERS. I HAVE A COMPUTER. I NEED A COMPUTER. I WANT A
COMPUTER. I USE THAT COMPTUER. MY COMPUTER CRASHED.
(II) I SELL COMPUTERS. I HEVE E COMPUTER. I NEED E COMPUTER. I WENT E
COMPUTER. I USE THET COMPTUER. MY COMPUTER CRESHED.
11. Write a Python function that count the lines start with the word “the” in a file “xyz.txt” and display it at the
end.
12. Write a Python function that Count total number of vowels in a file “abc.txt”
13. Write a user-defined function named Count() that will read the contents of text file named
“Report.txt” and count the number of lines which starts with either “I‟ or “M‟.
E.g. In the following paragraph, there are 2 lines starting with “I‟ or “M‟:
“India is the fastest growing economy.
India is looking for more investments around the globe.
The whole world is looking at India as a great market.
Most of the Indians can foresee the heights that India is capable of reaching.”