0% found this document useful (0 votes)
85 views5 pages

Xii CS W2 - Python Basic and Random

Uploaded by

royalragul762
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views5 pages

Xii CS W2 - Python Basic and Random

Uploaded by

royalragul762
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SRI NACHAMMAL VIDYAVANI SENIOR SECONDARY SCHOOL

Devarayampalayam Bye-pass Road


Avinashi – 641654.

XII - Computer Science with Python

WORKSHEET - 2

Topics: Python basics & random function Max. Marks: 60


Chapter – 1 and 2
Part – 1(30 x 2 = 60)

1 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#

2 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#
3 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 PICKER=random.randint(0,3)
COLORS=["BLUE","PINK","GREEN","RED"]
for I in COLORS:
for J in
range(1,PICKER)
:
print(I,end="")
print()
(i) (ii)
BLUE BLUE
PINK BLUEPINK
GREEN BLUEPINKGREEN
RED BLUEPINKGREENRED
(iii (iv)
) BLUEBLUE
PINK PINKPINK
PINKGREEN GREENGREEN
PINKGREENRED REDRED

5 Differentiate between Syntax Error and Run time Error. Also write a
suitable example in Python to illustrate both.

6
7 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() statenebt to achieve the task:
print( ) print(
)
8 Identify the valid declaration of L: L = [1, 23, „hi‟, 6].
(i) list (ii) dictionary (iii) array (iv) tuple
9 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]
10 Identify the valid declaration of Rec: Rec=(1,‟Vikrant,50000)
(i)List(ii) Tuple (iii) String (iv) Dictionary

11 Given String STR=”COMPUTER”, choose the correct option(s) to print


reverse of string.
(i)STR[::-1] (ii)STR[0,LEN(str)]
(iii) STR[-1:-1:0] (iv) STR[-1:-len(STR)-1:-1]
12 What will be the output of following python code:
for i in range(1,12):
if i%2==0:
continue
print(i)
13 What will be the output of following python code:
for i in range(1,12):
if i%6==0:
break
print(i)

14 x="abAbcAb
a" for w
in x:
if w=="a":
print("*")
else:
print(w)
15 What will be the output of following
python code: num=1
while num==1:
print(num) num+=1
print(num*10)
16

17 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)

18 Find and write the output of following


python code: def drawLine(ch,time=3):
print(ch*time)
drawLine('@',5)
drawLine(chr(65))
19

20 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
21 What are the different types of Passing parameters in Python? Give
example of any
one.
22 Write to create Pie chart for sequence
con=[24.5,19.2,25,30,45] for Zones
=[„East‟,‟West‟,‟North‟,‟South‟,‟Central‟]
- Show % contribution for each zone
- The Pie should be
circular OR
Give the output of the following
python code: import
matplotlib.pyplot as plt
x=[1,2,3]
y=[5,3,7]
x2=[1,2,3]
y2=[8,4,9]
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.title('My First Chart\nHave fun!')
plt.plot(x,y,label='Overs',color='r')
plt.plot(x2,y2,label='Runs',color='g')
plt.legend()
plt.show()
23 Output? a = 1 def f(): a = 10
print(a)

24 Which file must be present inside a directory to be considered by


Python as a library?
25 Convert the following using while loop
for k in range (10,20,5):
print(k)
26 Give Output
colors=["violet", "indigo", "blue", "green", "yellow", "orange",
"red"] del colors[4]
colors.remove("blue")
colors.pop(3) print(colors)

27 Consider the following unsorted list: 95 79 19 43 52 3. Write


the passes of bubble sort for sorting the list in ascending
order till the 3rd iteration
28 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"

29 Output?
def myfunc(a): a = a + 2
a = a * 2 return a
print(myfunc(2))

30 Output?
def example(a): a = a + '2'
a = a*2
return a
example("hello")

You might also like