# Tuple Question Answer in Python for Class 11

Tuple Question Answer in Python for CBSE Class 11 Computer Science. Assignment solutions of Sumita arora book. There are conceptual, application based and program based questions and answers for the preparation of annual exam.

## Type A : Conceptual based Questions

Q.1. Discuss the utility and significance of Tuples, briefly.

It is a type of arrays. In python it is immutable type of container .

Q.2. If a is (1, 2, 3)
(a) what is the difference (if any) between a * 3 and (a, a, a)?
(b) is a * 3 equivalent to a + a + a ?
(c) what is the meaning of a[1:1] ?
(d) what is the difference between a[1:2] and a[1:1] ?

A = a*3 >>>(1,2,3,1,2,3,1,2,3)
(a,a,a) will print .>>>((1,2,3),(1,2,3),(1,2,3))
B = yes
C = it will print empty tuple.
D = a[1:2] will print index number 1 while,a[1:1] print empty tuple.

Q.3.Does the slice operator always produce a new tuple ?

Yes ,it will print a part of tuple.

Q.5.Are the following two assignments same ? Why / why not ? (b) T3 = (3, 4, 5) T4 = ((3, 4, 5)) (a) T1 =3, 4, 5 T2 = (3,4 ,5)

(a)   t1==t2      True      Because t1 and t2 have same value.
(b) t3 == t4     False     Because T3 is a tuple but T4 is a nested tuple.

Q.6. What would following statements print ? Given that we have tuple = (‘t’, ‘p’, ‘I’) (a) print(“tuple”) (b) print(tuple(“tuple”)) (c) print (tuple)

A = ‘tuple’
B  = (‘t’,’u’,’p’,’l’,’e’)
C = (‘t’,’p’,’l’)

Q.7. How is an empty tuple created ?

By two way we can create a empty tuple first by given value with out any  valueLike :- a =()Second by defining tuple       A=tuple ()

Q.8. How is a tuple containing just one element created ?

3 ways are there_
a =’b’  a=(‘b’,)  a=tuple ([‘a’])

Q.9. How can you add an extra element to a tuple ?

By using + operator
Example:- a=(‘p’,’y’,’t’,’h’,’o’)
b =(‘n’)
print (a+b)
>>>(‘p’,’y’,’t’,’h’,’o’,’n’)

### Application Based Questions : Tuple in Python for Class 11

Q.1. Find the output generated by following code fragments:
(a)plane = (“Passengers”, “Luggage”)
plane = “Snakes”
(b)(a, b, c) = (1, 2, 3)
(c)(a, b, c, d) = (1, 2, 3)
(d)a, b, c, d = (1, 2, 3)
(e)a, b, c, d, e = (p, q, r, s, t) = t1
(f)What will be the values and types of variables a, b, c, d, e, f, p, q, r, s, t after executing part e above?
(g)t2 = (‘a’)
type(t2)
(h)
t3 = (‘a’,)
type(t3)
(i)T4 = (17)
type(T4)
(j)T5 = (17,)
type(T5)
(k)
tuple = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’)
tuple = (‘A’,) + tuple [1:]
print (tuple)
(l)
t2 = (4, 5, 6)
t3 = (6, 7)
t4  = t3 + t2
t5 = t2 + t3
print(t4)
print(t5)
(m)
t3 =  (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
print(t4)
print(t5)
(n)
t1 = (3, 4)
t2 = (‘3’, ‘4’)
print(t1 + t2)
(o) What will be stored in variables a, b, c, d, e, f, g, h after following statements?
perc = (88, 85, 80, 88, 83, 86)
a = perc[2:2]
b = perc[2:]
c = perc[:2]
d = perc[:-2]
e = perc[-2]
f = perc[2:-2]
g = perc[-2:2]
h = perc[:]

(a) It will generate an error.
>>> a
1
>>> b
2
>>> c
3
>>> type(a)
<class ‘int’>
>>> type((a,b,c))
<class ‘tuple’>
>>>
(c) It will give an error .
(d) It will generate an error .
(e) If value of t1 = (1, 2, 3, 4, 5) Then after running the program.
>>> a
1
>>> p
1>>> type(a)
<class ‘int’>
>>> type(p)
<class ‘int’>
>>
(f) value of t1 = (1, 2, 3, 4, 5) , after running the program.
>>> a
1
>>> p
1
>>> type(a)
<class ‘int’>
>>> type(p)
<class ‘int’>
>>> b
2
>>> q
2
>>> c
3
>>> r
3
>>> d
4
>>> s
4
>>> e
5
>>> t
5
>>> type(c)
<class ‘int’>
>>> type(t)
<class ‘int’>
>>>
(g) <class ‘str’>
(h) <class ‘tuple’>
(i) <class ‘int’>
(j)
(‘A’, ‘b’, ‘c’, ‘d’, ‘e’)
(k)
(6, 7, 4, 5, 6)
(4, 5, 6, 6, 7)
>>>
(l)
(6, 7, 4, 5, 6)
(4, 5, 6, 6, 7)
>>>
(m)
(6, 7, 6, 7, 6, 7)
(6, 7, 6, 7, 6, 7)
(n)
(3, 4, ‘3’, ‘4’)
>>>
(o)
>>> a
()
>>> b
(80, 88, 83, 86)
>>> c
(88, 85)
>>> d
(88, 85, 80, 88)
>>> e
83
>>> f
(80, 88)
>>> g
()
>>> h
(88, 85, 80, 88, 83, 86)

Q.2.What does each of the following expressions evaluate to? Suppose that T is the tuple
(“These”, (“are”, “a”, “few”, “words”), “that”, “we”, “will”, “use”)
(a)T[0: : 2]
(b)”a” in T  [ 0 ]
(c)T [ : 1 ] + T[ 1 ]
(d)T[ 2 : : 2 ]
(e)T in T

(a)
>>> T[0: : 2]
(‘are’, ‘few’)
(b)
>>> “a” in T  [ 0 ]
True
(c)
>>> T [ : 1 ] + T[ 1 ]
(‘These’, ‘are’, ‘a’, ‘few’, ‘words’)
(d)
>>> T[ 2 : : 2 ]
(‘that’, ‘will’)
(e)
>>> T in T
True>>>

Q.3. Carefully read the given code fragments and figure out the errors that the code may produce.
(a)
t = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’)
print(t)
(b)
t = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’)
t = ‘A’
(c)
t1 =  (3)
t2 = (4, 5, 6)
t3 = t1 + t2
print(t3)
(d)
t2 = (4, 5, 6)
t3 = (6, 7)
print(t3 – t2)
(e)
t3 = (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
t6 = t3 * (3,)
print(t4)
print(t5)
print(16)
(f)
t = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’)
1, 2, 3, 4, 5, = t
(g)
t = (‘a’, ‘b’, ‘c, d’, ‘e’)
1n, 2n, 3n, 4n, 5n = t
(h)
t = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’)
x, y, z, a, b = t
(i)
t = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’)
a, b, c, d, e, f = t

