You are on page 1of 2

Ayesha Khan-2K19-MCS-3

1- Write a program to print the 5th item from last. (Through negative indexing).

myTuple=("white","blue","green","yellow","red","pink",)
print(myTuple[-5])

2- Print a range from 1 to 5.

myTuple=("white","blue","green","yellow","red","pink","black","brown",)
print(myTuple[1:5])

3- Create a tuple and use enumerate function.

myTuple=("white","blue","green","yellow","red","pink","black","brown",)
for index,myTuple in enumerate(myTuple):
print(index,myTuple)

4- Write a program and do the following:

a- Find the length of a tuple.

myTuple=("white","blue","green","yellow","red","pink","black","brown",)
print(len(myTuple))

b- Find the maximum value in a tuple.

myTuple=("25","30","19","50","54","70")
print(max(myTuple))

c- Find the minimum value in a tuple.

myTuple=("25","30","19","50","54","70")
print(min(myTuple))
d- Sort the tuple.

myTuple=("25","30","19","50","54","70")
print(sorted(myTuple))

You might also like