Xii HHW 2024-25
Xii HHW 2024-25
Class – XII
Subject – Computer Science
1. What will the following expression be evaluated to in Python?
print(4+3*5//3-5%2)
2. What will the following expression be evaluated to in Python?
5<10 and 12>7 or not 7>4
3. Rewrite the following code in Python after removing all syntax error(s). Underline each correction done
in the code.
Runs = ( 10, 5, 0, 2, 4, 3 )
for I in Runs:
if I=0:
print(Maiden Over)
else
print(Not Maiden)
4. Which of the following statements would give an error after executing the following code?
Stud={“Murugan”:100, “Mithun”:95} #Statement 1
print(Stud[95]) #Statement 2
Stud[“Murugan”]=99 #Statement 3
print(Stud.pop()) #Statement 4
print(Stud) #Statement 5
5. Consider the statements given below. What will be the output of the code?
pride="#G20 Presidency"
print(pride[-2:2:-2])
6. What will be the output of the code –
S=”Amrit Mahotsav @ 75”
A=S.partition(“ ”)
print(A)
7. What will be the output of the code :
S="Amrit Mahotsav @ 75"
A=S.split(" ",2)
print(A)
8. Given is a Python list declaration:
Listofnames=[“Aman”, “Ankit”, “Ashish”, “Rajan”, “Rajat”]
Write the output of:
print(Listofnames[-1:-4:-1]
9. Write the output of the code given below :
dict1={1:["Rohit",20], 2:["Siya",90]}
dict2={1:["Rahul",95], 5:["Rajan",80]}
dict1.update(dict2)
print(dict1.values())
10. Predict the output of the code given below:
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 +'&'
print(m)
11. Write a Python statement to declare a Dictionary named ClassRoll with Keys as 1, 2, 3 and
corresponding values as 'Reena', 'Rakesh', 'Zareen' respectively.
12. What possible output(s) are expected to be displayed on screen at the time of execution of the
following code ?
import random
S=["Pen","Pencil","Eraser","Bag","Book"]
for i in range (1,2):
f=random.randint(i,3)
s=random.randint(i+1,4)
print(S[f],S[s],sep=":")
13. What possible output(s) is/are expected to be displayed on the screen at the time of execution of the
program from the following code? Also specify the maximum and minimum value that can be assigned
to the variable R when K is assigned value as 2.
import random
Signal = ['Stop', 'Wait', 'Go' ]
for K in range(2, 0, -1):
R = randrange(K)
print (Signal[R], end = ' # ')
14. What possible outputs(s) will be obtained when the following code is executed?
import random
myNumber=random.randint(0,3)
COLOR=[“YELLOW”,”WHITE”,”BLACK”,”RED”]
for i in range(1,myNumber):
print(COLOR[i],end=”*”)
print()
15. Name the Python Library modules which need to be imported to invoke the following functions :
(a) cos() (b) randint()
16. Rao has written a code to input a number and check whether it is prime or not. His 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’)
17. Predict the output of the given code –
def makenew(mystr):
newstr= “”
count=0
for i in mystr:
if count%2!=0:
newstr=newstr+str(count)
else:
if i.lower():
newstr=newstr+i.upper()
else:
newstr=newstr+i
count+=1
print(newstr)
makenew(“No@1”)
18. Write the output of the Python code given below :
g=0
def fun1(x,y):
global g
g=x+y
return g
def fun2(m,n):
global g
g=m-n
return g
k=fun1(2,3)
fun2(k,7)
print(g)
19. Write the output for the execution of the following Python code :
def change(A):
S=0
for i in range(len(A)//2):
S+=(A[i]*2)
return S
B= [10,11,12,30,32,34,35,38,40,2]
C= Change(B)
print('Output is' , C)
20. Write a function EOReplace() in Python, which accepts a list L of numbers. Thereafter, it increments all
even numbers by 1 and decrements all odd numbers by 1.
21. Write a function search_replace() in Python which accepts a list L of numbers and a number to be
searched. If the number exists, it is replaced by 0 and if the number does not exist, an appropriate
message is displayed.
22. Write the definition of a function Sum3(L) in Python, which accepts a list L of integers and displays the
sum of all such integers from the list L which end with the digit 3.
23. What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k=foo()
print(k)
24. What will be the output of the following Python code?
def foo():
try:
print(1)
finally:
print(2)
foo()
25. What happens when ‘1’ == 1 is executed?
26. In exception handling, what is the order of blocks execution when an exception occurs?
27. Write the definition of a Python function named LongLines() which reads the content of a text file
named ‘Lines.txt’ and displays those lines from the file which have at least 10 words in it.
28. Write a function count_Dwords() in Python to count the words ending with a digit in a text file
“Details.txt”.
29. Write a program in Python that defines and calls the following user defined functions –
(a) Courier_add() – it takes the values from the user and adds the details to a csv file ‘courier.csv’. Each
record consists of a list with field elements as cid, s_name, source, destination to store Courier ID,
Sender name, Source and Destination address respectively.
(b) Courier_Search() – Takes the destination as the input and displays all the courier records going to
that destination.
30. Write a program in Python that defines and calls the following user defined functions –
(a) Add_Book() – Takes the details of the books and adds them a to a csv file ‘Book.csv’. Each record
consists of a list with field elements as book_ID, B_name and pub to store Book ID, Book name and
publisher respectively.
(b) Search_Book() – Takes publisher name as input and counts and displays number of books published
by them.