Python Pyq's
Python Pyq's
Q1. Name the Python Library modules which need to be imported to invoke the following
functions : (a) load () (b) pow () [CBSE Delhi 2016]
1. Uniform ()
2. fabs () [CBSE SQP 2016]
Q3. Differentiate between the round() and floor() functions with the help of suitable example.
[CBSE Comptt. 2016]
Q 4.Out of the following, find those identifiers, which cannot be used for naming Variables
or functions in a Python program:
Total * Tax, While, Class, Switch, 3rd Row, finally, Column 31, Total. [CBSE Outside
Delhi-2016]
Q5. Name the Python Library modules which need to be imported to invoke the following
functions :
1. sqrt()
2. dump() (CBSE Outside Delhi-2016)
Q 6. Out of the following, find the identifiers, which cannot be used for naming Variable or
Functions in a Python program: [CBSE Delhi 2016]
_Cost, Price*Qty, float, switch, Address one, Delete, Number12, do
Q 7.Out of the following find those identifiers, which can not be used for naming Variable or
Functions in a Python Program:
Days * Rent, For, A_price, Grand Total, do, 2Clients, Participantl, My city
i = 0
while i< 0 and i>2 :
print “Hello ...”
i = i+1
Q 14.How many times will Python execute the code inside the following while loop?
i = 1
while i< 10000 and i> 0 and 1:
print “ Hello ...”
i = 2 * i
Q 15.Convert the following for loop into while loop, for i in range (1,100):
if i % 4 == 2 :
print i, “mod”, 4 , “= 2”
for i in range(10):
for j in range(i):
print '$',
print"
Q 17. Rewrite the following for loop into while loop: [CBSE Text Book]
for a in range(25,500,25):
print a
Q 18. Rewrite the following for loop into while loop: [CBSE Text Book]
i=88
while(i>=8): print i
i- = 8
Q 20. Write for statement to print the series 10,20,30, ……., 300
Q 22. How many times is the following loop executed? [CBSE Text Book]
i = 100
while (i<=200):
print i
i + =20
Q 23.State whether the statement is True or False? No matter the underlying data type if
values are equal returns true,
char ch1, ch2;
if (ch1==ch2)
print “Equal”
TOPIC – 2
Writing Python Programs
Q 39. Rewrite the following code in Python after removing all syntax errors(s). Underline
each correction done in the code. [CBSE Delhi-2016]
for Name in [Amar, Shveta, Parag]
if Name [0] = „s‟:
Print (Name)
Q 40. Rewrite the following code is Python after removing all syntax errors(s).
Underline each correction done in the code. [CBSE Outside Delhi-2016]
for Name in [Ramesh, Suraj, Priya]
if Name [0] = „S‟:
Print (Name)
Q 41.Give the output of following with justification. [CBSE SQP 2015]
x = 3
x+ = x-x
print x
Q41. What will be printed, when following Python code is executed? [CBSE SQP 2015]
Q 44. Write the output from the following code: [CBSE Text Book]
x= 10
y = 20
if (x>y):
print x+y
else:
print x-y
s = 0
for I in range(10,2,-2):
s+=I
print “sum= ",s
n = 50
i = 5
s = 0
while i<n:
s+ = i
i+ = 10
print “i=”,i
print “sum=”,s
Q 47. Observe the following program and answer the Q that follows:
import random
x=3
N = random, randint (1, x)
for 1 in range (N):
print 1, „#‟, 1 + 1
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
Q 48. Observe the following Python code carefully and obtain the output, which will appear
on the screen after execution of it. [CBSE SQP 2016]
Q 50. What are the possible outcome(s) executed from the following code? Also,
specify the maximum and import random. [CBSE Delhi 2016]
PICK=random.randint (0,3)
CITY= ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"];
for I in CITY :
for J in range (1, PICK)
print (I, end = " ")
Print ()
Q 51.Find and write the output of the following Python code : [CBSE Outside Delhi-2016]
Values = [10,20,30,40]
for val in Values:
for I in range (1, Val%9):
print (I," * ", end= " ")
print ()
Q 52.Give the output of the following statements :
Q 53.
Give the output of the following statements :
A={10:1000,20:2000,30:3000,40:4000,50:5000}
print A.items()
print A.keys()
print A.values()
t=(10,20,30,40,50)
print len(t)
t=(„a‟,„b‟,„c‟,„A‟,„B‟)
print max(t)
print min(t)
T1=(10,20,30,40,50)
T2 =(10,20,30,40,50)
T3 =(100,200,300)
cmp(T1, T2)
cmp(T2,T3)
cmp(T3,T1)
T1=(10,20,30,40,50)
T2=(100,200,300)
T3=T1+T2
print T3
Q 59.Find the output from the following code:
t=tuple()
t = t +(„Python‟,)
print t
print len(t)
t1=(10,20,30)
print len(t1)
Q 60.Rewrite the following code in Python after remo¬ving all syntax error(s).
Underline each correction done in the code.
Q61. Find and write the output of the following Python code:
Q 62.
What are the possible outcome(s) executed from the following code? Also, specify the
maximum and minimum values that can be assigned to variable SEL.
import random
SEL=random. randint (0, 3)
ANIMAL = [“DEER”, “Monkey”, “COW”, “Kangaroo”];
for A in ANIMAL:
for AAin range (1, SEL):
print (A, end =“”)
print ()
TOPIC-3
Random Functions
Q.63 What are the possible outcome(s) executed from the following code ? Also specify the
maximum and minimum values that can be assigned to variable PICKER. [CBSE Outside
Delhi-2016]
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 ()
Q 64.What are the possible outcome(s) expected from the following python code? Also
specify maximum and minimum value, which we can have. [CBSE SQP 2015]
def main():
p = „MY PROGRAM‟
i = 0
while p[i] != „R‟:
l = random.randint(0,3) + 5
print p[l],‟-‟,
i += 1
(i) R – P – O – R –
(ii) P – O – R – Y –
(iii) O -R – A – G –
(iv) A- G – R – M –
TOPIC-4
Correcting The Errors
Q 65. Rewrite the following Python code after removing all syntax error(s). Underline the
corrections done.
[CBSE SQP 2015]
def main():
r = raw-input(„enter any radius : ‟)
a = pi * math.pow(r,2)
print “ Area = ” + a
if (a>b)
print a:
else if (a<b)
print b:
else
print “both are equal”
Q 70.Which string method is used to implement the following: [CBSE Text Book]
Q 71. Write a program to input any string and to find the number of words in the string.
Q72. Find and write the output of the following Python code:
Q73.
Q74.
Q77.
Q78. What will be the output of following code:
def Alter(x, y = 10, z=20):
sum=x+y+z
print(sum)
Alter(10,20,30)
Alter(20,30)
Alter(100)
Q79. Ravi a python programmer is working on a project, for some requirement, he has to
define a function with name CalculateInterest(), he defined it as:
def CalculateInterest(Principal,Rate=.06,Time): # code
But this code is not working, Can you help Ravi to identify the error in the above function
and what is the solution.
Q80. Which line number of code(s) will not work and why?
def Interest(P,R,T=7):
I = (P*R*T)/100
print(I)
Interest(20000,.08,15) #Line 1
Interest(T=10,20000,.075) #Line 2
Interest(50000,.07) #Line 3
Interest(P=10000,R=.06,Time=8) #Line 4
Interest(80000,T=10) #Line 5