WORKSHEET for PYTHON_CLASS 11
WORKSHEET for PYTHON_CLASS 11
WORKSHEET for PYTHON_CLASS 11
1. State True or False: “In a Python loops can also have else clause”
Ans. True
Ans. (A)hAPPY#HOUR1122#33
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
7.
Ans. (a)[1,2]
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.
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('.')
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
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.
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
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
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( )
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)
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)
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
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)
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.
II (A) : L1.extend(L2)
(B) : unique_elements = list(set(L1))
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 +
51.
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]
Output:
TypeError: 'tuple' object does not support item assignment
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)
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
output ->
{1: 'Geeks', 2: 'For', 3: 'Geeks'}
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
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”
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()
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.
88.
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.
100.
Page 21 of 24
Ans. (C) L * [2]
101.
102.
103.
Page 22 of 24
Ans. (B) print(my_dict['apple', 'banana'])
104.
105.
Page 23 of 24
106.
Page 24 of 24