WORKSHEET for PYTHON_CLASS 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

PYTHON REVISION TOUR 1 AND 2 (CLASS XI)

1. State True or False: “In a Python loops can also have else clause”
Ans. True

2. What is the output of the following code?

Ans. (A)hAPPY#HOUR1122#33

3. Consider the given expression:


17%5==2 and 4%2>0 or 15//2==7.5
Which of the following will be correct output if the given expression is evaluated?
(a)True (b) False (c)None (d)Null
Ans. (b) False

4. Select the correct output of the code:


s = "Question paper 2022-23"
s= s.split('2')
print(s)
a. ['Question paper ', '0', '', '-', '3']
b. ('Question paper ', '0', '', '-', '3')
c. ['Question paper ', '0', '2', '', '-', '3']
d. ('Question paper ', '0', '2', '', '-', '3')
Ans. (a)['Question paper ', '0', '', '-', '3']

Page 1 of 24
5. 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])
Ans. True

6. Select the correct output of the code:


a = "foobar"
a = a.partition("o")
print(a)
(a) ["fo","","bar"]
(b) ["f","oo","bar"]
(c) ["f","o","bar"]
(d) ("f","o","obar")
Ans. (d) ("f","o","obar")

7.

Ans. (a)[1,2]

8. Which of the following is not a tuple in python?


(a) (10,20) (b) (10,) (c) (10) (d) All are tuples.
Ans. (c ) (10)

9. What will be the output of the following Python code snippet?


d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a. True b. False
c. Error d. None
Ans b. Error

Page 2 of 24
10. Write difference between mutable and immutable property, Explain it with its
example.
Ans. Mutable: Can be changed (e.g., lists, dictionary).
Immutable: Cannot be changed (e.g., tuples, string).

11.

Ans. (18, 36, 54)

12. Write the Python statement for each of the following tasks using BUILT-IN
functions/methods only:
(i) To insert an element 400 at the fourth position, in the list L1.
(ii) To check whether a string named, message ends with a full stop/ period or
not.

Ans.
(i) L1.insert(3,400)
(ii) message.endswith('.')

13. State True or False


“continue keyword skips remaining part of an iteration in a loop”
Ans. True

14. Select the correct output of the code:


>>> St=”Computer”
>>> print(St[4:])
(a) “Comp” (b) “pmoC” (c) “uter” (d) “mput”
Ans. (c) “uter”,

Page 3 of 24
15. print(True or not True and False)
Choose one option from the following that will be the correct output after
executing the above python expression.
a) False b) True c) or d) not
Ans: (b) True, as firstly “not” performed then “And” performed and at last “Or”
performed.
True or not True and False
True or False and False
True or False
True

16. Given the following dictionaries


dict_stud = {"rno" : "53", "name" : ‘Rajveer Singh’} dict_mark = {"Accts" : 87,
"English" : 65}
Which statement will merge the contents of both dictionaries?
(a) dict_stud + dict_mark (b) dict_stud.add(dict_mark)
(c) dict_stud.merge(dict_mark) (d) dict_stud.update(dict_mark)
Ans. (d) dict_student.update(dict_marks)

17. Consider a declaration L=(1,’Python’,’3.14’)


Which of the following represents the data type of L?
(a) list (b) tuple (c) dictionary (d) string
Ans. (b) tuple,

18. Given a tuple tupl=(10,20,30,40,50,60,70,80,90)


What will be the output of print (tupl[3:7:2])?
(a) (40,50,60,70,80) (b) (40,50,60,70) (c) [40,60] (d) (40,60)
Ans: (d) (40,60)

19. What will the following expression be evaluated to in Python?


print(2**3**2)
a) 64 b) 256 c) 512 d) 32
Ans. (c) 512,

20. Which of the following statement(s) would give an error after executing the
following code?
S="Welcome to class XII" #Statement 1
print(S) # Statement 2
S="Thank you" #Statement 3
S[0]= '@' #Statement 4
S=S+"Thank you" #Statement 5

Page 4 of 24
(a) Statement 3 (b) Statement 4
(b) Statement 5 (d) Statement 4 and 5
Ans. (b) Statement 4,
as string’s individual element can’t assigned new value so S[0]= '@' # Statement
4 give error.

21. Which of the following can be used as valid identifier(s) in Python?


(i) Total (ii) @selute (iii) Que$tion (iv) great
(v) 4th Sem (vi) li1 (vii) No# (viii) _Data
Ans. Valid identifier(s)
(i)Total (iv) great (vi) li1 (viii) _Data

