Tuples Programs

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

#Give Output

tt=(12,3,[5,6,9],"alok",'b',44.5)
print(len(tt)) #6
print(len(tt[2])) #3
print(tt[-2]) #'b'
print(tt[1:4]) #(3,[5,6,9],"alok")
print(tt[-1:-4] #()
print(tt[-1:-4:-1]) #(44.5,’b’,’alok’)
print(tt[2][0]) #5
print(tt[3][:len(tt[3])-1]) #alo
x=tt+(22,)
print(x) #(12,3,[5,6,9],"alok",'b',44.5,22)

# WAP to print sum of values ending with digit 2, from numbers stored in a tuple
#Example if T=(3,22,120,12,41,2,100,102)
# Then sum should be 138 ie 22+12+2+102
T=(3,22,12,41,2,100,102)
s=0
for i in T:
if i%10==2:
s=s+i
print("Sum = ",s)

# WAP to print minimum and maximum value from integers stored in a tuple
# Do Not use min()/max()
tt=(3,5,1,8,11,4)
#print(tt)

min=max=tt[0]#min=1,max=11
for i in range(1,len(tt)):
if tt[i]>max:
max=tt[i]
elif tt[i]<min:
min=tt[i]
print("Minimum value= ",min,"Maximum value ",max)

# WAP to store marks of three subjects for three students and print total marks for each

#marks=((50,60,40),(80,70,90),(70,60,80))

marks=eval(input("ENter Marks "))


for i in marks:
s=0
for j in i:
s=s+j
print("Total= ",s)

# WAP to read tuple storing certain names, print number of vowels in each name.

If tuple is tt=("aniket","kamal","alok"), then output should be

aniket has 3 vowels

kamal has 2 vowels

alok has 2 vowels


for i in tt:
v=0
for x in i:
if x in ['a','e','i','o','u']:
v=v+1
print(i, "has ",v,"vowels")

# The Above program using index/in range

for i in range(len(tt)):
v=0
for j in range(len(tt[i])):
if tt[i][j] in ['a','e','i','o','u']:
v=v+1
print(tt[i], "has ",v,"vowels")

You might also like