1. Crete a numeric tuple using for loop and while loop.
Find the number of elements in the tuple.
Find the minimum element in the tuple.
Find the maximum element in the tuple.
Find sum,average,total of tuple.
Print the tuple in reverse.
Print tuple elements along with indexes.
tup = (1,2,3,4,5,6,7,8,9,0,11,22,33,44)
##the number of elements in the tuple.
print("number of elements :",len(tup))
##the minimum element in the tuple.
print("minimum value :",min(tup))
##the maximum element in the tuple.
print("maximum value :",max(tup))
##sum,average,total of tuple.
print("sum :",sum(tup),"Average :",sum(tup)/len(tup))
## using list because tuple is immutable
##tuple in reverse.
lit = list(tup)
lit = reversed(lit)
print("tuple in reverse :",tuple(lit))
##tuple elements along with indexes.
for i in range(len(tup)):
print(str(i)+"--"+str(tup[i]))
    2. Create tuple of strings and find the largest string.
    s = ("hi","hello","world","rgukt","welcome123")
    b,c = 0,""
    for i in s:
    if len(i) >= b:
    c = i
    b = len(i)
    print(c)
      3. Create a tuple and do alternative code for
      adding element to tuple at last.
      adding element at particular index.
      Deleting tuple element.
      Changing a tuple element.
      ## it is impossible to edit a tuple.
      ##adding element to tuple at last.
      a = (0,1,2,3,4,5,6,7,8,9)
      a = list(a)
      a.append(100)
      print(tuple(a))
      ##adding element at particular index.
      a.insert(1,23)
      print(tuple(a))
      ##Deleting tuple element.
      a.remove(6)
      print(tuple(a))
      ##Changing a tuple element.
      a.sort()
      print(tuple(a))
        4. Take a numeric tuple and create a new tuple with its binary numbers.
        a = (11,22,33,44,55,66,1,2,4,8,16,32)
        t = []
        for i in a:
        n = bin(i) ##converts to binary
        t.append(n[2:]) ## removes "0b" from the binary form
        print(tuple(t)) ## converts to tuple
          5. T=((11,22,33),(44,55,66)), write code to create tuple with the sum of associated elements.
          T = ((11,22,33),(44,55,66))
          l = []
          for i in range(3):
          l.append(T[0][i]+T[1][i])
          print(tuple(l))
            6. T= (11,22,33,44,55,66,77,88,99), create two tuple one with odd numbers and second with even numbers.
            T = (11,22,33,44,55,66,77,88,99)
            new1 = []
            new2 = []
            for i in T:
            if i%2 == 0:
            new1.append(i)## it stores even values
            else:
            new2.append(i)## it stores odd values
            print("Even tuple :",tuple(new1),"Odd tuple :",tuple(new2))
              7. Verify whether all the elements in the tuple equal or not.
              a = (1,1,1,1,1,1,1)
              b = (1,1,1,2,3)
              for i in range(1):
              for j in range(len(a)):
              if a[i] != a[j]:## change a to b
              break
              else:
              print("all elements are Equal")
                8. Take two tuples and create a new tuple with other two tuple elements (do not use +)
                t1 = (11,22,33,44,55,66,77,88,99)
                t2 = (1,2,3,4,5,6,7,8,9)
                t3 = list(t1)
                for i in t2:
                t3.append(i)
                print(tuple(t3))
                  9. Take a tuple and create a new tuple without duplicates.
                  t = (1,1,1,2,3,2,3,2,4,5,7,9,8,7,9,7,5,4,3,5)
                  t = set(t)
                  t = tuple(t)
                  print(t)
                  ## or
                  t = tuple([*set(t)])
                  print(t)
                    10. Take a tuple of different data types and count strings,int,float,list etc.
                    a = (1,2,3,4,"hello","good","morning","friends",1.23,3.14,55.43,(1j),(54j),[1.1,1.2,1.3],["hi","hello"],[1,2,3],("a","b","c"),(101,102))
                    n = f = c = s = l = t = 0
                    for i in a:
                    if type(i) == type(1):
                    n = n+1
                    if type(i) == type(1.5):
                    f = f+1
                    if type(i) == type((1j)):
                    c = c+1
                    if type(i) == type("1"):
                    s = s+1
                    if type(i) == type([]):
                    l = l+1
                    if type(i) == type(()):
                    t = t+1
                    print("Integers :",n,"\nFloat :",f,"\nComplex :",c,"\nstrings :",s,"\nLists :",l,"\nTuples :",t)
                      11. Create a tuple ,where each element must be a list.
                      a = ([1],[1,1.5],["hello","world"],[(6j),1],["python"],["rgukt"])
                      print(a)
                        12. Create a list of tuples where each tuple should have a number and its square as a pair.
                        a = [(x,x**2) for x in range(1,11)]
                        ## () -- DEFINES a tuple
                        print(a)
                          13. .Take a tuple with different data types and create separate tuple for each data type separately.
                          a = (1,2,3,4,"hello","good","morning","friends",1.23,3.14,55.43,(1j),(54j),[1.1,1.2,1.3],["hi","hello"],[1,2,3],("a","b","c"),(101,102))
                          n,f,c,s,l,t = [],[],[],[],[],[]
                          for i in a:
                          if type(i) == type(1):
                          n.append(i)
                          if type(i) == type(1.5):
                          f.append(i)
                          if type(i) == type((1j)):
                          c.append(i)
                          if type(i) == type("1"):
                          s.append(i)
                          if type(i) == type([]):
                          l.append(i)
                          if type(i) == type(()):
                          t.append(i)
                          print("Integers :",tuple(n),"\nFloat :",tuple(f),"\nComplex :",tuple(c),"\nstrings :",tuple(s),"\nLists :",tuple(l),"\nTuples :",tuple(t))
                            14. Take a tuple of strings and count the total characters of all the strings in the tuple.
                            a = ("123@abc","hello","welcome","@@@@@@","learn python","good morning")
                            for i in a:
                            print(a[i],len(a[i]))
                              15. Take an integer tuple and create new tuple with their float values.
                              a = (11,22,33,44,55,66,77,88)
                              b = []
                              for i in a:
                              b.append(float(i))
                              print(tuple(b))
                                16. Take an even length tuple and print the difference of adjacent elements.
                                a = (1,8,6,4,0,8,3,2,6,5)
                                for i in range(1,len(a)-1):
                                print(a[i-1]-a[i+1])
                                  17. Take a tuple with different data types and print tuple only with strings,integers and float values.
                                  a = (1,2,3,4,"hello","good","morning","friends",1.23,3.14,55.43,(1j),(54j),[1.1,1.2,1.3],["hi","hello"],[1,2,3],("a","b","c"),(101,102))
                                  n = []
                                  for i in a:
                                  if type(i) == type(1) or type(i) == type(1.5) or type(i) == type("1"):
                                  n.append(i)
                                  a = tuple(n)
                                  print(a)
                                    18. Take two numeric tuples.
                                    Create new tuple with common elements.(Intersection)
                                    Create new tuple with all the elements.(Union)
                                    a = (1,22,3,4,55,6,77,8,99,0)
                                    b = (11,22,33,44,55,66,77,88,99,100)
                                    inter = []
                                    union = list(a)
                                    for i in a:
                                    if i in b:
                                    inter.append(i)
                                    for j in b:
                                    if j not in a:
                                    union.append(j)
                                    print(inter,union)
                                      19. Take a numeric tuple and create a new tuple by sorting based on number of digits.
                                      tup = (5,6,99,7,54,3,2,12,34,55,77,90,77,65,11,22,665,43,234,221,101)
                                      b = sorted(list(tup))
                                      tup = tuple(b)
                                      print(tup)
                                        20. Take a tuple and clear all the elements without using clear method. (code must be logic based).
                                        a = (1,2,3,4,5,6,7,8,9,0)
                                        print(a)
                                        a = ()
                                        print(a)
                                          21. Take a tuple with number and create a new tuple with sum of digits of each number.
                                          a = (11,2222,333,44444,555,66,7677,887688,999)
                                          b = []
                                          for i in a:
                                          summ = 0
                                          i = str(i)
                                          for j in i:
                                          summ = summ+int(j)
                                          b.append(summ)
                                          print(tuple(b))
                                            22. Take two numeric tuples and perform OR operator on same indexed elements, store the result in a new tuple.
                                            tup1 = (0,88,33,44,0,78,5,0,24,12)
                                            tup2 = (0,54,76,45,34,223,112,23,55,22)
                                            new = []
                                            for i in range(len(tup1)):
                                            new.append(tup1[i] or tup2[i])
                                            print(tuple(new))
                                              23. Take an integer tuple, count the each element occurrences, pair it as tuple, create new tuple with pairs.
                                              tup = (1,1,1,2,2,3,33,4,5,6,6,5,7,8,9,6,7,7,4,5,3,9,10)
                                              new = []
                                              for i in tup:
                                              if i not in new:
                                              new1 = [i for j in range(tup.count(i))]
                                              new1 = tuple(new1)
                                              if new1 not in new:
                                              new.append(new1)
                                              new = tuple(new)
                                              print(new)
                                                24. Take two tuple of same length and verify both are equal or not.
                                                a = (1,2,3,4,5,6)
                                                b = (1,2,3,4,5,6)
                                                if len(a) == len(b):
                                                for i in range(len(a)):
                                                if a[i] != b[i]:
                                                print("Not equal")
                                                break
                                                else:
                                                print("Equal")
                                                else:
                                                print("Not equal")
                                                  25. Develop python code to repeat a tuple based on input number times.
                                                  tup = (1,2,3,45,6,7)
                                                  n = int(input())
                                                  dup = tup
                                                  for i in range(1,n):
                                                  tup = tup+dup
                                                  print(tup)
                                                    26. Take a nested tuple of integers
                                                    sort each sub tuple.
                                                    Print last elements of each sub tuple.
                                                    Print the total of all the sub tuples.
                                                    a = ((1,2,3,4,0),(11,22,3,44,5),(-111,-23,-345,-4567),(100,100,10),(11,1),(66,99,66,99,66,99),(109,202,106,404),(9,99,-99,99))
                                                    for i in range(len(a)):## sort each sub tuple.
                                                    new = sorted(a[i])
                                                    a = list(a)
                                                    a[i] = tuple(new)
                                                    a = tuple(a)
                                                    print(a)
                                                    print("last elements of each sub tuple.")
                                                    for i in a:## last elements of each sub tuple.
                                                    print(i[-1:])
                                                    print("the total of all the sub tuples.")
                                                    for i in a:## the total of all the sub tuples.
                                                    print(sum(i))
                                                      27. Take tuple of strings.
                                                      Count the number of words in the tuple.
                                                      Create a new string with first character in sub tuple.
                                                      Print sub tuples without special characters.
                                                      tup = ("hello","hello world","print python","welcome","workshop","123@abcd")
                                                      length = len(tup) ## Count the number of words in the tuple.
                                                      print(length)
                                                      new = ""
                                                      for i in tup:## Create a new string with first character in sub tuple.
                                                      new = new+str(i[:1])
                                                      print(new)
                                                      for i in tup:## sub tuples without special characters.
                                                      store = []
                                                      for j in i:
                                                      if chr(65) <= j <= chr(90) or chr(97) <= j <= chr(122) or chr(48) <= j <= chr(57):
                                                      store.append(j)
                                                      print(tuple(store))
                                                        28. Take a tuple of single characters.
                                                        Create new tuple with their ascii values
                                                        Create new tuple with only special characters.
                                                        Create a new tuple with change cases.
                                                        tup = ("1","v","A","4","Y","s","Z","e","5","@","[","&","}","$","6")
                                                        new = []
                                                        for i in tup:## new tuple with their ascii values
                                                        new.append(ord(i))
                                                        print(tuple(new))
                                                        spe = []
                                                        for j in tup:## new tuple with only special characters.
                                                        if chr(65) <= j <= chr(90) or chr(97) <= j <= chr(122) or chr(48) <= j <= chr(57):
                                                        pass
                                                        else:
                                                        spe.append(j)
                                                        print(tuple(spe))
                                                        tupnew = []
                                                        for i in tup:## new tuple with change cases.
                                                        if i.islower() == True:
                                                        tupnew.append(i.upper())
                                                        elif i.isupper() == True:
                                                        tupnew.append(i.lower())
                                                        else:
                                                        tupnew.append(i)
                                                        print(tuple(tupnew))

                                                          *Questions Prepared by--Srikanth.D

                                                          Mentor in IT,Dept of IT,RGUKT-SRIKAKULAM
                                                          duppada8@rguktsklm.ac.in

                                                              30

                                                              Projects

                                                              300

                                                              Minutes Of Support

                                                              5

                                                              Hard Worker