WORKSHEET-TUPLES
Learning objectives: To apply the tuple methods in python.
Assessment
1. Which of the following is a Python tuple?
a)(1,2,3) b)[1,2,3] c){1,2,3} d){}
2. What will be the output of the following Python code?
>>>t=(1,2,4,3)
>>>t[1:3]
a)(1,2) b)(2,4) c)(2,4,3) d)(1,2,4)
3. What will be the output of the following Python code?
>>>t=(1,2,4,3)
>>>t[1:-1]
a)(1,2,4) b)(2,4,3) c)(2,4) d) (1,2)
4. What will be the output of the following Python code?
>>>t = (1, 2, 4, 3, 8, 9)
>>> for i in range(0, len(t), 2):
print(t[i])
a)[1,4,8] b)[2,3,9] c)Error d)[1,2,4,3,8,9]
5. What will be the output of the following Python code?
>>>t = (1, 2)
>>>2 * t
a)(1,2,1,2) b)(1,1,2,2) c)[1,1,2,2] d)[1,2,1,2]
ACTIVITY-1
Find the output generated by following code fragments :
tuple = ( 'a' , 'b', 'c' , 'd' , 'e') tuple = ( 'A', ) + tuple[1: ] print(tuple)
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]
ACTIVITY 2:
Write the output of the following. a=(23,34,65,20,5) print(a[0]+[Link](5))
[Link] the output of the following
numbers = (1, 2, 3, 4, 5, 1, 2, 1)
count_1=[Link](1)
print(count_1)
ACTIVITY-3
Scenario: The UAE Government is designing a secure digital identity system for
citizens. Each ID record should be immutable and must include:
✔️ID number
✔️Full name
✔️Emirate of residence
✔️Birth year
Task:
1. Store Emirates ID records in tuples.
2. Allow searching by ID number.
3. Ensure data integrity (immutability).