22. (i)Write the names of any two data types available in python.
(ii)Write any 2 operators name used in python.
Ans. i) Names of any two data types available in python: int, float or any other
valid datatype in python.
ii) Any 2 operators name used in python: Arithmetic, Logical, Relational or any other
valid operator in python.

23. Write the Python statement for each of the following tasks using BUILT_IN functions/
methods only:
i) str="PYTHON@LANGUAGE"
(A) To print the above string from index 2 onwards.
(B) To initialize an empty dictionary named as d.

Ans.
(i) A) str="PYTHON@LANGUAGE"
print(str[2: : ])

B) d=dict( )

ii) Write the Python statement for each of the following tasks using BUILT_IN
functions/ methods only:
(A) s=”LANGUAGE"
To convert the above string into list.
(B) To initialize an empty tuple named as t.

Ans.
(ii) A) s=”LANGUAGE"
l=list(s)

B) t=tuple( )

Page 5 of 24
24. State True or False:
The keys of a dictionary must be of immutable types.
Ans. True

25. 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*
Ans. (c) KENDRI* VID*LA*

26. What will be the output of following expression?


(5<10 ) and (10< 5) or (3<18) and not 8<18
(a) True (b) False (c) Error (d) No output
Ans. (b) False

27. What is the output of the expression?


St1=”abc@pink@city”
print(St1.split("@"))
(a) (“abc”, “@”, “pink”, “@”, “city”) (b) [“abc”, “@”, “pink”,”@’,”city”]
(c) [“abc”, “pink”, “city”] (d) Error
Ans. (c) [“abc”, “pink”, “city”]

28. What will be the output of the following code snippet?


message= "Satyamev Jayate"
print(message[-2::-2])
Ans. tyJvmya

29. Which of the following options will not result in an error when performed on types in
python where tp = (5,2,7,0,3) ?
(a) Tp[1] = 2 (b) tp.append(2)
(c) tp1 = tp+tp (d) tp.sum( )
Ans. (c) tp1 = tp+tp

30. If my_dict is a dictionary as defined below, then which of the following statements
will raise an exception?
my_dict = {'aman': 10, 'sumit': 20, 'suresh': 30}
(a) my_dict.get('suresh') (b) print(my_dict['aman', 'sumit'])
(c) my_dict['aman']=20 (d) print(str(my_dict))

Page 6 of 24
Ans. (b) print(my_dict['aman', 'sumit'])

31. Which of the following can delete an element from a list if the index of the element
is given?
(a) pop( ) (b) remove( )
(c) clear( ) (d) all of these
Ans. (a) pop( )

32. What are immutable and mutable types? List immutable and mutable types of
python.
Ans. Immutable types are those that can never change their value in place.
These are : integers, float, string, tuple
Mutable types are those whose values can be changed in place. These are : lists,
dictionaries

33. If given A=2,B=1,C=3, What will be the output of following expressions:


(i) print((A>B) and (B>C) or(C>A))
(ii) print(A**B**C)
Ans. (i) True
(ii) 2

34. Write the most appropriate list method to perform the following tasks.
(I) A) To delete a given element from the list L1.
B) To sort the elements of list L1 in ascending order.
Ans.
(I) A) L1.remove(4)
B) L1.sort( )

(II) A) To add an element in the beginning of the list L1.


B) To add elements of a list L2 in the end of a list L1.
Ans.
(II) A) L1.insert( )
B) L1.extend(L2)

35. Rewrite the following code in Python after removing all syntax error(s). Underline
each correction done in the code.
p=30
for c in range(0,p)
If c%4==0:
print (c*4)
Elseif c%5==0:
print (c+3)
else
print(c+10)

Page 7 of 24
Ans.
p=30
for c in range(0,p):
if c%4==0:
print (c*4)
elif c%5==0:
print (c+3)
else:
print(c+10)

36. Predict the output of the Python code given below:


T= [“20”, “50”, “30”, “40”]
Counter=3
Total= 0
for I in [7,5,4,6]:
newT=T[Counter]
Total= float (newT) + I
print(Total)
Counter=Counter-1
Ans.
47.0
35.0
54.0
26.0
37. State True or False:
The Python statement print(‘Alpha’+1) is example of TypeError Error
Ans : True
38. What id the output of following code snippet?
country = "GlobalNetwork"
result = "-".join(country.split("o")).upper()
print(result)
(A) GL-BALNETW-RK
(B) GL-BA-LNET-W-RK
(C) GL-BA-LNET-W-RK
(D) GL-BA-LNETWORK
Ans : A ) GL-BALNETW-RK
39. Identify the output of the following code snippet:
text = "The_quick_brown_fox"
index = text.find("quick")
result = text[:index].replace("_", "") + text[index:].upper()
print(result)
(A) Thequick_brown_fox (B) TheQUICK_BROWN_FOX
(C) TheQUICKBROWNFOX (D) TheQUICKBROWN_FOX

