Tuple in Python

65



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[0]= 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[0]=12
#del s[0]
#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),
Tags

Post a Comment

65Comments

POST Answer of Questions and ASK to Doubt

  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)

    ReplyDelete
  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])

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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])

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

    output-This value is maximum- 3456

    ReplyDelete
  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])

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete

  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[0]

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

    ReplyDelete

  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)

    ReplyDelete


  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)

    ReplyDelete
  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)

    ReplyDelete
  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)


    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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[0]
    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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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);

    ReplyDelete
  30. WAP to find the max element on Tuple

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

    ReplyDelete
  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))

    ReplyDelete
  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)

    ReplyDelete
  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)

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

    ReplyDelete
  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))

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  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)

    ReplyDelete
  40. #devide odd and even elements sepreately in tuple?
    x=(2,3,4,5,6,9,34,12)
    for i in range(0,len(x)):
    if x[i]%2==0:
    print("even element are",x[i])
    else:
    print("odd elements are",x[i])

    ReplyDelete
  41. #find the maximum element in a tuple?
    x=(12,23,45,80,67,11,2)
    m=0
    for i in x:
    if m<i:
    m=i
    print("maximun element is",m)

    ReplyDelete
  42. #count total integer,float,and string in tupple?

    t=(12,23,34,45.67,"hello",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__=="string":
    cstring=cstring+1
    elif type(t[i].__name__=="cbool":
    cbool=cbool+1
    print("total integer is",cint,"total float is",cfloat,"total string is",cstring,"total boolean is",cbool,)

    ReplyDelete
  43. # wap to print sum of all elements
    x=([1,2,3,4,5],[3,4])
    s=0
    for i in x:
    for j in i:
    s=s+j
    print(j,end='')
    print()
    print("sum of all elements are",s)

    ReplyDelete
  44. #wap to print only prime number
    x=([1,2,3,4,5],[5,6],(7,8),[5,7,9,6])
    for i in x:
    for j in i:
    for k in range(2,j):
    if j%k==0:
    break
    else:
    if j>1:
    print(j)

    print()

    ReplyDelete
  45. # wap to print reverse number
    x=([2,5,7,9,19,20],(20,12),[12,45,22],[1,2,4,7,8])
    for i in range(3,-1,-1):
    for j in x[i]:
    print(j,end='')
    print()

    ReplyDelete
  46. # reverse multidimensional
    x=([1,5,1,8,2],(8,5,3,7),[55,99,55,41],(7,5,2,2))
    x1=[]
    for i in x:
    x1.append(i)
    print(x1[::-1])

    ReplyDelete
  47. #Wap program to find which type of element in the tuple?

    tpl=(3,6,44,55.55,55.3,"hello","world",True,"Ankit",False)
    cint=0
    cfloat=0
    cstr=0
    cbool=0
    for i in range(0,len(tpl)):
    if type(tpl[i]).__name__=="int":
    cint=cint+1
    elif type(tpl[i]).__name__=="float":
    cfloat=cfloat+1
    elif type(tpl[i]).__name__=="str":
    cstr=cstr+1
    elif type(tpl[i]).__name__=="bool":
    cbool=cbool+1
    print("Total Integer is ",cint,"Total float is ",cfloat,"Total string is ",cstr,"Total boolean is ",cbool)

    ReplyDelete
  48. #Wap program to find max Element in Tuple?
    tpl=(111,44,33,212,54)
    maxxi=0
    for o in tpl:
    if maxxi<o:
    maxxi=o
    print("Maximum Elements is ",maxxi)

    ReplyDelete
  49. #Wap to find sum of element?
    tpl=([1,2,4,3],(4,6),[7,8],[5,5,37,6])
    s=0
    for i in tpl:
    for j in i:
    s=s+j
    print(j,end='')
    print()
    print("sum of all element are ",s)

    ReplyDelete
  50. #Wap to find prime Element in Tuple?
    tpl=([2,4,33,55,6],(5,7),[5,9],[1,3,5,6,7,0])
    c=0
    for i in tpl:
    for j in i:
    for k in range(2,j):
    if j%2==0:
    break
    else:
    if j>1:
    print("prime",j)
    c=c+1
    print()
    print("Total Prime Element is ",c)

    ReplyDelete
  51. #Wap to Reverse Tuple?
    tpl=([23,4,3,5,6],(44,33),[5,4,2],[6,5,4,3,2],[23,55,43,65,60],(1,2,3,4,5))
    for i in range(5,-1,-1):
    for j in tpl[i]:
    print(j,end=' ')
    print()

    ReplyDelete
  52. #Wap to Addition of two Matrix in Tuple?
    tpl=[(1,2,3),[1,5,4]]
    tpl1=[[1,7,5],(6,7,8)]
    tpl2=([0,0,0],[0,0,0])
    for i in range(0,len(tpl)):
    print(i)
    for j in range(0,len(tpl[0])):
    #print(j)
    tpl2[i][j]=tpl[i][j]+tpl1[i][j]
    print(tpl2)

    ReplyDelete
  53. #Wap Find Even and odd element in Tuple?
    tpl=([2,3,4,7,67],(4,5,8,77),[1,5,4,6,7,9])
    e=0
    o=0
    for i in range(0,len(tpl)):
    for j in tpl[i]:
    if j%2==0:
    e=e+1
    else:
    o=o+1

    print("Even",e)
    print("odd",o)

    ReplyDelete
  54. #Program to add two matrices

    x=[[2,4,5],
    [4,6,6],
    [7,8,9]]

    y=[[5,4,8],
    [14,9,8],
    [45,8,19]]
    r=[[0,0,0],
    [0,0,0],
    [0,0,0]]

    for i in range(len(x)):
    for j in range(len(y)):
    r[i][j]=x[i][j]+y[i][j]

    for k in r:
    print(k)

    ReplyDelete
  55. #Program to multiply two matrices

    x=[[2,4,5],
    [4,6,6],
    [7,8,9]]

    y=[[5,4,8],
    [14,9,8],
    [45,8,19]]
    r=[[0,0,0],
    [0,0,0],
    [0,0,0]]

    for i in range(len(x)):
    for j in range(len(y)):
    r[i][j]=x[i][j]*y[i][j]

    for k in r:
    print(k)

    ReplyDelete
  56. # addition of two matrix
    x=[(1,2),(3,4)]
    y=[(4,5),(6,7)]
    res="["
    for i in range(0,len(x)):
    for j in range(0,len(x)):
    res=res+str(x[i][j]+y[i][j])+""
    if i==1:
    res=res+"]"
    else:
    res=res+"\n"
    print(res)

    ReplyDelete
  57. #Find Prime Elements in a Tuple using For in loop?

    tpl=(4,3,7,11,6)
    c=0
    for i in tpl:
    if i%2==0:
    print("not prime",i)
    c=c+1
    else:
    if c==1:
    print("prime",i)

    print(c)


    ReplyDelete
  58. #wap to count total integer ,float and string in a tuple?
    x=(2,3,5,3.6,5.5,"anvi",'vini',True)
    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__=="str":
    cstring=cstring+1
    elif type(x[i]).__name__=="bool":
    cbool=cbool+1
    print("total intger is ",cint,"total float is",cfloat,"total string",cstring,"total boolean is",cbool)

    ReplyDelete
  59. # wap to count even and odd number in tuple?
    x=(2,3,4,5,6)
    e=0
    o=0
    for i in range(0,len(x)):
    if x[i]%2==0:
    e=e+1
    else:
    o=o+1
    print("total even number is",e)
    print("total odd number is",o)

    ReplyDelete
  60. # wap to divided even ele and odd ele separately in a tuple?
    x=[2,3,4,5,23]
    for i in x:
    if i%2==0:
    print("even number",i)
    else:
    print("odd number",i)

    ReplyDelete
  61. x=(12,23,45,67,11,2)
    m=0
    for i in x:
    if m<i:
    m=i
    print("max ele of list is",m)

    ReplyDelete
  62. # wap to find the max ele,second max,third max ele on tuple?
    x=(23,45,67,89,100,98,111)
    m=0
    sm=0
    tm=0
    for i in x:
    if m<i:
    tm=sm
    sm=m
    m=i
    elif sm<i:
    tm=sm
    sm=i
    elif tm<i:
    tm=i
    print("maximum ele is",m)
    print("second max ele is",sm)
    print("third max ele is",tm)



    ReplyDelete
  63. # tuple using for each loop?
    n=("c","java","python","html")
    for value in n:
    print(value)

    ReplyDelete
  64. # wap to count total positive and negative digit in tuple?
    x=(2,5,3,-6,-9)
    cp=0
    cn=0
    for i in range(0,len(x)):
    if x[i]>=0:
    cp=cp+1
    else:
    cn=cn+1
    print("total positive digit is",cp)
    print("total negative digit is",cn)

    ReplyDelete
  65. WAP to count total even number and Odd number in Tuple?

    t=(1,2,3,4,5,6,7,8,9,10)
    ev=0
    od=0
    for i in t:
    if i%2==0:
    ev=ev+1
    else:
    od=od+1
    print(t)
    print("Total even numbers are: ",ev)
    print("Total odd numbers are: ",od)

    ReplyDelete
Post a Comment