Page 450 - Computer Science V2.0 Class 11
P. 450
TUPLES AND DICTIONARIES
1. 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)
Ans. 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)
2. Consider the following dictionary stateCapital:
stateCapital = {"AndhraPradesh":"Hyderabad",
"Bihar":"Patna","Maharashtra":"Mumbai",
"Rajasthan":"Jaipur"}
Find the output of the following statements:
i. print(stateCapital.get("Bihar"))
ii. print(stateCapital.keys())
iii. print(stateCapital.values())
iv. print(stateCapital.items())
v. print(len(stateCapital))
vi. print("Maharashtra" in stateCapital)
vii. print(stateCapital.get("Assam"))
viii. del stateCapital["Rajasthan"]
print(stateCapital)
Ans. i. Patna
ii. dict_keys(['AndhraPradesh', 'Bihar', 'Maharashtra', 'Rajasthan'])
iii. dict_values(['Hyderabad', 'Patna', 'Mumbai', 'Jaipur'])
iv. dict_items([('AndhraPradesh', 'Hyderabad'), ('Bihar', 'Patna'), ('Maharashtra', 'Mumbai'),
('Rajasthan', 'Jaipur')])
v. 4
vi. True
vii. None
viii. {'AndhraPradesh': 'Hyderabad', 'Bihar': 'Patna', 'Maharashtra': 'Mumbai'}
3. “Lists and Tuples are ordered”. Explain.
Ans. Lists and Tuples are ordered, it means that both the lists’ and tuples’ elements are ordered, because each element in lists and tuples has
a designated index position. The index position (either forward or backward), maintain the order and these elements can also accessed
individually with the help of their index position.
436 Touchpad Computer Science (Ver. 2.0)-XI

