Tuples Exam Questions Class 11 Computer Science

Exam Questions Class 11

Please see Chapter 8 Tuples Exam Questions Class 11 Computer Science below. These important questions with solutions have been prepared based on the latest examination guidelines and syllabus issued by CBSE, NCERT, and KVS. We have provided Class 11 Computer Science Questions and answers for all chapters in your NCERT Book for Class 11 Computer Science. These solved problems for Tuples in Class 11 Computer Science will help you to score more marks in upcoming examinations.

Exam Questions Chapter 8 Tuples Class 11 Computer Science

Short Answer Type Questions

Question: Explain the mixed data types tuple with an example.
Answer: Mixed data types can be created to place different data types such as integers, strings, double etc into one tuple. For example,tuple1=(‘English’, 90, ‘Rahul’,‘Meerut’, ‘99.5’)

Question: Distinguish between tuple and list.
Answer: Differences between tuple and list are as follows

Question: What is the output of following code?
t1=(1, 2, 3, 4, 5)
print(“Tuple is :”, t1)
del(t1)
print(“Tuple after deleting”)
print(t1)
Answer: Output
Tuple is : (1, 2, 3, 4, 5)
Tuple after deleting
Trackback (most recent call last) :
File “<pyshell#6>”, line 1, in <module>
print(t1)
NameError: name ‘t1’ is not defined

Question: Explain sum() method of tuple with an example.
Answer: sum() method is used to calculate the sum of elements of tuple. The elements of tuple must be integer.
Syntax sum(tuple_name)
For example,
>>>price=(100, 150, 95, 120, 80)
>>>sum(price)
Output
545

Question: Write a Python program to find maximum and minimum elements in a tuple.
Answer: tuple1=(23,45,−65,−45,20,45,65,− 24)
print(“The tuple is:”,tuple1)
min1=tuple1.index (min(tuple1))
max1=tuple1.index (max(tuple1))
print(“Maximumelement in the tuple is :”,max(tuple1),“ at
index number ”,max1)
print(“Minimumelement in the tuple is :”,min(tuple1),“ at
index number ”,min1)

Question: Observe the following tuples and answer the questions that follow.
t1=(4, 7, 8, 9)
t2=(0, 4, 3)
(i) >>>t=t1+t2
>>>print(t)
(ii) >>>t=t1*t2
>>>print(t)
Answer: (i) (4, 7, 8, 9, 0, 4, 3)
(ii) It gives TypeError because cannot multiply sequence by non-int of type ‘tuple’.

Question: Observe the following tuple and answer the questions that follow.
t1=(76, 56, ‘Harish’, ‘Ansh’, 98, (45, 34), ‘Muskan’)
(i) len(t1) (ii) t1[−6]
(iii) t1[3] (iv) t1[: 2]
Answer: (i) 7
(ii) 56
(iii) ‘Ansh’
(iv) (76, 56)

Question: Find the output of the given questions
t=(45, 76, 23, ‘The’, 89, (‘This’, 56), (23, ‘That’),34)
(i) (t[4])
(ii) t[2:10:3]
(iii) t[2] + t [–1]
Answer: (i) 89
(ii) (23,(‘This’, 56))
(iii) 57

Question: What do you mean by membership operators in Python?
Answer: Membership operators are used to check whether a value/variable exists in the sequence like string, list, tuple etc. These operators return True or False as per conditions met.
Membership operators are of two types as:
(i) in operator
(ii) not in operator

Question: Find the output of following code?
t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’)
for i in range (len(t)):
print (t[i])
Answer: Output
A
R
I
H
A
N
T

Question: What will be the output of following code?
tuple1=(1,2,3,4,5)
tuple2=(6,7,8,9)
for item in tuple1:
if item in tuple2:
print(“overlapping”)
else:
print(“not overlapping”)
Answer: Output not overlapping

Question: Prove with the help of an example that the variable is rebuilt in case of immutable data types. 
Answer: When a variable is assigned to the immutable data type, the value of the variable cannot be changed in place.
Therefore, if we assign any other value of the variable, the interpreter creates a new memory location for that value and then points the variable to the new memory location. This is the same process in which we create a new variable. Thus, it can be said that the variable is rebuilt in case of immutable data types on every assignment.
Program to represent the same:
v = 20
print(“Before: ”,id(v))
v = 21
print(“After: ”,id(v))
Output
Before: 140705582623120
After: 140705582623152
It can be seen that the memory location a variable is pointing after the assignment is different. The variable is entirely new and it can be said that the variable is rebuilt. 