Ans. (B) TheQUICK_BROWN_FOX

Page 8 of 24
40. What will be the output of the following Python expression? x = 5
y = 10
result = (x ** 2 + y) // x * y - x
print(result)
(A) 0
(B) -5
(C) 65
(D) 265

Ans : ( C ) 65

41. What will be the output of the following code snippet? text = "Python Programming"
print(text[1 : :3])
(A) Ph oai (B) yoPgmn (C) yhnPormig (D) Pto rgamn
Ans : (B)

42. 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

Ans : C )

43. Dictionary my_dict as defined below, identify type of error raised by statement
my_dict['grape']?
my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
ValueError (B) TypeError (C) KeyError (D) ValueError
Ans : (C) KeyError

44. What does the list.pop(x) method do in Python?


A. Removes the first element from the list.
B. Removes the element at index x from the list and returns it.
C. Adds a new element at index x in the list.
D. Replaces the element at index x with None.
Ans : B. Removes the element at index x from the list and returns it.

45. Consider the following Python code snippet:


a = [1, 2, 3]
b=a
a.append(4)
c = (5, 6, 7)
d = c + (8,)
a. Explain the mutability of a and c in the context of this code.
b. What will be the values of b and d after the code is executed?

Page 9 of 24
Ans : a) a is a mutable object (a list), meaning its contents can be changed
after it is created. This is demonstrated by the append() method that adds an
element to the list.
c is an immutable object (a tuple). Once created, its contents cannot be changed.
The operation c + (8,) does not modify c but creates a new tuple.

b) The value of b will be [1, 2, 3, 4], as b references the same list as a, which was
modified by appending 4.
The value of d will be (5, 6, 7, 8), as the expression c + (8,) creates a new tuple
combining c and (8,).

46. Give examples for each of the following types of operators in Python:
(I) Assignment Operators
(II) Identity Operators
Ans :
(I) Assignment Operators:
1. Example 1: = (Simple Assignment) Usage: x = 5 (assigns the value 5 to x)
2. Example 2: += (Add and Assign) : Usage: x += 3 (equivalent to x = x + 3)

(II) Identity Operators:


1. Example 1: is , Usage: x is y (checks if x and y refer to the same object)
2. Example 2: is not : Usage: x is not y (checks if x and y do not refer to the same
object)

47. If L1 = [10, 20, 30, 40, 20, 10, ...] and L2 = [5, 15, 25, ...], then:
(Answer using builtin functions only)
(I) A) Write a statement to count the occurrences of 20 in L1. OR B) Write a
statement to find the minimum value in L1.
(II) A) Write a statement to extend L1 with all elements from L2. OR B) Write a
statement to get a new list that contains the unique elements from L1.

Ans : I ( A) : count_20 = L1.count(20)


(B) : min_value = min(L1)

II (A) : L1.extend(L2)
(B) : unique_elements = list(set(L1))

48. Predict the output of the following code:


data = [3, 5, 7, 2]
result = ""
for num in data:
for i in range(num):
result += str(i) + "*"
result = result[:-1]
print(result)

Ans. 0*1*2*0*1*2*3*4*0*1*2*3*4*5*6*0*1

Page 10 of 24
49. Predict the output of the following code:
numbers = [10, 15, 20]
for num in numbers:
for j in range(num // 5):
print(j, "+", end="")
print()
Ans.
0 +1 +
0 +1 +2 +
0 +1 +2 +3 +

50. State True or False


In Python, a dictionary is an ordered collection of items(key:value pairs).
Ans. False

51.

Ans. iv) [2,14,3,7]

52. The following expression will evaluate to


print(2+(3%5)**1**2/5+2)
i) 5
ii) 4.6
iii) 5.8
iv) 4
Ans. ii) 4.6

53. What is the output of the expression?


food=’Chinese Continental’
print(food.split(‘C’))
i. ('', 'hinese ', 'ontinental')
ii. ['', 'hinese ', 'ontinental']
iii. ('hinese ', 'ontinental')
iv. ['hinese ', 'ontinental']
Ans. ii) ['', 'hinese ', 'ontinental']

Page 11 of 24
54. What will be output of the following code snippet?
Msg=’Wings of Fire!’
print (Msg[-10: :2])
Ans. so ie

