11 Cs Tuples Worksheet
11 Cs Tuples Worksheet
1|Page 11_CS_TUPLES_Worksheet
T1 = (1, 2, 3, 4, 5, 6, 7, 8)
print(T1[1 : : 2])
print(T1[-1 : -5 : -2])
print(T1[: : -1])
print(T1[ : 7 : 2])
Q13. Which error is returned by the following code :
T1 = (1, 2, 3, 4, 5, 6, 7, 8)
print(T1[15])
Q14. Write two differences between Tuple and List.
Q15. Write a statement in python to concatenate the given tuples.
T1 = (1, 2, 3)
T2 = (5, 6, 7)
Q16. Write the output of the following code :
T1 = (45, 67, 98)
T1 = T1 + (1, 2, 3)
print(T1)
Q17. Write the output of the following code :
T1 = (45, 67, 98)
T1 = T1 * 3
print(T1)
Q18. Write the output of the following code :
T1 = (45, 67, 98)
T2 = ((45, 67, 98))
print(T1 in T2)
print(45 in T2)
print(45 in T1)
print(T1 + T2)
Q19. Explain the following functions in reference to Tuple in Python.
1. len( )
2. count( )
Q20. Write a program to accept five numbers from the user and store it in a tuple ‘T1’.
Q21. Write a program to accept five fruit name from the user and store it in a tuple ‘F1’.
Q22. Write a program to store ‘n’ number of sports in a tuple ‘S1’. (Accept ‘n’ from the user)
Q23. Consider the following tuple and write the code for the following statements :
T1 = (12, 3, 45, ‘Hockey’, ‘Anil’, (‘a’, ‘b’))
a. Display the first element of ‘T1’
b. Display the last element of ‘T1’
2|Page 11_CS_TUPLES_Worksheet
c. Display ‘T1’ in reverse order.
d. Display ‘Anil’ from tuple ‘T1’
e. Display ‘b’ from tuple ‘T1’
Q24. Write the output of the following :
for i in tuple("SHIMLA"):
print(i + i)
Q25. Write the output of the following :
>>> 7 in tuple(“123456789”)
>>> ‘7’ in tuple(“123456789”)
Q26. Write the output of the following :
T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
print(len(T1) + T1[-1])
print(T1[T1.count(23) + len(T1) -5])
print(T1.count(T1[6]))
print(T1.count(max(T1)))
Q27. Write the output of the following :
T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
print(max(T1))
print(min(T1))
Q28. Write the output of the following :
T1 = ('Hockey', 'Cricket', 'Football')
print(max(T1))
print(min(T1))
3|Page 11_CS_TUPLES_Worksheet
Q32. Write a program to accept three numbers from the user and insert it at the end of given Tuple
T1.
T1 = (23, 32, 4, 5, 2, 12, 23, 7, 9, 10, 23)
Q33. What type of error is returned by following statement :
>>> (a,b,c,d) = (5, 6, 8)
Q34. Write the output of the following code :
>>>(name, rollNo, subject) = ("Anil", 9, "CS")
>>> name
Q35. Which escape character is used for following :
a. for adding horizontal tab space.
b. for inserting a new line.
Q36. What do you mean by Nested Tuple? Give one example
Q37. Write a statement to print 30 from the given tuple.
a = (“Seventy”, [1, 2, 3], (20, 30, 40), “Eighty”)
Q38. Write a statement to unpack the following tuple into 3 variables.
(60, 70, 80)
Q39. Write a program to swap the values of given tuples.
T1 = (“A”, “B”)
T2 = (34, 65)
Q40. Write the output of the following code :
T1 = ("A",["B","D"],"C")
T1[1][1] = "C"
print(T1)
Q41. Write a program to print the frequency of a number accepted from the user in given tuple : T1 =
(12, 17, 18, 25, 19, 12, 18, 5)
Q42. Write a program in python to concatenate all the characters of given tuple. T1 = (‘B’ , ‘O’, ‘O’,
‘K’)
Expected OUTPUT : BOOK
Q43. Write a program to remove a number (accepted from the user) from the given tuple T1 = (12,
15, 18, 21, 24, 27, 30)
SAMPLE EXECUTION
4|Page 11_CS_TUPLES_Worksheet
T1 = (2, 'Apple', 6)
print(max(T1))
Q48. Consider the given tuple and write the output of given statements: T1 = (1, 23, 4, 5, “A”, [“C”,
“D”], (23, 45), 45)
1. print(len(T1))
2. print(T1.index(45))
3. print(T1.count(45))
4. print(T1[5][0]*2)
5. print(T1[:5])
6. print(T1[5:])
7. print(T1.index(“A”))
8. print(T1[-1 : -7 : -2])
9. print(T1[4] + T1[5])
10. print(max(T1))
Q49. Write the length of following tuple :
T1 = (1,(2,3),(((34,56),45,67),39))
Q50. Write a program to store the detail ( Roll number, Name, Section) of three students in a tuple.
Accept all data from the user.
SAMPLE OUTPUT :
((1, 'Amita', 'B'), (2, 'Sunita', 'C'), (3, 'Daya', 'A'))
Q51. Write a program to accept roll number from user and display it’s detail from given tuple
Det=((1, ‘Amita’, ‘B’), (2, ‘Sunita’, ‘C’), (3, ‘Daya’, ‘A’))
Q52. Write a program to accept five numbers from the user and store these numbers in a tuple.
Display the following from tuple :
1. Largest number
2. Smallest number
3. Sum of all numbers
4. Average of all numbers
Q53. Write a program in python to print the second largest element in tuple given below :
T1 = (23, 45, 87, 45, 67, 43, 23, 12)
Q54. Write a program in python to display the sum of all even numbers and odd numbers separately
from the tuple given below :
T1 = (24, 45, 87, 46, 67, 44, 23, 12)
Q55. Write the output of the following :
T1 = (“Amit”, “Sumit”)
T2 = “Sumit”, “Amit”
T3 = “Amit”, “Sumit”
print(T1==T2)
print(T1==T3)
5|Page 11_CS_TUPLES_Worksheet
Q56. Write a program to accept a number from the user and store first 10 multiples of number in a
tuple for example :
SAMPLE OUTPUT :
print(len(T1))
print(T1[1][0])
print(7 in T1[3])
print(T1.index(1))
print(len(T1[3]))
print(T1[T1[2][0]])
Q61. Write the output of the following :
T1 = (1,(2, 'a', (3, 'b', 'c', (7, 'd', 'e', 'f'))))
print(len(T1))
print(T1[1][0])
print(7 in T1[1])
6|Page 11_CS_TUPLES_Worksheet
print(T1.index(1))
print(len(T1[1]))
print(T1[T1[0]])
Q62. Write the output of the following :
T1 = (1, (2, 'a') * 2)
print(T1)
print(len(T1))
print(T1[1][1])
print(len(T1[1]))
Q63. Write the output of the following :
T1 = (1, (2, 'a')) * 2
print(T1)
print(len(T1))
print(T1[1][1])
print(len(T1[1]))
print(T1.count(1))
print(T1.index(1))
Q64. Write the output of the following :
T1 = ('a') * 3
T2 = ('a',) * 3
print(T1)
print(type(T1))
print(len(T1))
print(T2)
print(type(T2))
print(len(T2))
Q65. Write the output of the following :
T1 = "tuple questions in python"
T2 = (T1.split())
print(T1)
print(type(T1))
7|Page 11_CS_TUPLES_Worksheet
print(len(T1))
print(T2)
print(T2[0][0] + T2[1][0])
print(len(T2))
Q66. What type of error is returned by following code :
T1 = (1, 2, 3, 4)
T2 = (4, 5, 6)
print(T1 - T2)
Q67. Write the output of the following :
T1 = (1, 2, 3, 4)
print(T1 * 3)
print(T1 * (3))
print((T1) * 3)
print(T1 + (3,))
Q68. Write the output of the following :
T1 = (10, 20, 30)
print((T1, T1, T1))
print(T1, T1, T1)
print((T1 + T1 + T1))
print(T1 * 3)
Q69. Write the output of the following :
a = 30
b = (30)
c = (30,)
print(type(a))
print(type(b))
print(type(c))
Q70. Write a program to accept a number from the user and create a tuple containing all factors of
number. for example :
SAMPLE OUTPUT :
Enter any Number : 9
Tuple is : (1, 3, 9)
Q71. Write a program to arrange all the sub tuples of a tuple in increasing order and store them in
another tuple. for example
T1 = ((1, 2, 3), (45, 23), (98, 34, 67)) #Original Tuple
T2 = ((1, 2, 3), (23, 45), (34, 67, 98)) #New Tuple
Q72. Write a program to store the length of all sub tuples of a tuple into a new tuple. for example
T1 = ((1, 2, 3), (45, 23), (98, 34, 67),(34, 56, 78, 9)) #Original Tuple
8|Page 11_CS_TUPLES_Worksheet
T2 = (3, 2, 3, 4) # New Tuple
Q73. Write a program to print square of all odd numbers of a tuple.
T1 = (12, 13, 22, 7, 9, 66, 4)
Expected Output : 169, 49, 81
Q74. Write a program to print the common elements of given tuples :
T1 = (1, 2, 3, 4, 5, 6)
T2 = (3, 5, 7, 9, 11)
Expected Output : 3, 5
Q75. Write a program to find the union (Common element include once) of given tuples:
T1 = (1, 2, 3, 4, 5, 6)
T2 = (3, 5, 7, 9, 11)
Expected Output : 1, 2, 3, 4, 5, 6, 7, 9, 11
Q76. Write a program to store the sum of all sub tuples of given tuple into a new tuple. for example
T1 = ((1, 2, 3), (45, 23), (98, 34, 67),(34, 56, 78, 9)) #Original Tuple
T2 = (6, 68, 199, 177) # New Tuple
Q77. Write a program to store the maximum value of all sub tuples of given tuple into a new tuple. for
example
T1 = ((1, 2, 3), (45, 23), (98, 34, 67),(34, 56, 78, 9),(“A”, “B”, “c”))
#Original Tuple
T2 = (3, 45, 98, 78, c) # New Tuple
Q78. Write a program to display the longest sub tuple from the given tuple.
T1 = ((1, 2, 3), (45, 23), (98, 34, 67), (34, 56, 78, 9)) #
Original Tuple
T2 = (34, 56, 78, 9) # New Tuple
Q79. Write a program to display names starting from vowel from the given tuple.
T1 = (“Amit”, “Ram”, “Esha”, “Harry”)
Q80. Write a program to print the length of all names in a given tuple.
T1 = (“Amit”, “Ram”, “Esha”, “Harry”)
Expected Output : 4, 3, 4, 5
Q81. What is the purpose of following operators in reference to tuples.
a) +
b) *
c) in
Q82. Match the following :
Functions Description
9|Page 11_CS_TUPLES_Worksheet
max( ) Returns the length of the tuple.
10 | P a g e 11_CS_TUPLES_Worksheet