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

PYTHON - MYSQL CONNECTIVITY CODE

  #INSERTION OF DATA import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", passwd="root", database="school" ) print("Successfully Connected") #print(mydb) mycursor=mydb.cursor()   v1=int(input("enter ID:")) v2=input("enter name:") v3=input("enter Gender:") v4=int(input("enter age:")) sql='insert into TEACH values("%d","%s","%s","%s")'%(v1,v2,v3,v4) print(sql) mycursor.execute(sql) mydb.commit() print("record added") #MYSQL Connection code – Deletion on database SOURCE CODE: s=int(input("enter id of TEACHER to be deleted:")) r=(s,) v="delete from TEACH where id=%s" mycursor.execute(v,r) mydb.commit() print("record deleted") MYSQL Connection code – Updation on database SOURCE CODE: import mysql.connector mydb = mysql.connector.c...

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...