0% found this document useful (0 votes)
31 views

TUPLE (1)

Uploaded by

Trisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

TUPLE (1)

Uploaded by

Trisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CLASS-11

WORKSHEET ON TUPLE
MCQ:

1. Which of the following will create a single element tuple? [SUMITA ARORA]
(a) (1,) (b) (1) (c) ([1]) (d)tuple([1])

2. What will be the output of the following python code? [SUMITA ARORA]
tp1=(2,4,3)
tp3=tp1*2
print(tp3)

(a)(4,8,6) (b) (2,43,2,4,3) (c)(2,2,4,4,3,3) (d) Error

3. What will be the output of following python code? [SUMITA ARORA]


tp1=(15,11,17,16,12)
tp1.pop(12)
print(tp1)

(a) (15,11,16,12) (b) (15,11,17,16) (c)(15,11,17,16,12) (d) Error

4. Which of the below given functions cannot be used with nested tuples? [SUMITA ARORA]
(a) index() (b)count() (c)max() (d)sum()

5. What will be following relation result in? [VK PANDAY]


(1,2,3)<(1,2,8,9)
(a)False (b)Error (c)True (d)None of these

6. Which of the following tuple concatenate two tuples? [VK PANDAY]


(a)+ (b)* (c)add (d)join

7. Given is a nested tuple structure: [VK PANDAY]


T=(1,2,3,(4,5),6)
Which of the following will access only the sub-tuple?
(a)T[2] (b)T[4] (c)T[:3] (d)T[3]

ASSERTION AND REASONING BASED: [VK PANDAY]

Based on the following assertion (A) and reasoning(R), pick up an appropriate statement
from the options below:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true and R is not the correct explanation of A.
(c) A is true but R is false
(d) Both A and R are false.
8. Assertion (A): Indexing of tuple elements means the positioning of the elements in a
tuple.
Reason(R): The indexing of tuple elements can be defined in two ways. In the forward
indexing, the index of the elements starts with 1, whereas the backward indexing starts
with -1.

9. Assertion (A): The sorted() function is used to arrange the set of elements of atuple
either in the ascending or descending order.
Reason(R): The tuple is an mutable set of data. Therefore the tuple gets converted
implicitly into a list before getting used as argument to the sorted() function.Finaly the
sorted elements appear as a list.

10. Assertion (A): The index() function returns the index of the first occurrence of an
element in the tuple.
Reason(R): This function will start searching from the 0th index of the tuple and return
the index of the last occurrence of an element.

11. Assertion (A): You can also compare two tuples using relational operators.
Reason(R): The relation operators such as ==,<,<=,>,>= etc are used to compare the
tuple elements with each other starting with the 0th index. The result of the comparison
will either be true or false.

CASE BASED QUESTIONS:


12. Swechha , a student of ‘Jamshedpur Public School’ wants to create different tuples after
slicing the elements from main tuple. The main tuple and the tuples she wants to create
after slicing are given below:
Main tuple:
T1=(1,2,3,4,5,6,7,8,9,10)
Tuples to be created after slicing the elements from the main tuple:
(a) (2,3,4,5,6)
(b) (7,8,9,10)
(c) (1,3,5,7)
(d) (2,5,8)
Write the statements that she should execute to obtain the above mentioned tuples after
slicing the main tuple.

13. A code snippet is given below:


