# Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

## "Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Tuple Concept in Python:-

A tuple is a collection of finite elements that can not be modified dynamically means tuple provides an immutable object, It is basically used to create a constant LIST.

Tuple will be declared by ()  small bracket but accessed by []

x = ("C","C++",1200,1200)

means we can not change the value of x anyway.

x= 12  #error we can not change tuple elements

x.append() #tuple can not be append

Where we use tuple in the project?

In the project, if we want to declare a set of constant then we can use a tuple object because the tuple object can not be modified hence it is also called an immutable object in python.

Tuple Example:-

s = ("C","CPP",1200,3500,12.34)
#s=12
#del s
#s.append(12)
for i in range(0,len(s)):
print(s[i])

Tuple using for each Loop:-

x= (12,23,34,56,67)
for x1 in x:
print(x1)

Tuple basic operation:-

We can add (merge tuple objects), repeat, and delete tuple objects.

a=(1,2,3)
b=(4,5,6)
c=()
c=a+b
c

........................................................................................................................................................

a= (1,2,3)*4
print(a)

......................................................................................................................................................

Program of Tuple:-

WAP to find the max element on Tuple?

x = (12,23,45,67,11,2)

m=0

for i in x:
if m<i:
m=i

print("Max element of List is ",m)

WAP to divide even elements and odd elements separately in a tuple?

WAP to count total even number and Odd number in Tuple?

WAP to count total integer, float, and string in a tuple?

The solution to this program:-

t = (12,23,34,45.67,"hello", "welcome", True)
cint=0
cfloat=0
cstring=0
cbool=0

for i in range(0,len(t)):
if type(t[i]).__name__=="int":
cint=cint+1
elif type(t[i]).__name__=="float":
cfloat=cfloat+1
elif type(t[i]).__name__=="str":
cstring=cstring+1
elif type(t[i]).__name__=="bool":
cbool=cbool+1

print("Total integer is ",cint, "Total float is ", cfloat," Total String is",cstring," Total boolean is ",cbool),

If you have any doubt in programming or join online classes then you can contact us by comment .

1. #WAP to find the max element in Tuple?
t=(45,56,78,90)
max=0
for i in range(0,len(t)):

if t[i]>max:
max=t[i]
print("the largest number is",max)

2. #WAP to divide even elements and odd elements separately in a tuple?
x=(2,3,4,5,6)
for i in range(0,len(x)):
if x[i]%2==0:
print("even number=",x[i])
else:
print("odd number=",x[i])

3. #WAP to divide even elements and odd elements separately in a tuple?
x=(2,3,4,5,6)
c1=0
c2=0
for i in range(0,len(x)):
if x[i]%2==0:
c1=c1+1
else:
c2=c2+1
if c1>0:
print("total even",c1)
if c2>0:

print("total odd=",c2)

4. x=(2,3,4,5,6)
c1=0
c2=0
for i in range(0,len(x)):
if x[i]%2==0:
c1=c1+1
else:
c2=c2+1
if c1>0:
print("total even",c1)
if c2>0:

print("total odd=",c2)

5. Q:- WAP to find the max element in Tuple ??
t=(15,65,98,78,25,32)
max=0
for i in range(0,len(t)):

if t[i]>max:
max=t[i]
print("The Largest Number is :- ",max)

6. Q:- WAP to divide even elements and odd elements separately in a tuple ??
x=(2,3,4,5,6)
for i in range(0,len(x)):
if x[i]%2==0:
print("Even Number :=",x[i])
else:
print("Odd Number :=",x[i])

7. Program to find maximum value in tuple-->>
s=(897,1201,3456,34.36,123,345)
t=s
for i in range(0,len(s)):
if s[i]>s:
t=s[i]
print("This value is maximum-",t)

output-This value is maximum- 3456

8. x=(100,103,215,67,90)
for i in range(0,len(x)):
if x[i]%2==0:
print("Even Number-",x[i])
else:
print("Odd Number-",x[i])

9. DOUBT-->>
Sir divide even elements and odd elements separately in a tuple,iss program mein user input se kaise kare?????

Isme append karna padh raha hai,but phir bhi execute nahi ho raha hai-->

a=[]
n=int(input("Enter number of elements-"))
even=[]
odd=[]
for i in range(0,n):
b=int(input("Enter element-"))
a.append(b)
for j in a:
if(j%2==0):
print("even numbers list-",even)
else:
print("odd numbers list-",odd)

10. Program to count even and odd numbers in tuple-->>

x=(23,34,56,78,90,91,65,73)
y=0
z=0
for i in range(0,len(x)):
if x[i]%2==0:
y=y+1
else:
z=z+1
print("Total even numbers=",y)
print("Total odd numbers=",z)

11. Program to count total integer,float,string,boolean in tuple-->>