55. 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}
i) print(str(farm))
ii) print(farm[‘sheep’,’hen’])
iii) print(farm.get(‘goat))
iv)farm[‘pig’]=17
Ans. ii) print(farm[‘sheep’,’hen’])

56. Differentiate list and tuple with respect to mutability. Give suitable example to
illustrate the same .
Ans. List is Mutable and Tuple is not (Cannot update an element, insert and delete
elements)
# code to test that lists are mutable
List = [1, 2, 4, 4, 3, 3, 3, 6, 5]
print("Original list ", List)
List[3] = 77
print("Example to show mutability ", List)

Output:
Original list [1, 2, 4, 4, 3, 3, 3, 6, 5]
Example to show mutability [1, 2, 4, 77, 3, 3, 3, 6, 5]

# code to test that tuples are immutable


tuple1 = (0, 1, 2, 3)
tuple1[0] = 4
print(tuple1)

Output:
TypeError: 'tuple' object does not support item assignment

57. Give two examples of each of the following


a) Assignment operators b) Logical operators
Ans.
a) Assignment Operators: =, +=, -=, *=, **=, /=, //=, %=
b) Logical Operators: not, and, or

Page 12 of 24
58. If L1 = [13,25,41,25,63,25,18,78] and L2= [58,56,25,74,56]
(i) A) Write a statement to remove fourth element from L1
B) Write the statement to find maximum element in L2
Ans.
(i) A) L1.pop(4)
B) print(max(L2)

(ii) (A) write a statement to insert L2 as the last element of L1


(B) Write a statement to insert 15 as second element in L2
Ans. (ii) (A) L1.append(L2)
(B) L2.insert(1,15)

59. Predict the output


Con1="SILENCE-HOPE-SUCCEss@25"
Con2=""
i=0
while i<len(Con1):
if Con1[i]>='0' and Con1[i]<='9':
Num=int(Con1[i])
Num-=1
Con2=Con2+str(Num)
elif Con1[i]>='A' and Con1[i]<='Z':
Con2=Con2+Con1[i+1]
else:
Con2=Con2+'^'
i+=1
print(Con2)
Ans.
ILENCE-^OPE-^UCCEs^^^14

60. State-True or false:


Python interpreter handles semantic errors during code execution.
Ans. False

61. Which of the following will return False:


A) not (True and False) B) True or False
C) not (True or False) D) not (False and False)
Ans. C) not (True or False)

62. Which of the following function will help in converting a string to list with elements
separated according to delimiter passed?
A) list( ) B) split( ) C) str( ) D) shufle( )
Ans. B) split()

Page 13 of 24
63. What is the output of the following?
OCEANS=('pacific','arctic','Atlantic','southern')
print(OCEANS[4])
A) ‘southern’ B) (‘southern’) C) Error D) INDEX
Ans. C) error

64. What is the output of the following


x="Excellent day"
print(x[1::3])
A) x B) xlnd C) error D) dnlx
Ans. B) xlnd

65. If D={‘Mobile’:10000, ‘Computer’:30000, ‘Laptop’:75000} then which of the following


command will give output as 30000
A) print(D) B) print(D['Computer'])
C) print(D.values( )) D)print(D.keys( ))
Ans. B) print(D['Computer'])

66. Which of the following is not correct?


(A) del deletes the list or tuple from the memory
(B) remove deletes the list or tuple from the memory
(C) pop is used to delete an element at a certain position
(D) pop(<index>) and remove(<element>) performs the same operation

Ans. B) remove deletes the list or tuple from the memory

67. a) Explain dictionary with example?


b) What is the data type of (i) x=10 (ii) x=10,20
Ans. a) Dictionary: A dictionary is a collection of data that stores information in
key-value pairs.
E.g. d = {1: 'Geeks', 2: 'For', 3: 'Geeks'}
print(d)

output ->
{1: 'Geeks', 2: 'For', 3: 'Geeks'}

b) (i) x=10 -> integer (ii) x=10,20 -> tuple

68. Explain ‘in’ operator and write a small code in Python to show the use of ‘in’
operator.
Ans. The in operator returns True if the specified value or object is found in the
sequence and False otherwise.

Page 14 of 24
Eg.
A="welcome"
print('e' in A)
print('z' in A)
output ->
True
False

69. Consider T=(10,20,30) and L=[60,50,40] answer the question I and II


(I) Write command(s) to add tuple T in list L.
Ans. L.append(T)

(II) Write command to find and delete element 20 from tuple T


As T is tuple deletion of an element is tuple is not possible due to its immutable
nature.(any relevant correct reason)

(III) Write command to add 50 in L at position 2.


Ans. L.insert(50,2)

