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 index of 45 in tuple1 ii. print count of 45 in tuple1 iii. print tuple1 concatenated with tuple2 iv. print length of tuple2 v. print maximum value in tuple1 vi print minimum value in tuple1 vii. print sum of tuple2 viii. print sorted tuple1, then unsorted tuple1
Question
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)
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Let's evaluate each statement one by one for the given tuples:
tuple1 = (23, 1, 45, 67, 45, 9, 55, 45)
tuple2 = (100, 200)
Statement i:
print(tuple1.index(45))
This statement finds the index of the first occurrence of the value
45
intuple1
.Output:
2
Statement ii:
print(tuple1.count(45))
This statement counts the number of times the value
45
appears intuple1
.Output:
3
Statement iii:
print(tuple1 + tuple2)
This statement concatenates
tuple1
andtuple2
.Output:
(23, 1, 45, 67, 45, 9, 55, 45, 100, 200)
Statement iv:
print(len(tuple2))
This statement prints the length of
tuple2
.Output:
2
Statement v:
print(max(tuple1))
This statement prints the maximum value in
tuple1
.Output:
67
Statement vi:
print(min(tuple1))
This statement prints the minimum value in
tuple1
.Output:
1
Statement vii:
print(sum(tuple2))
This statement prints the sum of values in
tuple2
.Output:
300
Statement viii:
print(sorted(tuple1)) print(tuple1)
sorted(tuple1)
returns a new list of all items intuple1
in ascending order.tuple1
remains unchanged because tuples are immutable.Output:
[1, 9, 23, 45, 45, 45, 55, 67] (23, 1, 45, 67, 45, 9, 55, 45)
Summary
i.
print(tuple1.index(45))
→2
ii.
print(tuple1.count(45))
→3
iii.
print(tuple1 + tuple2)
→(23, 1, 45, 67, 45, 9, 55, 45, 100, 200)
iv.
print(len(tuple2))
→2
v.
print(max(tuple1))
→67
vi.
print(min(tuple1))
→1
vii.
print(sum(tuple2))
→300
viii.
print(sorted(tuple1)) print(tuple1)
→[1, 9, 23, 45, 45, 45, 55, 67] (23, 1, 45, 67, 45, 9, 55, 45)
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month