Worksheet 4 CS

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

WORKSHEET – 4

Class – XII (CS) Name of Chapters: Functions


1. What are the possible outcome(s) executed from the following code? Also specify the maximum and (2)
minimum values that can be assigned to variable PICKER.
import random
PICK=random.randint(0,3)
CITY=[“DELHI”,”MUMBAI”,”CHENNAI”,”KOLKATA”]
for I in CITY:
for J in range(1,PICK):
print(I, end=””)
print()

2. What are the possible outcome(s) executed from the following code? Also specify the maximum and (2)
minimum values that can be assigned to variable ROUND.
import random
PLAY=[40,50,10,20]
ROUND=random.randint(2,3)
for J in range(ROUND,1,–1):
print (PLAY[J],”:”)

(i) 20:10: (ii) 20:10:50:


(iii) 20: (iv) 40:50:20:
3. What are the possible outcome(s) executed from the following code? Also specify the maximum and (2)
minimum values that can be assigned to variable N.
import random
SIDES=["EAST","WEST","NORTH","SOUTH"];
N=random.randint(1,3)
OUT=""
for I in range(N,1,–1):
OUT=OUT+SIDES[I]
print (OUT)
4. What possible outputs(s) are expected to be displayed on screen at the time of execution of the (3)
program from the following code? Also specify the minimum and maximum values that can be
assigned to each of the variables BEGIN and LAST.

import random
VALUES=[10,20,30,40,50,60,70,80];
BEGIN=random.randint(1,3)
LAST =random.randint(BEGIN,4)

for I in range(BEGIN,LAST+1):
print (VALUES[I],"-",end=’’)

5. What are the possible outcome(s) executed from the following code? Also specify the (2)
maximum and minimum values that can be assigned to variable PICKER.
import random
PICKER = random.randint (0, 3)
COLOR = ["BLUE", "PINK", "GREEN", "RED"]
for I in COLOR :
for J in range (1, PICKER):
print (I, end = " ")
print ()
(i) (ii) (iii) (iv)

BLUE BLUE PINK BLUEBLUE

PINK BLUEPINK PINKGREEN PINKPINK

GREEN BLUEPINKGREEN GREENRED GREENGREEN

RED BLUEPINKGREENRED REDRED

6. What are the possible outcome(s) executed from the following code? Also specify the maximum (2)
and minimum values that can be assigned to variable COUNT.

TEXT="CBSEONLINE"
COUNT=random.randint(0,3)
C=9
while TEXT[C]!='L':
print TEXT[C]+TEXT[COUNT]+'*',
COUNT=COUNT+1
C=C-1
(i) EC*NB*IS* (iii) NS*IE*LO*
(ii) ES*NE*IO* (iv) LE*NO*ON*

7. Observe the following program and answer the questions that follow: (2)
a. What is the minimum and maximum number of times the loop will execute?
b. Find out, which line of output(s) out of (i) to (iv) will not be expected from the program?
i. 0#1 ii. 1#2 iii. 2#3 iv. 3#4
8. Import random (2)
print(int(20 + random.random() * 5), end=’’)
print(int(20 + random.random() * 5), end=’’)
print(int(20 + random.random() * 5), end=’’)
print(int(20 + random.random() * 5))
Find the suggested output options (i) to (iv). Also, write the least value and highest
value that can be generated.
(i) 20 22 24 25
(ii) 22 23 24 25
(iii) 23 24 23 24
(iv) 21 21 21 21
9. Import random (2)
print(int(50 + random.random() * 5), end=’’)
print(int(50 + random.random() * 5), end=’’)
print(int(50 + random.random() * 5), end=’’)
print(int(50 + random.random() * 5))
Find the suggested output options (i) to (iv). Also, write the least value and highest
value that can be generated.
(i) 50 52 54 55
(ii) 52 53 54 55
(iii) 51 51 51 51
(iv) 53 54 53 54
10. Import random (2)
print(int(70 + random.random() * 5), end=’’)
print(int(70 + random.random() * 5), end=’’)
print(int(70 + random.random() * 5), end=’’)
print(int(70 + random.random() * 5))
Find the suggested output options (i) to (iv). Also, write the least value and highest
value that can be generated.
(i) 71 71 71 71
(ii) 73 74 73 74
(iii) 72 73 74 75
(iv) 70 72 74 75
11. Import random (2)
print(int(90 + random.random() * 5), end=’’)
print(int(90 + random.random() * 5), end=’’)
print(int(90 + random.random() * 5), end=’’)
print(int(90 + random.random() * 5))
Find the suggested output options (i) to (iv). Also, write the least value and highest
value that can be generated.
(i) 91 91 95 91
(ii) 92 93 94 95
(iii) 90 92 94 95
(iv) 93 94 93 94
12. Import random (2)
print(int(200 + random.random() * 5), end=’’)
print(int(200 + random.random() * 5), end=’’)
print(int(200 + random.random() * 5), end=’’)
print(int(200 + random.random() * 5))
Find the suggested output options (i) to (iv). Also, write the least value and highest
value that can be generated.
(i) 200 202 204 205
(ii) 202 203 204 205
(iii) 203 204 203 204
(iv) 201 201 201 201
13. Find and write the output of the following Python code after removing syntax errors. (3)
Underline each correction done in the code.
def Display(str)
m=""
for i in range[0,len(str)]:
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
Else:
if i%2=0:
m=m+str[i-1]
else:
m=m+"#
print(m)
display('[email protected]')
14. What possible output(s) are expected to be displayed on screen at the time of (2)
execution of the program from the following code?
from random import randint
LST=[5,10,15,20,25,30,35,40,45,50,60,70]
first = randint(3,8) – 1
second = randint(4,9) – 2
third = randint(6,11) – 3
print(LST[first],"#", LST[second],"#", LST[third],"#")
a) 20#25#25#
b) 30#40#70#
c) 15#60#70#
d) 35#40#60#
Specify the possible combination of values that can be assigned to each of the
variables first, second and third in the code given in above question -
a) First: 6, Second: 6, Third: 7
b) First: 7, Second: 7, Third: 8
c) First: 3, Second: 4, Third: 6
d) First: 8, Second: 8, Third: 9
15. Consider the following code: (1)
import math
import random
print(str(int(math.pow(random.randint(2,4),2))),end= ' ')
print(str(int(math.pow(random.randint(3,4),2))),end= ' ')
print(str(int(math.pow(random.randint(4,4),2))))
What could be the possible outputs out of the given four choices?
(a) 2 3 4
(b) 9 16 16
(c) 16 4 16
(d) 2 4 9
16. Find and write the output of the following python code: (1)
a=10
def call():
a=15
b=20
print(a+b,end=’ ‘)
call()
print(a)
a) 10 15 b) 35 10 c) 35 15 d) 15 15
17. Find and write the output of the following python code: (1)
a=10
def call():
global a
a=15
b=20
print(a+b, end=’ ‘)
call()
print(a)
a) 10 15 b) 35 10 c) 35 15 d) 15 15

