Python Programming Quiz

Quiz on Tuples in Python

Time left: 300 seconds

Q.1. Tuples can contain data of multiple data types

Select Your Option

A tuple can have any number of items and they may be of different types (integer, float, list, string, etc.)

Q.2. What is the output of following program?
          
            tup = ['America', 'Africa', 'Antartica', 'Alaska']
            print(min(tup))
          
          

Select Your Option

The min() function is widely used to find the smallest value present in an iterable. For the values of the given tuple, Python checks the ASCII values of the first letters and chooses the smallest one. If more than one element has the same values, Python checks the following letters in the same fashion.

Q.3. What is the output of following program?
          
            t1 = (1,2,3,4,5)
            t2 = (6,7,8,9,10)
            t = tuple(map(sum, zip(t1, t2)))
            print(t)
          
          

Select Your Option

The given code maps the sums of corresponding elements of the tuples t1 and t2 to a new tuple.

Q.4. Which statement of the following is false?

Select Your Option

2 lists cannot be directly subtracted in Python. However, modules such as numpy and zip or looping statements can be used to subtract two lists.

Q.5. What is the output of following program?
          
            t = (1, 2, 3, 4) 
            t.append( (5, 6, 7) ) 
            print(len(t))
          
          

Select Your Option

As tuples are immutable, there is no append() function available for tuples.

Q.6. Which of the following is the correct syntax to get "(76,23,16,42,89)" as output?
l = (78,54,76,23,16,42,89,12,56,87)

Select Your Option

You must slice a tuple in order to access a range of elements in it. The given code prints elements from index 2 to index 6.

Q.7. Initializing a tuple as " t = [1,True,"Hello",5.6] " would not give an error

Select Your Option

The given initialization will not give an error however, t is initialized as a list instead of a tuple.

Q.8. With a list " t = ((1,(11,12)),((31,32),4),(5,6,(71,72))) ",
Which of the following will give output as 32?

Select Your Option

The index of the value 32 is t[1][0][1].

Q.9. What is the output of following program?
          
            t = ("Vehicle",12,67.8)
            print(type(t))
          
          

Select Your Option

The type() function is used to get the type of an object. Here, the object type of t is tuple.

Q.10. What would be the output of following program?
          
            t = (65,3,6,75,4,36,67,56,54)
            t.pop()
            print(t)
          
          

Select Your Option

Tuples are immutable. Hence, tuple objects do have the function pop(). Hence, the program will give an error.

Q.11. Determine Output of the following snippet of code:
          
            l = (45.7,12,35.8,True*3,32.8)
            print(l[0]+l[1]+l[2])
          
          

Select Your Option

The print statement adds the vlaues at indices 0, 1, and 2 of the tuple.

Q.12. Whats the total number of elements, max number of rows and columns in the list given below:
t = ((1,(11,12)),((31,32),4),(5,6,(71,72)))

Select Your Option

There are total 10 elements, 3 rows and 3 maximum columns in the given tuple.

Q.13. What will be the output of following program?
          
            t = "Apple", 55, "Car", 67
            a, b, c = t
            print(b)
          
          

Select Your Option

Unpacking tuples means assigning individual elements of a tuple to multiple variables. However, in the second statement we are trying to unpack 4 variables but we have provided only 3 individual variables for assignment. This results in an error.

Q.14. What will be the output of following program?
          
            t = (100,)
            print(t * 5)
          
          

Select Your Option

The * operator works as the repetition operation in the given context of the program. Hence, the value of the tuple is repeated 5 times when printing.

Q.15. What will be the output of following code:
          
            t = (3,6,9,12,15,18)
            print(tuple(sorted(t,reverse=True)))
          
          

Select Your Option

The sorted() function returns a sorted list of the specified iterable object. Here, we are sorting the tuple in descending order and printing it.

Instructions:-

  1. This Quiz is based on Tuples in Python
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post