x=(121,234,341,98.49,"Python","Java", True,"I bought 3 burgers")
cint=0
cfloat=0
cstring=0
cbool=0
for i in range(0,len(x)):
if type(x[i]).__name__=="int":
cint=cint+1
elif type(x[i]).__name__=="float":
cfloat=cfloat+1
elif type(x[i]).__name__=="string":
cstring=cstring+1
elif type(x[i]).__name__=="bool":
cbool=cbool+1
print("total integers=",cint,"total floats=",cfloat,"total strings=",cstring,"total booleans=",cbool)

12. deependra singh jadaunNovember 26, 2020 at 3:35 PM

wap to find max digit from given tuple or list:

x=(1,2,3,4,5,4,3,7,50,-1)
y=0
for i in x:
if i>y:
y=i
print(y)

13. deependra singh jadaunNovember 26, 2020 at 3:50 PM

wap to divide eeven and odd nos. from a single given tuple:

x=(1,2,3,4,5,6,8,7,9)
x1=[]
x2=[]
for i in x:
if i%2 ==0:
x1.append(i)

else:
x2.append(i)
print(x1)
print(x2)

14. deependra singh jadaunNovember 26, 2020 at 9:56 PM

wap to find first five max. nos. from given list:

x=(1,2,3,4,5,6,7,8,20,18,0,13)
y=0
z=0
t=0
p=0
m=0
for i in x:
if i>y:
m=p
p=t
t=z
z=y
y=i

elif i>z:
m=p
p=t
t=z
z=i
elif i>t:
m=p
p=t
t=i
elif i>p:
m=p
p=i
elif i>m:
m=i
print(y)
print(z)
print(t)
print(p)
print(m)

15. # PYTHON( 6 To 7 PM BATCH)
# CODE to Find the Max Element in Tuple

a = (8,9,101,5,7,3,5,99,11,54,67)
e = 0
c = a

for b in a:
if b>c:
c=b
print("Max Element :-\t",c)

16. # PYTHON( 6 To 7 PM BATCH)
# CODE to divide Even Elements and Odd Elements Separately in a Tuple.

a = (8,9,101,6,7,4,5,99,11,54,67)
e = []
o = []

for b in a:
if b%2==0:
e.append(b)
if b%2!=0:
o.append(b)

even = tuple(e)
odd = tuple(o)

print("EVEN Number:-",even)
print("ODD Number :-",odd)

17. # PYTHON( 6 To 7 PM BATCH)
# CODE to Count Total even Number and Odd Number in Tuple.

a = (8,9,101,6,7,4,5,99,11,54,67)
e = 0
o = 0

for b in a:
if b%2==0:
e+=1
if b%2!=0:
o+=1

print("Total EVEN Number:-",e)
print("Total ODD Number :-",o)

18. # WAP to find the max element on Tuple?

x=(5,9,2,6,1)
max=0
for i in range(0,len(x)):
if x[i]>max:
max=x[i]
print(max)

# WAP to divide even elements and odd elements separately in a tuple?

x=(2,5,4,7,3,8,10)

for i in range(0,len(x)):
if x[i]%2==0:
print(x[i],"even")
else:
print(x[i],"odd")

# WAP to count total even number and Odd number in Tuple?

x=(2,5,4,7,3,8,10)
even=0
odd=0
for i in range(0,len(x)):
if x[i]%2==0:
even+=1
else:
odd+=1
if even>0:
print("total even",even)
if odd>0:
print("total odd",odd)

19. # WAP to count total integer, float, and string in a tuple?

t=(12.22,5,1,2.1,"hello","hi",True)
vint=0
vfloat=0
vstr=0
vbool=0
for i in range (0,len(t)):
if type(t[i]).__name__=="int":
vint+=1
elif type(t[i]).__name__=="float":
vfloat+=1
elif type(t[i]).__name__=="bool":
vbool+=1
elif type(t[i]).__name__=="string":
vstr+=1
print("integer = ",vint,"float = ",vfloat,"string = ",vstr,"bool = ",vbool)

20. #Shivam Shukla
#1) WAP to find the max element on Tuple?
tup=(1,6,4,6,8,6,9)
val=0
for i in tup:
if(val<i):
val=i;
print(val)

21. #Shivam Shukla
#2) WAP to divide even elements and odd elements separately in a tuple?
tup=(1,5,3,8,6,9,3,2)
even=[]
odd=[]
for i in tup:
if(i%2==0):
even.append(i);
continue
odd.append(i)
print("Even :",even)
print("Odd :",odd)

22. #Shivam Shukla
#3) WAP to count total even number and Odd number in Tuple?
tup=(1,5,3,8,6,9,3,2)
even=0
odd=0
for i in tup:
if(i%2==0):
even+=1
continue
odd+=1
print("Even :",even)
print("Odd :",odd)

