114 solutions available
Question 1Why are tuples called immutable types?
Question 2What are mutable counterparts of tuple?
Question 3What are different ways of creating a tuple?
Question 4What values can we have in a tuple? Do they all have to be the same type*?
Question 5How are individual elements of tuples accessed?
Question 6How do you create the following tuples?(a) (4, 5, 6)(b) (-2, 1, 3)(c) (-9, -8, -7, -6, -5)(d) (-9, -10, -11, -12)(e) (0, 1, 2)
Question 7If a = (5, 4, 3, 2, 1, 0) evaluate the following expressions:(a) a[0](b) a[1](c) a[a[0]](d) a[a[-1]](e) a[a[a[a[2]+1]]]
Question 8Can you change an element of a sequence? What if a sequence is a dictionary? What if a sequence is a tuple?
Question 9What does a + b amount to if a and b are tuples?
Question 10What does a * b amount to if a and b are tuples?
Question 11What does a + b amount to if a is a tuple and b is 5?
Question 12Is a string the same as a tuple of characters?
Question 13Can you have an integer, a string, a tuple of integers and a tuple of strings in a tuple?
Question 1Tuples are immutable data types of Python.
Question 2A tuple can store values of all data types.
Question 3The + operator used with two tuples, gives a concatenated tuple.
Question 4The * operator used with a tuple and an integer, gives a replicated tuple.
Question 5To create a single element tuple storing element 5, you may write t = ( 5, ).
Question 6The in operator can be used to check for an element's presence in a tuple.
Question 7The len( ) function returns the number of elements in a tuple.
Question 8The index( ) function returns the index of an element in a tuple.
Question 9The sorted( ) function sorts the elements of a tuple and returns a list.
Question 10The sum( ) function cannot work with nested tuples.
Question 1Which of the following statements will create a tuple:tp1=("a", "b")tp1[2]=("a", "b")tp1=(3)*3None of these
Question 2Choose the correct statement(s).Both tuples and lists are immutable.Tuples are immutable while lists are mutable.Both tuples and lists are...
Question 3Choose the correct statement(s).In Python, a tuple can contain only integers as its elements.In Python, a tuple can contain only strings as...
Question 4Which of the following is/are correctly declared tuple(s) ?a = ("Hina", "Mina", "Tina", "Nina")a = "Hina", "Mina", "Tina", "Nina")a =...
Question 5Which of the following will create a single element tuple ?(1,)(1)( [1] )tuple([1])
Question 6What will be the output of following Python code?tp1 = (2,4,3) tp3 = tp1*2 print(tp3)(4,8,6)(2,4,3,2,4,3)(2,2,4,4,3,3)Error
Question 7What will be the output of following Python code?tp1 = (15,11,17,16,12) tp1.pop(12)...
Question 8Which of the following options will not result in an error when performed on types in Python where tp = (5,2,7,0,3) ?tp[1] =...
Question 9What will be the output of the following Python code ?tp = () tp1 = tp * 2 print(len(tp1))021Error
Question 10What will be the output of the following Python code?tp = (5) tp1 = tp * 2 print(len(tp1)) 021Error
Question 11What will be the output of the following Python code?tp = (5,) tp1 = tp * 2 print(len(tp1)) 021Error
Question 12Given tp = (5,3,1,9,0). Which of the following two statements will give the same output?(i) print( tp[:-1] )(ii) print( tp[0:5] )(iii)...
Question 13What is the output of the following code ?t = (10, 20, 30, 40, 50, 50, 70) print(t[5:-1])Blank output( )(50,70)(50,50,70)(50,)
Question 14What is the output of the following code?t = (10, 20, 30, 40, 50, 60, 70) print(t[5:-1])Blank output( )(10, 20, 30, 40, 50)(10, 30, 50,...
Question 15Which of the below given functions cannot be used with nested tuples ?index( )count( )max( )sum( )
Question 1Tuples in Python are mutable.False
Question 2The elements in a tuple can be deleted.False
Question 3A Tuple can store elements of different types.True
Question 4A tuple cannot store other tuples in it.False
Question 5A tuple storing other tuples in it is called a nested tuple.True
Question 6A tuple element inside another element is considered a single element.True
Question 7A tuple cannot have negative indexing.False
Question 8With tuple( ), the argument passed must be sequence type.True
Question 9All tuple functions work identically with nested tuples.False
Question 10Functions max( ) and min( ) work with all types of nested tuples.False
Question 1Discuss the utility and significance of tuples, briefly.AnswerTuples are used to store multiple items in a single variable. It is a...
Question 2If a is (1, 2, 3)what is the difference (if any) between a * 3 and (a, a, a) ?Is a * 3 equivalent to a + a + a ?what is the meaning of...
Question 3Does the slice operator always produce a new tuple ?AnswerNo, the slice operator does not always produce a new tuple. If the slice operator...
Question 4The syntax for a tuple with a single item is simply the element enclosed in a pair of matching parentheses as shown below :t = ("a")Is the...
Question 5Are the following two assignments same ? Why / why not ?1. T1 = 3, 4, 5 T2 = ( 3, 4 , 5) T3 = (3, 4, 5) T4 = (( 3, 4,...
Question 6What would following statements print? Given that we have tuple= ('t', 'p',...
Question 7How is an empty tuple created ?AnswerThere are two ways of creating an empty tuple:By giving no elements in parentheses in assignment...
Question 8How is a tuple containing just one element created ?AnswerThere are two ways of creating single element tuple:By enclosing the element in...
Question 9How can you add an extra element to a tuple ?AnswerWe can use the concatenation operator to add an extra element to a tuple as shown below....
Question 10When would you prefer tuples over lists ?AnswerTuples are preferred over lists in the following cases:When we want to ensure that data is...
Question 11What is the difference between (30) and (30,) ?Answera = (30) ⇒ It will be treated as an integer expression, hence a stores an integer 30,...
Question 12When would sum( ) not work for tuples ?AnswerSum would not work for the following cases:When tuple does not have numeric value.For...
Question 13Do min( ), max( ) always work for tuples ?AnswerNo, min( ), max( ) does not always work for tuples. For min( ), max( ) to work, the...
Question 14Is the working of in operator and tuple.index( ) same ?AnswerBoth in operator and tuple.index( ) can be used to search for an element in...
Question 15How are in operator and index( ) similar or different ?AnswerSimilarity:in operator and index( ) both search for a value in...
Question 1(a)Find the output generated by following code fragments :plane = ("Passengers", "Luggage") plane[1] = "Snakes"
Question 1(b)Find the output generated by following code fragments :(a, b, c) = (1, 2, 3)
Question 1(c)Find the output generated by following code fragments :(a, b, c, d) = (1, 2, 3)
Question 1(d)Find the output generated by following code fragments :a, b, c, d = (1, 2, 3)
Question 1(e)Find the output generated by following code fragments :a, b, c, d, e = (p, q, r, s, t) = t1
Question 1(f)a, b, c, d, e = (p, q, r, s, t) = t1What will be the values and types of variables a, b, c, d, e, p, q, r, s, t if t1 contains (1, 2.0,...
Question 1(g)Find the output generated by following code fragments :t2 = ('a') type(t2)
Question 1(h)Find the output generated by following code fragments :t3 = ('a',) type(t3)
Question 1(i)Find the output generated by following code fragments :T4 = (17) type(T4)
Question 1(j)Find the output generated by following code fragments :T5 = (17,) type(T5)
Question 1(k)Find the output generated by following code fragments :tuple = ( 'a' , 'b', 'c' , 'd' , 'e') tuple = ( 'A', ) + tuple[1: ]...
Question 1(l)Find the output generated by following code fragments :t2 = (4, 5, 6) t3 = (6, 7) t4 = t3 + t2 t5 = t2 + t3 print(t4)...
Question 1(m)Find the output generated by following code fragments :t3 = (6, 7) t4 = t3 * 3 t5 = t3 * (3) print(t4) print(t5)
Question 1(n)Find the output generated by following code fragments :t1 = (3,4) t2 = ('3' , '4') print(t1 + t2 )
Question 1(o)What will be stored in variables a, b, c, d, e, f, g, h, after following statements ?perc = (88,85,80,88,83,86) a = perc[2:2] b =...
Question 2What does each of the following expressions evaluate to? Suppose that T is the tuple containing :("These", ["are" , "a", "few", "words"] ,...
Question 3(a)Carefully read the given code fragments and figure out the errors that the code may produce.t = ('a', 'b', 'c', 'd', 'e') print(t[5])
Question 3(b)Carefully read the given code fragments and figure out the errors that the code may produce.t = ('a', 'b', 'c', 'd', 'e') t[0] = 'A'
Question 3(c)Carefully read the given code fragments and figure out the errors that the code may produce.t1 = (3) t2 = (4, 5, 6) t3 = t1 + t2...
Question 3(d)Carefully read the given code fragments and figure out the errors that the code may produce.t1 = (3,) t2 = (4, 5, 6) t3 = t1 + t2...
Question 3(e)Carefully read the given code fragments and figure out the errors that the code may produce.t2 = (4, 5, 6) t3 = (6, 7) print(t3 - t2)
Question 3(f)Carefully read the given code fragments and figure out the errors that the code may produce.t3 = (6, 7) t4 = t3 * 3 t5= t3 * (3) t6 =...
Question 3(g)Carefully read the given code fragments and figure out the errors that the code may produce.odd= 1,3,5 print(odd + [2, 4, 6])[4]
Question 3(h)Carefully read the given code fragments and figure out the errors that the code may produce.t = ( 'a', 'b', 'c', 'd', 'e') 1, 2, 3, 4,...
Question 3(i)Carefully read the given code fragments and figure out the errors that the code may produce.t = ( 'a', 'b', 'c', 'd', 'e') 1n, 2n, 3n,...
Question 3(j)Carefully read the given code fragments and figure out the errors that the code may produce.t = ( 'a', 'b', 'c', 'd', 'e') x, y, z, a,...
Question 3(k)Carefully read the given code fragments and figure out the errors that the code may produce.t = ( 'a', 'b', 'c', 'd', 'e') a, b, c, d,...
Question 4What would be the output of following code ifntpl = ("Hello", "Nita", "How's", "life?") (a, b, c, d) = ntpl print ("a is:", a) print ("b...
Question 5Predict the output.tuple_a = 'a', 'b' tuple_b = ('a', 'b') print (tuple_a == tuple_b)
Question 6Find the error. Following code intends to create a tuple with three identical strings. But even after successfully executing following code...
Question 7Predict the output.tuple1 = ('Python') * 3 print(type(tuple1))
Question 8Predict the output.x = (1, (2, (3, (4,)))) print(len(x)) print( x[1][0] ) print( 2 in x ) y = (1, (2, (3,), 4), 5) print( len(y)...
Question 9What will the following code produce ?Tup1 = (1,) * 3 Tup1[0] = 2 print(Tup1)
Question 10What will be the output of the following code snippet?Tup1 = ((1, 2),) * 7 print(len(Tup1[3:8]))
Question 1Write a Python program that creates a tuple storing first 9 terms of Fibonacci series.Solutionlst = [0,1] a = 0 b = 1 c = 0 for i in...
Question 2(a)Write a program that receives the index and returns the corresponding value.Solutiontup = eval(input("Enter the elements of tuple:")) b...
Question 2(b)Write a program that receives a Fibonacci term and returns a number telling which term it is. For instance, if you pass 3, it returns 5,...
Question 3Write a program to input n numbers from the user. Store these numbers in a tuple. Print the maximum and minimum number from this...
Question 4Write a program to create a nested tuple to store roll number, name and marks of students.Solutiontup = () ans = "y" while ans == "y" or...
Question 5Write a program that interactively creates a nested tuple to store the marks in three subjects for five students, i.e., tuple will look...
Question 6Write a program that interactively creates a nested tuple to store the marks in three subjects for five students and also add a function...
Question 7Write a program that inputs two tuples and creates a third, that contains all elements of the first followed by all elements of the...
Question 8Write a program as per following specification :"'Return the length of the shortest string in the tuple of strings str_tuple.Precondition:...
Question 9(a)Create a tuple containing the squares of the integers 1 through 50 using a for loop.Solutiontup = () for i in range(1,51): tup = tup...
Question 9(b)Create a tuple ('a', 'bb', 'ccc', 'dddd', ... ) that ends with 26 copies of the letter z using a for loop.Solutiontup = () for i in...
Question 10Given a tuple pairs = ((2, 5), (4, 2), (9, 8), (12, 10)), count the number of pairs (a, b) such that both a and b are even.Solutiontup =...
Question 11Write a program that inputs two tuples seq_a and seq_b and prints True if every element in seq_a is also an element of seq_b, else prints...
Question 12Computing Mean. Computing the mean of values stored in a tuple is relatively simple. The mean is the sum of the values divided by the...
Question 13Write a program to check the mode of a tuple is actually an element with maximum occurrences.Solutiontup = eval(input("Enter a tuple: "))...
Question 14Write a program to calculate the average of a tuple's element by calculating its sum and dividing it with the count of the elements. Then...
Question 15Mean of means. Given a nested tuple tup1 = ( (1, 2), (3, 4.15, 5.15), ( 7, 8, 12, 15)). Write a program that displays the means of...