Worksheet 4 CS
Worksheet 4 CS
Worksheet 4 CS
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],”:”)
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)
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
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)