23. #Shivam Shukla
#4-4.1) the program to show five max digite numbers?? (but ristricted only possitive number's but not include zero's)
tup=(5,8,8,5,5,5,8,8,5,9,9,9,9,9,9,5,0,5,9,0)
lst=[]
find=int(input("How many max numbers are you finding here : "))
ctup=0
for i in tup:
ctup+=1
holdExect=0
for i in range(0,find):
hold=0
for j in range(0,ctup):
if(hold<=tup[j] and (i==0 or tup[j]<holdExect)):
hold=tup[j]
if(hold!=0):
holdExect=hold;
lst.append(hold);
print(lst)

24. #Shivam Shukla
#4-4.2) the program to show five max digite numbers?? (but ristricted only possitive number's with zero's)
tup=(5,8,8,5,5,5,8,8,5,9,9,9,9,9,9,5,0,5,9,0,-1,-5)
lst=[]
find=int(input("How many max numbers are you finding here : "))
ctup=0
for i in tup:
ctup+=1
holdExect=0
for i in range(0,find):
hold=-1
for j in range(0,ctup):
if(hold<=tup[j] and (i==0 or tup[j]<holdExect)):
hold=tup[j]
if(hold!=-1):
holdExect=hold;
lst.append(hold);
print(lst)

25. #Shivam Shukla
#4-4.3) the program to show five max digite numbers?? (without any ristricted - allShow's, if in a criteria)
tup=(5,8,8,5,5,5,8,8,5,9,9,9,9,9,9,5,0,5,9,0,0,0,-5,-7)
lst=[]
find=int(input("How many max numbers are you finding here : "))
ctup=0
for i in tup:
ctup+=1
holdExect=0

val=tup
for i in range(1,ctup):
if(val>tup[i]):
val=tup[i];

for i in range(0,find):
hold=val-1
for j in range(0,ctup):
if(hold<=tup[j] and (i==0 or tup[j]<holdExect)):
hold=tup[j]
if(hold!=val-1):
holdExect=hold;
lst.append(hold);
print(lst)

26. #Shivam Shukla
#5) WAP to count total of integer, float, string, and bool value's in a tuple?
#5.1 >>theMyWay | without any predefined function's
t = (12,23,34,45.67,"hello", "welcome", True);
cint=cfloat=cstring=cbool=0;
for element in t:
org=str(element);
k1=k2=0;
intfloat=string=0;
count=0;
for l in org:
count+=1;
for i in org:
if(element==True or element==False):
cbool+=1
break;
elif(((ord(i)>=65 and ord(i)<=90) or (ord(i)>=97 and ord(i)<=122) or (ord(i)=='.' and k2==0)) and (k1==0 or k1==1)):
k1=1;
string+=1;
elif(((ord(i)>=48 and ord(i)<=57) or (i=='.')) and (k1==0 or k1==2)):
k1=2;
if(i=='.'):
k2+=1;
intfloat+=1;
if(k1==2 and count==intfloat):
if(k2==0):
cint+=1;
if(k2==1):
cfloat+=1;
continue;
if(k1==1 and count==string):
cstring+=1
print("int :",cint,"\nfloat :",cfloat,"\nstring :",cstring,"\nbool :",cbool)

27. #Shivam Shukla
#5) WAP to count total of integer, float, string, and bool value's in a tuple?
#5.2 >>theMyWay | without any predefined function's
t = (12,23,34,45.67,"hello", "welcome", True);
cint=cfloat=cstring=cbool=0;
for element in t:
if(element==True or element==False):
cbool+=1;
continue;
org=str(element);
k1=k2=0;
intfloat=string=0;
count=0;
for l in org:
count+=1;
for i in org:
if(((ord(i)>=65 and ord(i)<=90) or (ord(i)>=97 and ord(i)<=122) or (ord(i)=='.' and k2==0)) and (k1==0 or k1==1)):
k1=1;
string+=1;
if(((ord(i)>=48 and ord(i)<=57) or (i=='.')) and (k1==0 or k1==2)):
k1=2;
if(i=='.'):
k2+=1;
intfloat+=1;
#print();
if(k1==2 and count==intfloat):
if(k2==0):
cint+=1;
if(k2==1):
cfloat+=1;
continue;
if(k1==1 and count==string):
cstring+=1
print("int :",cint,"\nfloat :",cfloat,"\nstring :",cstring,"\nbool :",cbool)