Question: Explain tuple slicing syntax with its parameters.
Answer: Syntax t=tuple_name[start : stop : step] Here,
♦ start integer where the slicing of the object starts.
♦  stop integer until which the slicing takes place. The slicing stops at index stop−1.
♦  step integer value which determines the increment between each index for slicing.

Question: What will be the output of following code?
x=44
y=30
tuple=(45, 65, 30, 78, 512)
if(x not in tuple):
print(“x is NOT present in given tuple”)
else :
print (“x is present in given tuple”) 
if(y in tuple):
print(“y is present in given tuple”)
else:
print(“y is NOT present in given tuple”)
Answer: x is NOT present in given tuple y is present in given tuple

Question: Find and write the output of the following Python code.
t=(4, (8, 0, 7))
t1=(4, 7, (2, 8))
print(t.count(0))
print(t[1][2])
print(t*2)
print(len(t1))
print(t1[2])
print(t+t1)
Answer: Output
0
7
(4, (8, 0, 7), 4, (8, 0, 7))
3
(2, 8)
(4, (8, 0, 7), 4, 7, (2, 8))

Question: Write a Python code to remove an element ‘2’ from the following tuple.
tuple1 = (2, 5, 6, 9, 4)
Answer: tuple1 = (2, 5, 6, 9, 4)
list1 = list (tuple1)
list1. remove (2)
tuple1 = tuple (list1)
print (tuple1)

Question: TypeError occurs while statement 2 is running.
Give reason. How can it be corrected?
>>> tuple1 = (5) #statement 1
>>> len(tuple1) #statement 2
Answer: The ‘statement 1’ is creating a variable, tuple1 which is of ‘int’ data type. The ‘statement 2’ is checking for the length of the variable, but the argument passed is an ‘int’ data type.
The len() function can return the length only when the object is a sequence or a collection. This is the reason for the type error.
The error can be corrected by adding one comma after ‘5’ in statement 1, as this will create a tuple and as a tuple is a collection, len() function will not return an error.
The correct statement will be
>>> tuple1 = (5,)
>>> len(tuple1)

Question: Write a Python code to display all the elements of the following tuple except ‘H’.
t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’)
Answer: t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’)
t = t[0 : 3] + t[−3 : ]
print (t)
Output
(‘A’, ‘R’, ‘I’, ‘A’, ‘N’, ‘T’)

Question: Identify the error, if any in the following code.
t1=(2, 3, 4, ‘Hello’, 6,9)
print (min(t1))
Answer: min() function is used in tuple to return with minimum value out of elements in tuple.
Given code has an error because min() will work only if elements in a tuple are of same data type, i.e. (2, 3, 4, 7, 6, 9).

Long Answer Type Questions

Question: Answer the following questions;
(i) t1=(25,78, (45, (65,89)),90, (34,8)) len(t1)
(ii) t2=(45,(‘The’,78,(‘This’),67),‘The’,67,67) 
t2.count(67)
(iii) t1=(3,)
t2=()
t=t1+t2
any(t)
(iv) t3=(87,89,56,99,75,45,100)
max(t3)
Answer: (i) 5 (ii) 2 (iii) True (iv) 100

Question: Write the short note on following terms.
(i) Tuple
(ii) in operator
(iii) Equal to (= =) operator
(iv) Packing
Answer: (i) Tuple is a collection of Python objects separated by
commas (,) and put the elements in parentheses ( ).
(ii) in operator is used to check, if a value exists in a sequence.
(iii) Equal to (= =) operator returns True if the values on either side of the operator are equal.
(iv) Tuples put all the elements or values together in a parentheses, is called packing.

Question: Write a Python program to find the common elements in two tuples.
Answer: tuple1=(45,87,56,−78,36,−12)
tuple2=(65,32,45,−78,36,−75)
a_set=set(tuple1)
b_set=set(tuple2)
if (a_set & b_set):
print(“Common elements are:”,a_set &
b_set)
else:
print(“No common elements”)
Output
Common elements are: {−78, 36, 45}

