Section A – Flow of Control
1. Write the output of the following code.
a, b, c, d = 100, 30, 1, 500
for a in range (50, b, -15):
d=d+a*c
c=c+1
print(“Result 1 = ”, c, end=” ”)
print(“Result 2 = “, d)
2. Write the values of A & C after the execution of the following code.
B, C = 70, 0
for A in range (31, B+1, 8):
C=C+A
A = C * 10
3. Write the output of the following coding.
M, N = 150, 80
while (M > N):
print (“Value = ”, (M+N))
M = M - 20
print (“Final M = ”, M)
4. How many numbers of times will the following loop executes?
x, y, z = 20, 45, 0
while (x < y):
z = z + x * 10
x = x + 12
print (“Result Z = ”, z)
Section B – String Handling
1. What will be the output of the following code?
S1 = “Amazon Prime TV”
print ( S1 [ : 6 ], S1 [ : -3], S1 [ 3 : ] )
print ( S1 [ 7 ] , S1 [ 4 : 7 ] )
print ( S1 [ 3 : -5 ], S1 [ -8 : -3 ] )
print ( S1 [2:12:3], S1 [ : : 2] )
1
2. Carefully go through the code given below and answer the questions
based on it.
testStr = “Welcome to Jungle Book”
inputStr = input(“Enter Integer: ”)
inputInt = int(inputStr)
count = 2
newStr = ‘ ’
while count <= inputInt :
newStr = newStr + testStr[0 : count]
testStr = testStr[-11 : -5] #Line 1
count = count + 1
print(newStr) #Line2
print(testStr) #Line3
print(count) #Line4
print(inputInt) #Line5
i) What will be the output produced in Line2, Line3, Line4 and Line5 when the input
integer is 3, 4 and 5?
ii) Which of the following statement is equivalent to the statement found in
Line 1?
(a) testStr = testStr[11 : 17] (b) testStr = testStr[11 : -5]
(b) testStr = testStr[-11 : 17]
3. Find and write the output of the following python code:
S = “Summer SALE 2020 @ Mega MALL”
k=len(S)
NS = “ ”
for I in range(0,k):
if(S[I].isupper()):
NS = NS + S[I].lower()
elif S[I].isalpha():
NS = NS + S[I].upper()
else:
NS = NS + “BLANK”
print(NS )
4. Find and write the output of the following python code :
Msg1 = “CORona Preventive MEAsures ”
Msg2 = “ ”
2
for I in range(0, len(Msg1)):
if Msg1[I] >= “A” and Msg1[I] <= “H”:
Msg2 = Msg2 + Msg1[I]
elif Msg1[I] >= “I” and Msg1[I] <= “Z”:
Msg2 = Msg2 + “%”
elif Msg1[I].isdigit():
Msg2 = Msg2 + “&”
else:
Msg3 = Msg3 + “#”
print(Msg3)
Section C – Lists in Python
1. Start with the list named MyList [300,325,375], Do the following using list functions:
(i) Set the second entry (index 1) to 315
(ii) Add 450,500,550 to the end of the list.
(iii) Remove the fourth entry from the list
(iv) Sort the list
(v) Replicate the list 5 times
(vi) Insert 425 at index 3
2. If MarkList is [78, 82, 45, 98, 36, 55, 15, 64].
(i) What is the difference between MarkList * 3 and [MarkList, MarkList, MarkList]?
(ii) Is MarkList * 4 is equivalent to MarkList + MarkList +MarkList + MarkList ?
(iii) What is the meaning of MarkList[1 : 1] = 72 ?
(iv) What is the difference between MarkList[1:2] = 35 and MarkList[1:1] = 35 ?
3. Predict the output
L1 = [25,32,12,32,28,25,16,32]
print(L1. index(16))
print(L1.count(25))
L1.append(L1.count(32))
print(L1)
4. Write a python program that input a list of numbers (List1), move all the positive
numbers to another list List2, move all the negative numbers to another list List3 and
count all the zeros in the original lists. Display all new lists along with zero count.
If List1 = [15, -3, -2, 18, 0, -5, 12, 17, 0, -6]
New List 1 = [15, 18, 12, 17] New List 2 = [-3, -2, -5, -6] No. of Zeros = 2.
3
5. Write a program that takes any two lists A and B of the same size and adds their
elements together to form a new list C whose elements are sums of the corresponding
elements in A and B. For instance, if A=[10,20,30] and B=[15,25,35], then C should equal
to [25,45,65].
Section D – Tuples and Dictionaries in Python
1. Write the code to create a PRODUCT dictionaries to store the details of N no. of product
items With Product Name as Key and its Rate as value. Print the FOOD dictionary. Also
input a Product name and checks whether the Product Name exist or not. If Product
name exists in the dictionary then the display the Product Name with its rate. Display
appropriate Error message when the Product Name not exist in the dictionary.
2. Predict the output for the following dictionary :
Books = {“Networks”: 750, “Compiler”:1150 “, “Microprocessor” : 955, }
NewBooks = {“JServer” : 575, “ASP” : 900, “C#” : 425}
print(Books.get(“Compiler”))
print(NewBooks.items())
Books.update(NewBooks)
print(NewBooks.values())
del Books[“Networks”]
print(Books.keys())
3. Predict the output.
a = (15, (20, (40, (50,))))
print(len(a))
print(a[1][1])
print(40 in a)
b = (1000,(2000,(3000,),4000),5000)
print(len(b))
print(len(b[1]))
print(b[0]+200)
4. What will be following code produce?
T5=(150,)*3
T5[0] = 200
print(T5)
5. What will be the output of the following code snippet?
Tup1 = ((5,10),) * 6
4
print(len(Tup1[2:4]))