Skip to main content

GRADE XI : TUPLES REVISION QUESTIONS

 

TUPLES

PRACTICE QUESTIONS


1.# Find the output:

tuple1 = (15, 25, 35, 45, 55, 65)  # Given tuple

list1 = list(tuple1)  # Convert tuple to list

new_list = []

for i in list1:

    if i % 5 == 0:

           new_list.append(i)

new_tuple = tuple(new_list)

print(new_tuple)


2.#Give Output of the following code:

Tuple1 = (5,6,-1,3)

Tuple2 = (7,8,4,-9)

Tuple3=()

i=0

while i<4:

    if(Tuple1[i]–Tuple2[i])%2==0:

        Tuple3+=(Tuple1[i] + 2 * Tuple2[i],)

    else:

        Tuple3+=(2*Tuple1[i] –Tuple2[i],)

    i+=1

print(Tuple3)


3.#Give Output of the following code:

t=(3.5,1.2,2.6,4.8)

L=list(t)

count=0

for x in L:

    L[count]+=int(x)+count

    count+=1

print(L)


4.#Give Output of the following code:

t1=(3.5,8,"computer","SCIENCE",False)

t2=()

for c in t1:

    if type(c) == int:

        t2+=(3*c,)

    elif type(c)==float:

        t2+=(int(c) **2,)

    elif type(c)==str:

        if c.islower():

            t2+=(c.capitalize(),)

        else:

            t2+=(c.lower(),)

    elif type(c)==bool:

        if c==False:

            t2+=("0",)

        else:

            t2+=("1",)

print(t2)


5.#Give Output of the following code:

t1=("This",[9,34,53],"of" ,"new" ,"chapter")

print(t1[1][2:4])

print(t1[:1]+t1[1:])

print(t1[1::2])

print(t1[3][0] in t1[1])


6.#Give Output of the following code:

T1=(45, 6, 86, 9)

a,b,c,d= T1

a=a*2

b=b+2

c=c-2

d=d+2

T1=T1[:1]+(a,)+T1[1:2]+(b,)+T1[2:3]+(c,)+T1[3:]+(d,)

print(T1)

7.#Give Output of the following code:

T1=(2,4,6,8,9,10,15)

i=1

while i<=5:

    if (T1[i]%2==0):

        T1 = T1[:i]+ T1[i+1:]

        i+=1

    i+=1

print(T1)

8.#Give Output of the following code:

t1=(2,45.5,"PYthOn",90,"c",False)

t2=( )

for i in t1:

    if type(i)== float:

        t2+=(i+2,)

    elif type(i)== int:

        t2+= ((i%3),)

    elif type(i)== str:

        if i.islower():

            t2+= (chr(ord(i)+2),)

        else:

            t2+=(i.lower(),)

    elif type(i)== bool:

        if i==True:

            t2+=("*",)

        else:

            t2+=("#",)

print(t2)

9. Rewrite the following program after removing the error. Underline each corrections made.

tuple1=tuple(1,2,3,4)

for i in range(len(tuple1)

               num=int(input(“Enter the element”))

               tuple1+=(num)

               if tuple1[i]<10:

                   tuple1[i]=20

10. Given the tuple tupl = (15, 25, 35, 45, 55, 65, 75, 85, 95)

what will be the output of:

print(tupl[2:8:3])

Comments

Popular posts from this blog

CS - SORTING/SEARCHING ALGORITHMS

  SORTING ALGORITHMS                       SORTING ALGORITHM PDF LINK #Bubble Sort          ·        The outer loop iterates through the entire array. ·        The inner loop compares adjacent elements and swaps them if they are out of order. ·        The outer loop runs n times, and each pass moves the largest element to its correct position. arr=[3,8,5,2,1] n = len(arr) print(n) for i in range(n):  #traverse through all the elements         # Last i elements are already sorted, no need to check them         for j in range(0, n-i-1):              # Swap if the element found is greater than the next element              if arr[j] > arr[j+1]:               ...

GRADE XI - NESTED FOR LOOP

                                                         NESTED FOR LOOP 1. for var1 in range(3):      print(var1,"OUTER LOOP")          # 0 outer loop       1 outer loop      2 outer loop          for var2 in range(2):                  print(var2+1,"INNER LOOP")    #1  2 inner loop     1  2  inner loop   1 2 inner loop  2. Print the following pattern using for loop: 1  1 2  1 2 3  1 2 3 4  Sol: for r in range(1,5):   #ROWS     for c in range(1,r+1):   #COLUMNS         print(c,end=" ")     print() 3. Print the following pattern using for loop: @  @ @  @ @ @...