18. Which of the following is a wrong way of defining a function:- (1)


a)def f(x=10, y=20, z=30) b)def f(x, y, z)
c)def f(x=10, y, z) d)def f(x, y=20, z=30)
19. What possible output(s) are expected to be displayed on screen at the time of execution of (2)
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
Arr=[20,30,40,50,60,70]
FROM= random.randint(1,3)
TO= random.randint(2,4)
for a in range(FROM, TO+1):
print(Arr[a]. end="#")
(a) 10#40#70# (b) 30#40#50# (c) 50#60#70# (d) 40#50#70#
20. Suppose list1 = [10 * x for x in range(10,50,5)]; the output of list1 is: (1)
(a) [100, 150, 200, 250, 300, 350, 400, 450, 500]
(b) [100, 150, 200, 250, 300, 350, 400, 450]
(c) [10, 15, 20, 25, 30, 35, 40, 45, 50]
(d) [10, 15, 20, 25, 30, 35, 40, 45]
21. Observe the following program and find out which output(s) out of (a) to (d) will not (2)
be expected from the program. What will be the minimum and maximum value
assigned to the variables X and Y?
import random
X= random.random()
Y= random.randint(0,4)
print (int (X),":", Y+ int(X))
(a) 0 : 0 (b) 1 : 6 (c) 2 : 4 (d) 0 : 3
22. Find the output of the following code: (3)
def CALLME(n1=1, n2=2):
n1=n1*n2
n2+=2
print(n1, n2)
CALLME()
CALLME(2,1)
CALLME(3)
23. What output will be generated when the following Python code is executed? (2)
def ChangeList():
L=[]
L1=[]
L2=[]
for i in range(1, 10):
L.append(i)
for i in range(10,1,-2):
L1.append(i)
for i in range(len(L1)):
L2.append(L1[i]+L[i])
L2.append(len(L)-len(L1))
print(L2)
ChangeList()
24. Which output is not possible? (2)
import random
r=["Amit","Sumit","Naina","Suman","Parth"]
min=random.randint(1,3)
max=random.randint(1,3)
print(r[0][min]+'#'+r[1][max])
a) i#i b) i#m c) s#h d) t#m
What is the minimum and maximum value of min and max in above question?
(a) 1,3 (b) 3,1 (c) 1,1 (d) 3,3
25. Which of the following function header is correct? (1)
a) def cal_si(p=200,r,t=3) b) def cal_si(p=100,r=8,t)
c) def cal_si(p,r=8,t) d) def cal_si(p,r=8,t=2)

26. Which of the following is the correct way to call a “my_func()” ? (1)
a) my_func() b) def my_func() c) return my_func() d) call my_func()
27. Which arguments are known as positional arguments? (1)
a) Keyword argument b) Default argument
a) Required argument d) Variable length argument
28. x=12 (1)
def f1(a,b=x):
print(a,b)
x=15
f1(4)
a) 15 4 b) 12 4 c) 4 12 d) 4 15
29. Which of the following function calls will cause Error while calling the below function (1)
definition?
def test(a,b,c,d)
a) test(1,2,3,4) b) test(4,5,6,7)
c) test(a=1,b=2,c=3,d=4) d) test(a=1,2,3,4)
30. Find the output of the following code: (3)
def CALLME(n1=1, n2=2):
n1=n1+n2
n2+=2
print(n1, n2)
CALLME()
CALLME(10,20)
CALLME(30)

You might also like