XII Monthly test CS
XII Monthly test CS
XII Monthly test CS
21. 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)
22. 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#
23. What do you understand by local and global scope of variables? How can you access a global variable inside the
function, if function has a variable with same name.
24. Evaluate the following expressions:
a) 8 * 3 + 2**3 // 9 – 4
b) 12 > 15 and 8 > 12 or not 19 > 4
25. Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the
code.
p=30
for c in range(0,p)
If c%4==0:
print (c*4)
Elseif c%5==0:
print (c+3)
else
print(c+10)
26. 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 Lower and Upper.
import random
AR=[20,30,40,50,60,70];
Lower =random.randint(1,4)
Upper =random.randint(2,5)
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)
(i) 40# (ii) 40#50#60# (iii) 50# (iv) All of these
27. Rewrite the following code in python after removing all syntax errors. Underline each correction done in the code:
def func(a):
for i in (0,a):
if i%2 =0:
s=s+1
else if i%5= =0
m=m+2
else:
n=n+i
print(s,m,n)
func(15)