T1=(23,41,12,78,82,33,45,29)
print(T!.index(T1[12])
print(T1[3:])
print(max(T1) –min(T1))
print(list(T1[:4])
Write the statements used in the above code snippet which will produce the following
outputs on the screen:
(a)70
(b)(23,41,12,78)
(c)2
(d)(78,82,33,45,29)

14. Your brother is trying to understand a code snippet while preparing for his examination.
The code snippet is as given below:
T1=eval(input())
tln=len(T1)
for x in T1:
if(x<10)
c1=c1+1
elif(x<100)
c2=c2+1
else:
c3=c3+1
He has some queries in his mind about some of the statements used in the above code
snippet. Answer his queries to help him to understand the logic. His queries as a listed
below:
(a) Which statement of the snippet finds the number of elements available in the tuple?
(b) Which statement of the snippet has been used to enter the values in the tuple?
(c) Which statement has been used to iterate for getting the values from different indices
of the tuple?
(d) Which statement of the code snippet counts the number of two digit numbers?

SAQ (APPLICATION BASED):

15. Consider the tuples given below: [VK PANDAY]


T1=(1,2),T2=(5,8)
Find the output, if the following operations are carried out:
(i) T1==T2
(ii) T1>T2
(iii) T1!=T2
(iv) T1<T2

16. Refer to the tuple given below: [VK PANDAY]


T=(3,2,5,1,2)
Predict the output when the following code snippet is executed:
m=max(T)-min(T)
s=sum(T)+m
print(m)
print(s)

17. A tuple T1(1,2,3,4,5) contains the five integers. What will be the result when the
following statements are executed? [VK PANDAY]
(i) T1.index(3)+len(T1)
(ii) T1[1]+T1[4]
(iii) len(T1*2)

18. Carefully read the given code fragments and figure out the errors that the code may
produce. [SUMITA ARORA]
(a) t3 = (6, 7)
t4 = t3*3
t5 = t3 * (3)
t6 = t3 * (3,)
print(t4)
print(t5)
print(t6)

(b) t = (‘a’, ‘b’, ‘c’, ‘d’, ‘e’)


x, y, z, a, b = t

19. Predict the output. [SUMITA ARORA]


tuple_a = ‘a’, ‘b’
tuple_b = (‘a’, ‘b’)
print (tuple_a == tuple_b)

20. What will be the output of the following code snippet? [SUMITA ARORA]
Tup1 = ((1, 2),) * 7
Print(len(Tup1 [3:8]))

21. Given below is a tuple for your reference: [VK PANDAY]


TPL=(1,2,4,2,5,8,2,6,2)
What will be the result,if the following statements are executed?
(i) TPL.count(2)+TPL.index(2)
(ii) TPL.count(2)*2

22. Predict the output. [SUMITA ARORA]


x = (1, (2, (3, (4,))))
print (len(x) )
print( x[1][0] )
print( 2 in x )
y = (1, (2, (3,), 4), 5)
print( len(y) )
print( len(y[1]) )
print( y[2] =50 )
z = (2, (1, (2,), 1), 1)
print( z[z[z[0]]] )
23. Given below is a tuple: [VK PANDAY]
T=(‘a’,’b’,’c’,’d’,’e’,’f’,(‘g’,’h’,’i’),’j’,’k’)
What will the following instructions result in?
(i) T[2:5]
(ii) T[6:12:2]
(iii) T[::-2]
(iv) T[6][1]
(v) T[-1:-10:-3]

24. Given below is a tuple: [VK PANDAY]


T=(“Jack”,”and”,”Jill”,”went”,”up”,”the”,”the”,”hill”)
Write appropriate statements or functions to perform each of following tasks:

(i) Slice the tuple containing (‘Jill’,’went’,’up’)


(ii) Slice the tuple from the beginning till the end using the elements at a step of 2.
(iii) Obtain the index of the string ‘Jill’ in the tuple.
(iv) Arrange the tuple elements in an alphabetical order.

THEORY QUESTIONS: [VK PANDAY]

25. What is meant by a null or empty tuple?

26. Name two techniques used for searching an element in a tuple.

27. Give an example to create a tuple using a single element.

28. What is the purpose of the count function?

29. Differentiate between the followings with examples:


(a) max() and min() functions
(b) sum() function and ‘+’ operator
(c) concatenation and slicing
(d) sort() and sorted()

30. What is meant by unpacking of a tuple?

PROGRAM:

31. Write a program that receives the index and returns the corresponding value.
[SUMITA ARORA]

32. Write a program that receives a Fibonacci term and returns a number telling which term it
is. For instance, if you pass 3, it returns 5, telling it is 5 th term; for 8, it returns 7.
[SUMITA ARORA]
33. Write a program that interactively creates a nested tuple to store the marks in three
subjects for five students, i.e., tuple will look somewhat like : [SUMITA ARORA]

marks( (45,45, 40), (35, 40, 38),


(36, 30, 38), (25, 27, 20), (10, 15, 20) )

34. In the program created in previous question, add a function that computes total marks and
average marks obtained by each student. [SUMITA ARORA]

35. Write a program that inputs two tuples and creates a third that contains all elements of the
first followed by all elements of the second. [SUMITA ARORA]

36. Given a tuple pairs = ((2, 5), (4, 2), (9,8), (12,10)), count the number of pairs (a, b) such
that both a and b are even. [SUMITA ARORA]

37. Write a Python code to accept different strings in a tuple. Display the strings that start
and end with the same letter. [VK PANDAY]

38. Write a Python code to accept a set of numbers in a tuple. Display all the unique
numbers. [VK PANDAY]

39. Write a program in Python to accept the names of some countries and their capitals in
two different tuples respectively. Display the names of countries along with their capitals.
The program also checks whether the information is displayed correctly or not by
entering country name (say ‘India’) to display capital name(say ‘New Delhi’). [VK PANDAY]

40. Write a Python program to accept some string in a tuple. Find and display the length of
the longest string. [VK PANDAY]

HOME WORK:

41. 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:
print(tuple1.index(45))
print(tuple1.count(45))
print(tuple1 + tuple2)
print(len(tuple2))
print(max(tuple1))
print(min(tuple1))
print(sum(tuple2))
print(sorted(tuple1))
print(tuple1)

42. 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()]

43. Write a program to input names of n students and store them in a tuple. Also, input a
name from the user and find if this student is present in the tuple or not.
We can accomplish these by:
(a) writing a user defined function
(b) using the built-in function

44. A bank is a financial institution which is involved in borrowing and lending of money.
With advancement in technology, online banking, also known as internet banking allows
customers of a bank to conduct a range of financial transactions through the bank’s
website anytime, anywhere. As part of initial investigation you are suggested to
• collect a bank’s application form. After careful analysis of the form, identify the
information required for opening a savings account. Also enquire about the rate of
interest offered for a saving account.
• The basic two operations performed on an account are Deposit and Withdrawal. Write
a menu driven program that accepts either of the two choices of Deposit and Withdrawal,
then accepts an amount, performs the transaction and accordingly displays the balance.
Remember, every bank has a requirement of minimum balance which needs to be taken
care of during withdrawal operations. Enquire about the minimum balance required in
your bank.
• Collect the interest rates for opening a fixed deposit in various slabs in a savings bank
account. Remember, rates may be different for senior citizens.
Finally, write a menu driven program having the following options (use functions and
appropriate data types):
• Open a savings bank account
• Deposit money
• Withdraw money
• Take details, such as amount and period for a Fixed Deposit and display its maturity
amount for a particular customer.

45. What advantages do tuples have over lists?


46. When to use tuple in Python. Give some examples of programming situations mentioning
their usefulness.

47. Prove with the help of an example that the variable is rebuilt in case of immutable data
types.

48. TypeError occurs while statement 2 is running. Give reason. How can it be corrected?
>>> tuple1 = (5) #statement 1
>>> len(tuple1) #statement 2

49. Write a program to input ‘n’ numbers in a tuple and separate the tuple in the following
manner.
Example
T=(10,20,30,40,50,60)
Tl=(10,30,50)
T2=(20,40,60)

50. Write a program to input two tuple and find the intersection of both.
Example:
Input:
Tl=(10,30,50,40,60)
T2=(20,40,60,70)
Output:
Intersection:(40,60)

You might also like