(a) IndexError: tuple index out of range
(b) TypeError: ‘tuple’ object does not support item assignment
(c) TypeError: unsupported operand type(s) for +: ‘int’ and ‘tuple’
(d) TypeError: unsupported operand type(s) for -: ‘tuple’ and ‘tuple’
(e) TypeError: can’t multiply sequence by non-int of type ‘tuple’
(f) syntax error
(g) invalid syntax
(h) It will give no error.
(i) ValueError: not enough values to unpack (expected 6, got 5)

Q.4.What would be the output of following code if
ntpl = (“Hello”, “Nita”, “How’s”, “life?”)
(a, b, c, d) = ntpl
print ( “a is:”, a)
print(“b is:”, b)
print(“c is:”, c)
print(“d is:”, d)
ntpl = (a, b, c, d)
print (ntpl + ntpl, ntpl)

a is: Hello
b is: Nita
c is: How’s
d is: life?
Hi Nita

Q.5.Predict the output:
tuple_a = ‘a’, ‘b’
tuple_b = (‘a’, ‘b’)
print (tuple_a == tuple_b)

Output:-
True

Q.6. Find the error. Following code intends to create a tuple with three identical strings. But even after successfully executing following code (No error reported by Python). The len() returns a value different from 3 Why ?
tup1 = (‘Mega’) * 3
print(len(tup1))