28. #Shivam Shukla
#5) WAP to count total of integer, float, string, and bool value's in a tuple?
#5.3 >>theMyWay | without any predefined function's
t = (12,23,34,45.67,"123","hello", "welcome", True);
cint=cfloat=cstring=cbool=0;
for element in t:
if(element==True or element==False):
cbool+=1;
continue;
org=str(element);
k1=k2=0;
intfloat=string=0;
count=0;
for l in org:
count+=1;
for i in org:
if(((ord(i)>=65 and ord(i)<=90) or (ord(i)>=97 and ord(i)<=122) or (ord(i)=='.' and k2==0)) and (k1==0 or k1==1)):
k1=1;
string+=1;
if(((ord(i)>=48 and ord(i)<=57) or (i=='.')) and (k1==0 or k1==2)):
k1=2;
if(i=='.'):
k2+=1;
intfloat+=1;
if(k1==2 and k2==0 and count==intfloat):
if(org==element):
cstring+=1;
else:
cint+=1;
continue;
if(k1==2 and k2==1 and count==intfloat):
if(org==element):
cstring+=1;
else:
cfloat+=1;
continue;
if(k1==1 and count==string):
cstring+=1;
print("int :",cint,"\nfloat :",cfloat,"\nstring :",cstring,"\nbool :",cbool)

29. #Shivam Shukla
#5) WAP to count total of integer, float, string, and bool value's in a tuple?
#5.4 >>theMyWay | without any predefined function's
s=float(input("Enter any key : "));
t = (12,23,34,45.67,s,"123","hello", "welcome", True);
cint=cfloat=cstring=cbool=0;
for element in t:
#to check bool.....
if(element==True or element==False):
cbool+=1;
continue;
org=str(element);
#to check string.....
if(org==element):
cstring+=1;
continue;
#to check int or float.....
count=0;
for l in org:
count+=1;
k=0;
for i in org:
if((ord(i)>=48 and ord(i)<=57) or (i=='.')):
if(i=='.'):
continue;
k+=1;
if(k==count):
cint+=1;
else:
cfloat+=1;
print("int :",cint,"\nfloat :",cfloat,"\nstring :",cstring,"\nbool :",cbool);

30. WAP to find the max element on Tuple

x=(34,86,27,23,12,90)
m=max(x)
print(m)

31. WAP to divide even elements and odd elements separately in a tuple

x=(1,2,3,4,5,6)
odd=[]
even=[]
for i in range(0,len(x)):
if i%2==0:
even.append(x[i])
else:
odd.append(x[i])
print(tuple(odd))
print(tuple(even))

32. WAP to count total even number and Odd number in Tuple

x=(1,2,3,4,5,6,7,8,9)
odd=[]
even=[]
co=0
ce=0
for i in range(0,len(x)):
if i%2==0:
even.append(x[i])
ce=ce+1
else:
odd.append(x[i])
co=co+1
print(tuple(odd),co)
print(tuple(even),ce)

33. WAP to count total integer, float, and string in a tuple

x=("english",12,34.2,"hindi",32.2,11,12)
ci=0
cf=0
cs=0
for i in range(0,len(x)):
if type(x[i]).__name__=="str":
cs=cs+1
elif type(x[i]).__name__=="int":
ci=ci+1
else:
cf=cf+1
print("count of string is", cs)
print("count of float is", cf)
print("count of integer is", ci)

34. x=(5,7,95,46,26,78)
m=0
for i in x:
if m<i:
m=i
print(m)

35. x=(1,2,3,4,5,6,7,8,9)
t1=[]
t2=[]
for i in range(0,len(x)):
if i%2==0:
t1.append(x[i])
else:
t2.append(x[i])
print(tuple(t1))
print(tuple(t2))

36. x=(1,2,3,4,5,6,7,8,9,10,11,12,13)
t1=[]
t2=[]
c1=0
c2=0
for i in range(0,len(x)):
if i%2!=0:
t1.append(x[i])
c1=c1+1
else:
t2.append(x[i])
c2=c2+1
print(tuple(t1),c1)
print(tuple(t2),c2)

37. x=["grv",12.5,59,"python",97,7.0]
s=0
f=0
i=0
for i in range(0,len(x)):
if type(x[i]).__name__=="str":
s=s+1
elif type(x[i]).__name__=="int":
i=i+1
else:
f=f+1
print("intger values are",i,"string value are",s,"float value are",f)

38. to count total integer, float, and string in a tuple
tupl = (115,55,8,"Indore", "World", False,True,3.2)
i=0
f=0
s=0
b=0

for x in range(0,len(tupl)):
if type(tupl[x]).__name__=="int":
i=i+1
elif type(tupl[x]).__name__=="float":
f=f+1
elif type(tupl[x]).__name__=="str":
s=s+1
elif type(tupl[x]).__name__=="bool":
b=b+1

print("Total integer is ",i )
print("Total float is ", f )
print("Total String is",s )
print("Total boolean is ",b)

39. WAP to count total even number and Odd number in Tuple?
Sol:-t=(1,2,3,4,5,6,7,8,9)
count1=0
count2=0
for i in t:
if i%2==0:
count1=count1+1
else:
count2=count2+1
print("count of even numbers:",count1)
print("count of odd numbers:",count2)