0% found this document useful (0 votes)
26 views

Python Pyq's

The document consists of a series of short answer questions related to Python programming, covering topics such as library modules, functions, loops, string methods, and error correction. It includes questions about syntax errors, output predictions, and the use of various Python features. The questions are designed for educational purposes, likely for a computer science curriculum.

Uploaded by

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

Python Pyq's

The document consists of a series of short answer questions related to Python programming, covering topics such as library modules, functions, loops, string methods, and error correction. It includes questions about syntax errors, output predictions, and the use of various Python features. The questions are designed for educational purposes, likely for a computer science curriculum.

Uploaded by

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

TOPIC – 1

Short Answer Type Qs :

Q1. Name the Python Library modules which need to be imported to invoke the following
functions : (a) load () (b) pow () [CBSE Delhi 2016]

Q2. Name the modules to which the following func-tions belong:

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

Q 8. Name the function / method required for [CBSE SQP 2015]

1. Finding second occurrence of m in madam.


2. get the position of an item in the list.

Q 9. Which string method is used to implement the following:

1. To count the number of characters in the string.


2. To change the first character of the string in capital letter.
3. To check whether given character is letter or a number.
4. To change lowercase to uppercase letter.
5. Change one character into another character. [CBSE TextBook]

Q 10.What is the difference between input() and raw_input()?


Q 11.What are the two ways of output using print()?
Q 12. Why does the expression 2 + 3*4 result in the value 14 and not the value 24?
Q 13. How many times will Python execute the code inside the following while loop? You
should answer the Q without using the interpreter! Justify your answers.

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”

Q 16.Convert the following for loop into while loop.

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]

for a in range(90, 9, -9):


print a

Q 19. Rewrite the following while loop into for loop:

i=88
while(i>=8): print i
i- = 8
Q 20. Write for statement to print the series 10,20,30, ……., 300

Q 21. Write for statement to print the series 105,98,91,… .7

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”

Q 24. What are the logical operators of Python?

Q 25. What is the difference between „/‟ and „//‟ ?

Q 26. How can we import a module in Python?

Q 27. What is the difference between parameters and arguments?


Q 28. What are default arguments?
Q 29. What are keyword arguments?
Q 30.What does “in” do?
Q 31.What does “slice” do?
Q 32. What is the use of negative indices in slicing?
Q 33. Explain find() function?
Q 38.What is the difference between a tuple and a list?

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 42. What would be the output of the following code snippets?


print 4+9
print “4+9”

Q 43. What is the result of 4+4/2+2?

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

Q 45. Write the output from the following code:

s = 0
for I in range(10,2,-2):
s+=I
print “sum= ",s

Q 46.Write the output from the following code: [CBSE TextBook]

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]

def Findoutput ():


L = "earn"
X = " "
count = 1
for i in L:
if i in ['a', 'e',' i', 'o', 'u']:
x = x + 1. Swapcase ()
else:
if (count % 2 ! = 0):
x = x + str (len (L[:count]))
else:
x = x + 1
count = count + 1
print x
Findoutput ()

Q 49.Find and write the output of the following Python code:

Number = [9,18,27,36] for N in Numbers:


print (N, "#", end = " ")
print ()

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 :

>>> str=„Honesty is the best policy‟


>>>str.replace(„o‟,„*‟)
.

Q 53.
Give the output of the following statements :

>> str=„Hello Python‟


>>>str.istitle()

Q54.Write the output for the following codes:

A={10:1000,20:2000,30:3000,40:4000,50:5000}
print A.items()
print A.keys()
print A.values()

Q55. Write the output from the following code:

t=(10,20,30,40,50)
print len(t)

Q 56.Write the output from the following code:

t=(„a‟,„b‟,„c‟,„A‟,„B‟)
print max(t)
print min(t)

Q 57.Write the output from the following code:

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)

Q 58.Write the output from the following code:

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.

for student in [Jaya, Priya, Gagan]


If Student [0] = „S‟:
print (student)

Q61. Find and write the output of the following Python code:

Values = [11, 22, 33, 44] for V in Values:


for NV in range (1, V%10):
print (NV, V)

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

Q 66. Rectify the error (if any) in the given statements.

>> str=“Hello Python”


>>>str[6]=„S‟

Q67. Find the errors from the following code:


T=[a,b,c]
print T

Q 68.Find the errors from the following code:

if (a>b)
print a:
else if (a<b)
print b:
else
print “both are equal”

Q 69. Find errors from the following codes:


c=dict()
n=input(Enter total number)
i=1
while i<=n:
a=raw_input(“enter place”)
b=raw_input(“enter number”)
c[a]=b
i=i+1
print “place”,“\t”,“number”
for i in c:
print i,“\t”,c[a[i]]

Q 70.Which string method is used to implement the following: [CBSE Text Book]

1. To count the number of characters in the string.


2. To change the first character of the string in capital letter.
3. To check whether given character is letter or a number.
4. To change lowercase to uppercase letter.
5. Change one character into another character.

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.

Q75. Predict the output from the following code:


Q76. Predict the output from the following code:

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

You might also like