Professional Documents
Culture Documents
(2015 ONWARDS)
2. Name the Python Library modules which need to be imported to invoke the following functions :
(i) open()
(ii) factorial()
3.Rewrite the following code in Python after removing all syntax error(s). Underline each correction
done in the code.
"HELLO"=String
for I in range (0,len(String)–1)
if String[I]=>"M":
print (String[I],"*”)
Else:
print (String [I-1])
6. What possible output(s) are expected to be displayed on screen at the time of execution of the
program from the following Python code ? Also specify the minimum values that can be assigned
to each of the variables BEGIN and LAST.
import random
VAL=[80,70,60,50,40,30,20,10]
Start=random.randint(1,3)
End=random.randint(Start,4)
for I in range(Start,End+1):
print (VAL[I],"*",)
(i) 40 * 30 * 20 * 10 * (ii) 70 * 60 * 50 * 40 * 30 *
(iii) 50 * 40 * 30 * (iv) 60 * 50 * 40 * 30 *
7.Name the Python Library modules which need to be imported to invoke the following functions : 1
(i) sqrt()
(ii) start()
8.Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
250 = Number
WHILE Number<=1000:
if Number=>750:
print( Number)
Number=Number+100
else
print Number*2
Number=Number+50
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print( Msg3)
11.What possible output(s) are expected to be displayed on screen at the time of execution of
the program from the following code ? Also specify the minimum 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],"-",)
(i) 30 - 40 - 50 - (ii) 10 - 20 - 30 - 40 -
(iii) 30 - 40 - 50 - 60 - (iv) 30 - 40 - 50 - 60 - 70 –
(i) elif
(ii) BREAK
(iii) in
(iv) _Total
13.Name the Python Library modules which need to be imported to invoke the following
functions :
(i) ceil()
(ii) randint()
14.Rewrite the following code in Python after removing all syntax error(s). Underline each
correction done in the code.
NUM1=1234
1=DAY1
for C in range[1,4]:
NUM+C=NUM1
DAY1=DAY1+2
print ( C )
print (NUM1:DAY1)
16. What are the possible outcome(s) executed from the following code ? Also specify the
maximum and minimum values that can be assigned to variable N.
import random
PLAY=[40,50,10,20]"EAST","WEST","NORTH","SOUTH";
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:
17.Out of the following, find those identifiers, which cannot be used for naming Variable or
Functions in a Python program:
print()
21.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.
import random
PICK=random.randint(0,3)
CITY=[“DELHI”,”MUMBAI”,”CHENNAI”,”KOLKATA”];
for I in CITY:
print()
(i) (ii)
DELHIDELHI DELHI
MUMBAIMUMBAI DELHIMUMBAI
CHENNAICHENNAI DELHIMUMBAICHENNAI
KOLKATAKOLKATA
(iii) (iv)
DELHI DELHI
MUMBAI MUMBAIMUMBAI
CHENNAI KOLKATAKOLKATAKOLKATA
KOLKATA
22.Out of the following, find those identifiers, which cannot be used for 2
naming Variables or Functions in a Python program :
(i) sqrt()
(ii) dump()
24.Rewrite the following code in Python after removing all syntax error(s). 2
IF Name[0]='S':
print(Name)
Values=[10,20,30,40]
for I in range(1,Val%9):
print(I,”*”,end =””)
print()
26. What are the possible outcome(s) executed from the following code ?
Also2specify the 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 inrange(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
(i) 4thSum
(ii) Total
(iii) Number#
(iv) _Data
28.Name the Python Library modules which need to be imported to invoke the following functions
:
(i) floor()
(ii) randint()
29.Rewrite the following code in Python after removing all syntax error(s). Underline each
correction done in the code.
STRING=""WELCOME NOTE""
for S in range[0,8]:
print STRING(S)
print S+STRING
TXT = ["20","50","30","40"]
CNT =3
TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
CNT-=1
31.What are the possible outcome(s) executed from the following code ? Also specify the maximum
and minimum values that can be assigned to the variable N.
import random
NAV = ["LEFT","FRONT","RIGHT","BACK"]
NUM = random.randint(1,3)
NAVG = ""
NAVG = NAVG+NAV[I]
print (NAVG)
32.Name the Python Library modules which need to be imported to invoke the following
functions :
(i) sin()
(ii) search()
33.Rewrite the following code in Python after removing all syntax error(s). Underline each
correction done in the code.
Val = int(input("Value:"))
Adder = 0
for C in range(1,Val,3)
Adder+C
If C%2=0:
print(C*10)
Else:
print( C)
print (Adder)
Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha = ""
Add =0
for C in range(1,6,2):
Times = Times + C
print (Times,Add,Alpha)
35.What possible output(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 LAST.
import random
POINTS=[20,40,10,30,15];
POINTS=[30,50,20,40,45];
BEGIN=random.randint(1,3)
LAST=random.randint(2,4)
for C in range(BEGIN,LAST+1):
print (POINTS[C],"#")
(i) 20#50#30# (ii) 20#40#45#
36.Name the Python Library modules which need to be imported to invoke the following
functions
37.Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
Num = int(input("Number:"))
Sum = 0
for i in range(10,Num,3)
Sum+=i
if i%2=0:
print (i*2)
Else:
print( i*3)
print (Sum)
38. Find and write the output of the following python code :
Val = [20,"A",40,"K",10,"H"]
Freq =0
Sum =0
Cat = ""
for I in range(1,6,2):
Freq = Freq + I
print (Freq,Sum,Cat)
39.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 START and END.
import random
SCORE=[20,40,10,30,15];
START=random.randint(1,3) END=random.randint(2,4)
for I in range(START,END+1):
print SCORE([I],"&",)
(i) 10&40&20& (ii) 10&30&15&
(iii) 40&10&30& (iv) 20&40&10&
41.Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code.
def Sum(Count)
S=0
for I in Range(1,Count+1):
S+=I
RETURN S
print Sum[2] #FunctionCall print
Sum[5]
print (Name)
if Name[0]=='S':
break
else:
print( 'Completed!' )
print('Welldone!')
43.What are the possible outcome(s) executed from the following code ? Also specify
the maximum 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
44.Observe the following Python functions and write the name(s) of the module(s) to which they
belong:
a. uniform() b. findall()
45.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”)
def makenew(mystr):
newstr = " " count = 0
for i in mystr:
if count%2 !=0:
newstr = newstr+str(count) else:
if islower(i):
newstr = newstr+upper(i) else:
newstr = newstr+icount +=1
newstr = newstr+mystr[:1]
print ("The new string is :",newstr )
makenew(“sTUdeNT")
47.Find the output of the following program
def calcresult () :
i=9
while i> 1 :
if (i % 2 == 0):
x = i%2
i = i-1
else :
i = i-2
x=i
print( x**2)
48.Observe the following Python code and find out , which out of the given options i) to iv)
are the expected correct output(s).Also assign the maximum and minimum value that can be
assigned to the variable ‘Go’.
import random
X =[100,75,10,125]
Go = random.randint(0,3) for i in
range(Go):
print (X[i],"$$",)
i. 100$$75$$10 ii. 75$$10$$125$$iii. 75$$10$$ iv.10$$125$$100
49.Carefully observe the following python code and answer the questions that follow:
53.Write a Python method/function SwitchOver(Val) to swap the even and odd positions of the
values in the list Val.
Note : Assuming that the list has even number of values in it.
For example :
If the list Numbers contain
[25,17,19,13,12,15]
After swapping the list content should be displayed as
[17,25,13,19,15,12]
54.Write definition of a method EvenSum(NUMBERS) to add those values in the list of NUMBERS,
which are odd.
56.Write definition of a method/function HowMany(ID,Val) to count and display number of times the
value of Val is present in the list ID.
For example :
If the ID contains [115,122,137,110,122,113] and Val contains
122
The function should display
122 found 2 Times
57.Write the definition of a method ZeroEnding(SCORES) to add all those values in the list
of SCORES, which are ending with zero (0) and display the sum.
For example :
If the SCORES contain [200, 456, 300, 100, 234, 678]
The sum should be displayed as 600
58. Write a Python method/function Count(Start,End,Step) to display natural numbers from Start.
End in equal intervals of Step
For example :
If the values of Start as 14, End as 35 and Step as 6
The method should be displayed as
14
20
26
32
For example :
["ZAHEEN","TOM","CATHERINE","AMIT","HEENA"]
And
61.Write a python method/function Swapper(Numbers) to swap the first half of the content of a list
Numbers with second half of thec ontent of list Numbers and display the swapped values.
Note : Assuming that the list has even number of values in it.
For example :
If the list Numbers contains
[35,67,89,23,12,45]
After swapping the list content should be displayed as
[23,12,45,35,67,89]
62.Write a python method/function Count3and7(N) to find and display the count of all those
numbers which are between 1 and N, which are either divisible by 3 or by 7.
For example :
If the value of N is 15
The sum should be displayed as
7
(as 3,6,7,9,12,14,15 in between 1 to 15 are either divisible by 3 or 7)
63.Write a method/function in python to find and display the prime numbers between 2 to N. Pass
N as argument to the method.
DATA STRUCTURES
1.Write InsQueue(Passenger) and DelQueue(Passenger) methods/function in Python to add a new
Passenger and delete a Passenger from a list of Passenger names, considering them to act as
insert and delete operations of the Queue data structure.
2.Write DoPush(Customer) and DoPop(Customer) methods/function in Python to add a new
Customer and delete a Customer from a List of Customer names, considering them to act as push
and pop operations of the Stack data structure.
3.Write Insert(Place) and Delete(Place) methods in python to add Place and Remove Place
considering them to act as Insert and Delete operations of the data structure Queue.
4.Write Addnew(Member) and Remove(Member) methods in Python to Add a new Member and
Remove a Member from a list of Members, considering them to act as INSERT and DELETE
operations of the data structure Queue.
6.Write PushOn(Book) and Pop(Book) methods/functions in Python to add a new Book and delete
a Book from a List of Book titles, considering them to act as push and pop operations of the Stack
data structure.
1.Write a statement in Python to open a text file CONTENT.TXT so that new contents can be
written in it.
2. Write a statement in Python to open a text file REMARKS.TXT so that existing content can be
read from it.
3.Write a method/function BIGWORDS() in Python to read contents from a text file CODE.TXT, to
count and display the occurrence of those words, which are having 5 or more alphabets. 2
For example :
If the content of the file is ME AND MY FRIENDS
ENSURE SAFETY AND SECURITY OF
EVERYONE
4.Write a method in Python to read lines from a text file NOTES.TXT, and count those lines, which
are ending with ‘.’ or ‘,’.
5.Write a statement in Python to perform the following operations :
8.Write a statement in Python to open a text file README.TXT so that existing content can be read
from it.
Count of IS TO and UP is 6
10.Write a method/function AEDISP() in python to read lines from a text file WRITER.TXT, and
display those lines, which are starting either with A or starting with E.
11.Write a statement in Python to open a text file STORY.TXT so thatnew contents can be added
at the end of it.
12.Write a method in Python to read lines from a text file INDIA.TXT, to find and display the
occurrence of the word ‘‘India’’.
13. Write a user defined function in Python that displays the number of lines starting with ‘H’
in the file Para.txt
14.Write a user defined function to display the total number of words present in the file.
15. Write a method in python to read the content from a text file story.txt line by line and
display the same on screen.
_____________________BEST WISHES______________________
MRS M DEBNATH
PGT CS
KV BARRACKPORE(AFS)