(IV) Write command to delete the variable T.


Ans. del T

70. Predict the output of the following code:


d={}
V="programs"
for x in V:
if x in d.keys():
d[x]=d[x]+1
else:
d[x]=1
print(d)
Ans.
{'p': 1, 'r': 2, 'o': 1, 'g': 1, 'a': 1, 'm': 1, 's': 1}

71. Predict the output of the following code:


V="interpreter"
L=list(V)
L1=""
for x in L:
if x in ['e','r']:
L1=L1+x
print(L1)
Ans. erreer

72. State True or False:


“In a Python program, if a break statement is given in a nested loop, it terminates the
Page 15 of 24
execution of all loops in one go.”
Ans. False

73. Identify the output of the following code snippet:


T=(100)
print(T*2)
(A) Syntax error
(B) (200,)
(C) 200
(D) (100,100)
Ans. (c ) 200

74. Given s1=“Hello”. Which of the following statements will give an error?
(A) print(s1[4])
(B) s2=s1
(C) s1=s1[4]
(D) s1[4]= “Y”
Ans. (D) s1[4]= “Y”

75. Write the output of following expression:


5>10 and not(10<15)
Ans. False

76. What is the output of the expression?

s='All the Best'


p=s.split("t")
print(p)
(A) ['All ', 'he Bes', '']
(B) (‘All ', 'he Bes', '')
(C) ['All ', 't', 'he', 'Bes', 't']
(D) Error
Ans. (A) ['All ', 'he Bes', '']

77. Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (tup1 [-2: -5])?
(A) (80,70,60)
(B) ( )
(C) (60,70,80)
(D) Error
Ans. (B) ( )

78. What will be the output of the following python dictionary operation?
data = {'A':2000, 'B':2500, 'C':3000, 'A':4000}
Page 16 of 24
print(data)
(A) {'A':2000, 'B':2500, 'C':3000, 'A':4000}
(B) {'A':2000, 'B':2500, 'C':3000}
(C) {'A':4000, 'B':2500, 'C':3000}
(D) It will generate an error.
Ans. (C) {'A':4000, 'B':2500, 'C':3000}
79. _______ method is used to delete a given element from the list.
Ans. remove()

80. Predict the output of the Python code given below:


List1 = list("Examination")
List2 =List1[1:-1]
New_list = []
for i in List2:
j=List2.index(i)
if j%2==0:
List1.remove(i)
print(List1)
Ans. ['E', 'a', 'i', 'a', 'i', 'n']

81. Difference between compile time and run time error.

82. (A)Given is a Python string declaration:


myexam="@@PRE BOARD EXAMINATION 2024@@"
Write the output of: print(myexam[::-2])
Ans. @40 OTNMX RO R@

OR
(B)Write the output of the code given below:
my_dict = {"name": "Aman", "age": 26}
my_dict['age'] = 27
my_dict['address'] = "Delhi"
print(my_dict.items())
Ans. dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')])

83.

Ans True

84.

Page 17 of 24
Ans. a) True, Fals0065

85.

Ans. a) True

86.

Ans. a) 19

87.

Ans. a) Welc. me t.rld

88.

Ans. b) del D1["Red"]

Page 18 of 24
89.

Ans. c) Statement 4

90.

Ans. b) Day.pop(2)

91.

Ans. b) length()

92.

Ans. b) len()

93.

Page 19 of 24
Ans. Mutable-> [1,2]
{1:1,2:2}

Immutable ->
(1,2)
‘123’

94.

Ans.
(i) L1.insert(2,200)
(ii) message.endswith('.')
OR
import statistics
print( statistics.mode(studentAge) )

95.

Ans. membership - the operator that checks the presence of an item in a variable.
E.g. in, not in
identity - the operator that checks if the memory location of two objects are equal.
E.g. is, is not

96.

Page 20 of 24
Ans. Error

97.

Ans. False

98.

Ans. ext#nex
99.

Ans. (C) -6.0

100.

Page 21 of 24
Ans. (C) L * [2]

101.

Ans. (C) puC dlroW

102.

Ans. (C) sub[0]= “ip”

103.

Page 22 of 24
Ans. (B) print(my_dict['apple', 'banana'])

104.

Ans. (A) (i)//


(B) (i) Keyword (ii) Variable

105.

Ans. (A) list


(B) (i) Day={1:’monday’,2:’tuesday’,3:’wednesday’}

Page 23 of 24
106.

Ans. (i) (A) Lsort() (B) min(L)


(ii) (A) L.append(“Apr”) (B) L.index(“Feb”)

Page 24 of 24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy