0% found this document useful (0 votes)
44 views9 pages

Python Revision Tour 2 worksheet

The document contains a series of Python programming questions and multiple-choice answers related to various concepts such as strings, tuples, lists, dictionaries, and their operations. Each question tests the reader's understanding of Python syntax and behavior. The document serves as a revision guide for students preparing for a Computer Science examination.

Uploaded by

A.S.Vishwaa
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)
44 views9 pages

Python Revision Tour 2 worksheet

The document contains a series of Python programming questions and multiple-choice answers related to various concepts such as strings, tuples, lists, dictionaries, and their operations. Each question tests the reader's understanding of Python syntax and behavior. The document serves as a revision guide for students preparing for a Computer Science examination.

Uploaded by

A.S.Vishwaa
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/ 9

VELAMMAL VIDYALAYA – SHOLINGANALLUR.

XII - COMPUTER SCIENCE (083)


Python Revision Tour 2
1. For a given declaration in Python as s=”WELCOME”
Which of the following will be the correct output of print (s[1:2])?
a. WEL b. COME c. E d. ECM
2. Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80) b. (40,50,60,70) c. [40,60] d. (40,60)
3. Consider a tuple tup1 = (10, 15, 25, and 30). Identify the statement that will result in an
error.
a. print(tup1[2]) b. tup1[2] = 20 c. print(min(tup1)) d. print(len(tup1))
4. Which of these about a dictionary is false?
a. The values of a dictionary can be accessed using keys
b. The keys of a dictionary can be accessed using values
c. Dictionaries aren’t ordered
d. Dictionaries are mutable
5. What is the output of following code?
T=(100)
print(T*2)
a. Syntax error b. (200,) c. 200 d. (100,100)
6. Identify the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
a. 12.0 b. 13.0 c. 14.0 d. 15.0
7. Given the lists L=[1,3,6,82,5,7,11,92] , write the output of print(L[2:5])
Ans:-

1
8. What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
a. (1,2,[3.14,2],3) b. (1,2,[1,3.14],3) c. (1,2,[1,2],3.14) d. Error Message
9. Identify the output of the following Python statements.
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
a. 2 b. 3 c. 4 d. 20
10. Identify the output of the following code snippet:
remark = "SQL - Structured Query Language"
note = remark[2:18].split()
print(note)
a. ['L', '-', 'Structured', 'Qu'] b. ['L', '-', 'Structured', ' ']
c. ['L', '-', 'Structured', 'Q'] d. 'L – Structured Q'
11. A tuple is declared as
T = (2,5,6,9,8)
What will be the value of sum(T)?
Ans:-
12. What will be the output of the following python code?
L=[10,20]
L1=[30,40]
L2=[50,60]
L.append(L1)
L.extend(L2)
print(L)

2
13. Write a statement in Python to declare a dictionary whose keys are 1, 2, 3 and values
are Monday, Tuesday and Wednesday respectively.
14. What is the output of the expression?
STR=”trip@split”
print(STR.rstrip(“t”))
a. rip@spli b. trip@spli c. rip@split d. rip@spli
15. What will be the output of the following code snippet?
gist=”Old is Gold”
X=gist.partition(“s”)
print(X[-1:-3])
a. () b. (' Gold') c. (' Gold', 'is') d. None of the above
16. What will be the output of the following code?
MainList = ["One", ["2", "3"], "4"]
CheckList = [ MainList[1] ]
print(CheckList)
a. [“2”] b. [“2”, ”3”] c. [ [“2”,”3”] ] d. Syntax Error
17. If “dict” is a dictionary as defined below, then which of the following
statements will raise an exception?
dict = {'Rose': 10, 'Lily': 20, 'Sunflower': 30}
a. dict.get('Sunflower') b. print(dict['Rose', 'Lily']) c. dict['Rose']=40 d. print(str(dict))
18. Identify the invalid python statement from the following:
a. t=(100) b. t=tuple() c. t=(100,) d. None of the above
19. Write the output:-
myTuple =("Ajay", "Siva", "Vicky")
x = "#".join(myTuple)
print(x)
a. #Ajay#Siva#Vicky b. Ajay#Siva#Vicky
c. Ajay#Siva#Vicky# d. #Ajay#Siva#Vicky#

3
20. What will be the output of the following code snippet?
message= "Tea City"
print(message[-1::-1])
21. What will be the output of the following code?
tuple1 = (1, 2, 4, 3)
tuple2 = (1, 2, 3, 4)
print(tuple1 < tuple2)
a. True b. False c. tuple1 d. Error
22. What does the list.pop(a) method do in Python?
a. Deletes the element at index a from the list
b. Deletes the first occurrence of value a from the list
c. Deletes all occurrences of value a from the list
d. Deletes the last occurrence of value a from the list
23. If one_dict is a dictionary as defined below, then which of the following statements
will raise an exception , one_dict = {'shoes': 1000, 'bag': 1200, 'specs': 500}
a. one_dict.get('specs') b. print(one_dict['shooes'])
c. k=one_dict.keys() d. print(str(one_dict))
24. Predict the output of the following code snippet
Marks = { ‘Manoj’: 92, ‘Suresh’: 79, ‘Vaibhav’:88 }
print ( list( marks.keys( ) ) )
a. ‘Manoj’ , ’Suresh’, ‘Vaibhav’ b. 92, 79, 88
c. [‘Manoj’, ‘Suresh’, ‘Vaibhav’] d. (‘Manoj’, ‘Suresh’, ‘Vaibhav’)
25. Find the output of the following code snippet
S=9, (2, 13, 8), 5, (1, 6)
print ( len (S) )
a. 4 b. 7 c. 6 d. Error
26. Which of the following operations on a string will generate an error?
a. ‘python’ * 2 b. ‘python’ + 2 c. ‘python’ + ’2’ d. ‘python’ + ’python’

4
27. Identify the invalid statement for list L= [1,2,3,4]
a. L.remove(3) b. L.pop(3) c. L.del(3) d. del L[3]
28. What will be the output of the following Python statements?
D={‘BHUSHAN’:90, ‘SAKSHI’:96,’RANJIT’:85}
print(‘RANJIT’ in D, 96 in D, sep=’@’)
a. True@True b. False@True c. True@False d. False@False
29. What will be the output of the following code?
s = [3,0,[2,1,2,3],1]
print(s[s[len(s[2])-2][1]])
a.0 b. 1 c. [2,1,2,3] d. 2
30. Which of the following statement(s) will raise an exception?
Sales = {"Printer":25000,"Mouse":750 } # Statement 1
print (Sales[750]) # Statement 2
Sales ["Printer"]=12500 # Statement 3
print (Sales.pop()) # Statement 4
print (Sales) # Statement 5
a. Statement 2 b. Statement 3 c. Statement 4 d. Statements 2 and 4
31. Which of the following will delete key-value pair for key = “Red” from a dictionary
COLOR?
a. delete COLOR("Red") b. del COLOR["Red"]
c. del.COLOR["Red"] d. COLOR.del["Red"]
32. What will be the output of the following code?
L1 = [1, 2, 3]
L2 = L1
L1 += [4,]
print(L1 = = L2)
a. True b. False c. tuple1 d. Error

5
33. What will the following code do?
dict={“Phy”:94,”Che”:70,”Bio”:82,”Eng”:95}
dict.update({“Che”:72,”Bio”:80})
a. It will create new dictionary as dict={“Che”:72,”Bio”:80} and old dict will be deleted
b. It will throw an error as dictionary cannot be updated
c. It will simply update the dictionary as dict={“Phy”:94,”Che”:72,”Bio”:80,“Eng”:95}
d. It will not throw any error but it will not do any changes in dict
34. What will be the output of the following list operations?
data = [[5,10,15],20,[40,50],50]
print(data[0]+data[-2])
print(data[2][-1])
35. What will be correct output for the following?
R = (4.5, 5), (5,4), (8.2,7), (8,7,3)
print(max(R))
a. Error b. (8.2, 7) c. (8, 7, 3) d. (4.5, 5, 8.2, 8)
36. Select the correct output of the following code:
S = "Motivational thought"
print(S.find("hou", 4, 13))
a. True b. 4 c. 14 d. -1
37. If farm is a t as defined below, then which of the following will cause an exception?
farm={‘goat’:5,’sheep’:35,’hen’:10,’pig’:7}
a. print(str(farm)) b. print(farm[‘sheep’,’hen’])
c. print(farm.get(‘goat)) d. farm[‘pig’]=17
38. Find out the correct answer.
str="R and Data Science"
z=str.split()
newstr="=".join([z[2].upper(),z[3],z[2]+z[3],z[1].capitalize()])
newstr is equal to