Here ‘tup1’ is not tuple, it is string.
Program is: –
tup1 = (‘Mega’,) * 3
print(len(tup1)
len() return 3

Q.7. Predict the output:
tuple1 = (‘Python’) * 3
print(type(tuple1))

Output: –
<class ‘str’>
>>>

Q.8. Predict the output:
x = (1, (2, (3, (4,))))
print (len(x))
print( x)
print(2 in x)
y = (1, (2, (3,), 4), 5)
print len((y))
print(len(y)
print( y = 50)
z = (2, (1, (2,), 1), 1)
print (z[z[z]])

Answer :  It will give an error

Q.9.What will the following code produce?
Tup1 = (1,) * 3
Tup1  = 2
print (Tup1)

It will give an error that ‘TypeError: ‘tuple’ object does not support item assignment’.

Q.10.What will be the output of the following code snippet?
Tup1 = ((1, 2),) * 7
print (len(Tup1 [3: 8 ]))

Output is: –
4
>>>
Because
Tup1 = ((1, 2),) * 7
After this Tup1 become
((1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2))
Now Len(Tup1[3:8]) strat from index number 3 , 4, 5, 6.
So, output is 4.

### Programming Tuple Question Answer in Python for Class 11

Q.1. Write python that create a tuple storing first 9 term of Fibonacci series.

```Answer:
i=0
fib = (0,1,1)
for i in range(6):
fib = fib + ( fib [ i +1] + fib [ i + 2 ] ,)
print(fib)
#print(i)```

Q.2.(a) Write a program that receive the index and return the corresponding value.
(b) Write a program that receives a Fibonacci term. And return and returns a number telling which term it is .

```Answer:
(a)
i=0
a = eval (input('Enter the list ='))
b = int (input ("Enter the index number ="))
if b< len(a):
print ("value is =", a[b])
else :
print ("index out of range")
#print(i)
(b)
i=0
term= int (input ("Enter the term of seris ="))
fib = (0,1,1)
for i in range(term):
fib = fib + ( fib [ i + 1] + fib [ i + 2 ],)
for j in range(len(fib)):
if term == fib[ j ] :
break
print("this is ",j + 1,"th of fibonocci ")
#print(i)```

Q.3.Write a program that interactively create a nested tuple to store the marks in three subjects for five student .

```Answer:
i=o
total = ()
for i in range(3):
mark = ()
mark1 = int(input("enter the marks of first subject = "))
mark2 = int(input("enter the marks of second subject = "))
mark3 = int(input("enter the marks of third subject = "))
mark = (mark1 , mark2 , mark3)
total= total + (mark,)
print("total marks = ",total)
#print(i)```

Q.4.In the program created in previous question , add a function that computes total marks and average marks obtain by each student .

```Answer:
i=0
for i in range(3):
mark1 = int(input("enter the marks of first subject = "))
mark2 = int(input("enter the marks of second subject = "))
mark3 = int(input("enter the marks of third subject = "))
print("total marks of",i+1,"student = ", mark1 + mark2 + mark3)
print("average marks of",i+1,"student = ", (mark1 + mark2 + mark3 )/3)
#print(i)```

Q.5.Write a program that input two tuples and creates a third , that contains all elements of the first followed by all elements of the second.

```Answer:
i=0
tup1 = eval(input("enter first tuple = "))
tup2 = eval(input("enter second tuple = "))
tup3 = tup1 + tup2
print(tup3)
#print(i)```

Q.6.Write a program as per following specification :
“‘ Return the length of the shortest string in the tuple of a strings str_tuple.
Precondition : the tuple will contain at least one element .’”

```Answer:
i=0
tup = eval(input("enter the string tuple = "))
short = tup [ 0 ]
for i in tup :
if len(i) < len( short ) :
short = i
print("smllest string in tuple = ",short)
#print(i)```

Q.7.Create the following tuple using a for loop :
(i) = a tuple containing the squares of the integer 1 though 50 .
(ii)= the tuple (“a”, “bb”, “ccc”….)that ends with 26 copies of the letter z .

```Answer:
(i)

i=0
tup = ()
for i in range(1,51):
tup = tup + ( i,)
print(tup)
#print(i)

```
```(ii)

i=0
tup = ()
for i in range(1 , 26):
tup = tup + ( chr(i + 96 )* i ,)
print(tup)
#print(i)
```

Q.8.Given a tuple pair ((2,5),(4,2),(9,8),(12,8)),count the number of pair (a,b) such that a and b are even .

```Answer:
i=0
tup = ((2,5),(4,2),(9,8),(12,8))
count = 0
for  i in range (len(tup)):
if tup [i] % 2 == 0 and tup[i] % 2 == 0:
count += 1
print("the number of pair (a,b) such that a and b are even = ",count)
#print(i)```

Q.9.Write a program that input two tuple seq_a and seq_b and print True if every element in seq_a is also an element of seq_b , else print False.

```Answer:
i=0
tup1 = eval(input("enter first tuple = "))
tup2 = eval(input("enter second tuple = "))
count = 0
if len(tup1)==len(tup2):
for i in range(len(tup1)) :
if tup1[i] == tup2 [ i ] :
continue #print(i)
else :
count += 1
if count == 0  :
print("True")
else :
print("False")
else :
print("False")
#print(i)```

Q.10. Computing mean. Computing the mean of values stores in a tuple is relatively simple. The mean is the sum of the values divided by the number of values in the tuple.
mean = Sum of frequency /no. of frequency
Write a program that calculate  and display  the mean  of a tuple with  numeric element .

```Answer:
i=0
a = eval (input ("Enter the numeric tupal ="))
b = 0
for i in range (len(a)):
b = b +a[i]
print('mean of tupal=',b/len(a))
#print(i)```

Q.11.Mean of means . given a nested tuple tup1 = ((1,2),(3,4.15,5.15),(7,8,12,15)) .write a program that display the mean of individual element of tuple tup1 and then displays  the mean of these computed means.

```Answer:
i=0
a = eval (input ("Enter the numeric tupal ="))
b = 0
for i in range (len(a)):
b = b +a[i]
print('mean of tupal=',b/len(a))
#print(i)```

Thanks for reading the Tuple Question Answer in Python for CBSE Class 11. Solved assignment of computer science python CBSE syllabus is provided on this site. Go through them to have a good score in exam. Also, Python practical exams question and solutions are provided here.