Question: Write a Python program to count the number of elements in a given range using traversal. Also, display its output.
Answer: c=0
l=40
r=80
tuple1=(10, 20, 30, 40, 50, 40, 40, 60, 70)
for x in tuple1:
if x>=l and x<=r:
c+=1
print(“Tuple:”, tuple1)
print(“Elements in a tuple:”,c)
Output
Tuple : (10, 20, 30, 40, 50, 40, 40, 60, 70)
Elements in a tuple : 6

Question: Write a Python program to calculate the sum and mean of the elements in a tuple.
Answer: tuple1=(23,45,20,45,65,24)
print(“The tuple is:”,tuple1)
sm=0
for i in range(len(tuple1)):
sm=sm+tuple1[i]
mean=sm/num
print(“SUM=”,sm)
print(“MEAN=”,mean)
Output
The tuple is: (23, 45, 20, 45, 65, 24)
SUM = 222
MEAN = 44.4

Question: A tuple is a collection of objects which ordered and immutable. Tuples are sequences, just like lists.
The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.
We can use the index operator [] to access an item in a tuple, where the index starts from 0.
So, a tuple having 6 elements will have indices from 0 to 5. Trying to access an index outside of the tuple index range(6,7,… in this example) will raise an IndexError.
(i)Which types of elements are stored in tuple?
(ii)What do you mean by nested tuples?
(iii)Write the syntax to create tuple from an existing sequence.
(iv) Observe the output of giving code.
>>>t=[“T”, “U”, “P”, “L”, “E”]
>>>t2 = tuple(t)
>>>t2
(v)What is traversing a tuple in Python?
Answer: (i) Tuples hold a sequence of heterogeneous elements.
(ii) Nested tuples are tuple objects where the elements in the tuples can be tuples themselves.
(iii) new_tuple_name=tuple(sequence)
(iv) (‘T’, ‘U’, ‘P’, ‘L’, ‘E’)
(v) Traversing a tuple is a technique to access an individual element of that tuple.

Question: Write a Python program to search an element with its index number.
Answer: tuple1=(12,65,78,−63,−2,3,78,−12)
sm=0
x=int(input(“Enternumber tobesearched:”))
found=False
for i in range(len(tuple1)):
if(tuple1[i]==x):
found=True
print(“%d found at %drd
position”%(x,i))
break
if(found==False):
print(“%d is not in tuple”%x)
Output
Enter number to be searched: − 63
− 63 found at 3rd position

Question: Consider the following tuples, tuple1 and tuple2.
tuple1 = (23,1,45,67,45,9,55,45)
tuple2 = (100,200)
Find the output of the following statements.
(i) print(tuple1.index(45))
(ii) print(tuple1.count(45))
(iii) print(tuple1 + tuple2)
(iv) print(len(tuple2))
(v) print(max(tuple1))
(vi) print(min(tuple1))
(vii) print(sum(tuple2))
(viii) print(sorted(tuple1))
print(tuple1) 
Answer: (i) 2
(ii) 3
(iii) (23, 1,45, 67,45, 9, 55, 45, 100, 200)
(iv) 2
(v) 67
(vi) 1
(vii) 300
(viii) [1, 9, 23, 45, 45, 45, 55, 67]
(23,1,45,67,45,9,55,45)

Question: Write a program to find the occurrence of a given element.
Answer: t=(23,45,20,−45,65,24,−45,−23)
print(“The tuple is:”,t)
k=0
num=int(input(“Enter the number to be
counted:”))
for j in t:
if(j==num):
k=k+1
print(“Number”,num,“is appear”,k, “times.”)
Output
The tuple is: (23, 45, 20, − 45, 65, 24, − 45, − 23)
Enter the number to be counted:45
Number 45 is appear 1 times.

Question: Write a program to read email IDs of n number of students and store them in a tuple. Create two new tuples, one to store only the usernames from the email IDs and second to store domain names from the email IDs. Print all three tuples at the end of the program.
[Hint You may use the function split()]
Answer: num=int(input(“Enternumberof students: ”))
list1=[]
for i in range(num):
email=input(“Enter email: ”)
list1.append(email)
tuple1=tuple(list1)
username=[]
domain=[]
for i in tuple1:
n,d=i.split(“@”)
username.append(n)
domain.append(d)
username=tuple(username)
domain=tuple(domain)
print(“Names=”,username)
print(“Domains=”,domain)
print(“Tuple=”,tuple1)