6
a. 'DATA=Science=DataScience=And' b. 'DATA=DataScience=And'
c. 'DATA=Science=And' d. 'DATA=Science==DataScience=And'
39. What will be the output of the following code?
tuple1 = (1, 2, 3)
tuple2 = tuple1 + (4,)
tuple1 += (5,)
print(tuple1, tuple2)
a. (1, 2, 3) (1, 2, 3, 4) b. (1, 2, 3, 5) (1, 2, 3) c. (1, 2, 3, 5) (1, 2, 3, 4) d. Error
40. Identify the output of the following code snippet:
str = "KENDRIYA VIDYALAYA"
str=str.replace('YA','*')
print(str)
a. KENDRIYA VIDYALAYA b. KENDRI*A VID*ALAYA
c. KENDRI* VID*LA* d. * KENDRI* VID*LA*
41. State the correct output of the following code-
S1= “India is on the Moon”
A=S1.split("o",3)
print(A)
a. ['India is ', 'n the M', ' ', 'n'] b. 'India is ', 'n the M', ' ', 'n'
c. ['India is n ', 'the ', ' ', 'Mn'] d. [„India is‟, „the‟, „n‟]
42. State the correct output of the following code-
str1=" Programming "
str2=" is My Junoon"
str3=str1.strip()+str2.replace("J", "j").lstrip()
print(str3.partition("My"))
a. ('Programmingis ', 'My', ' junoon') b. ['Programmingis ', 'My', ' junoon']
c. ['Programming is ', 'My', ' Junoon'] d. (('Programmingis ', 'My', ' Junoon')

7
43. What does this statement will do in python?
>>>L1=[10,20,30] # Statement 1
>>>L1.insert(-3,1) # Statement 2
>>>print(L1) # Statement 3
a. The statement 2 will insert the element -3 at index 1
b. The statement 2 will insert the element 1 at index -3
c. The statement 2 will insert the element 1 after the value 10
d. The statement 2 will insert the element -3 after the value 30
44. Which of the following statement is False?
a. list.pop() removes the last element of a list.
b. list.remove(x) removes the element x from a list.
c. list.extend(l2) adds all the elements of list l2 to a list.
d. list.sort() sorts all the elements of the list.
45. Find the output of the following code-
msg=“ this is wonderful”
L=msg.index(‘is’)
print(L)
a. 1 b. 2 c. 3 d. 4
State True or False:
46. As a Dictionary is mutable, both Key & Value are also mutable.
Assertion and Reasoning
47. Assertion(A):A tuple can be concatenated to a list,but a list cannot be concatenated to
a tuple.
Reason(R): Lists are mutable and tuples are immutable in Python.
48. Assertion(A): List is an immutable data type .
Reasoning(R): When an attempt is made to update the value of an immutable variable,
the old variable is destroyed and a new variable iscreated by the same name in memory.

8
49. What will be the output of following code if a = “abcde”
a [1:1 ] == a [1:2]
type (a[1:1]) == type (a[1:2])
50. Identify the output of the following python code:
D={1:”one”,2:”two”, 3:”three”}
L=[]
for k,v in D.items():
if ‘o’ in v:
L.append(k)
print(L)
(a) [1,2] (b) [1,3] (c)[2,3] (d)[3,1]

You might also like