Tuples || Type B || Sumita Arora || Class 11 || Computer science || Information practices || Solution
Q1. Find the output generated by following code fragments:
(a)
plane = ("Passengers", "Luggage")
plane[1] = "Snakes"
(b)
(a, b, c) = (1, 2, 3)
(c)
(a, b, c, d) = (1, 2, 3)
(d)
a, b, c, d = (1, 2, 3)
(e)
a, b, c, d, e = (p, q, r, s, t) = t1
(f)
What will be the values and types of variables a, b, c, d, e, f, p, q, r, s, t after executing part e above?
(g)
t2 = ('a')
type(t2)
(h)
t3 = ('a',)
type(t3)
(i)
T4 = (17)
type(T4)
(j)
T5 = (17,)
type(T5)
(k)
tuple = ('a', 'b', 'c', 'd', 'e')
tuple = ('A',) + tuple [1:]
print (tuple)
(l)
t2 = (4, 5, 6)
t3 = (6, 7)
t4 = t3 + t2
t5 = t2 + t3
print(t4)
print(t5)
(m)
t3 = (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
print(t4)
print(t5)
(n)
t1 = (3, 4)
t2 = ('3', '4')
print(t1 + t2)
(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 = perc[2:]
c = perc[:2]
d = perc[:-2]
e = perc[-2]
f = perc[2:-2]
g = perc[-2:2]
h = perc[:]
Q2. What does each of the following expressions evaluate to? Suppose that T is the tuple
("These", ("are", "a", "few", "words"), "that", "we", "will", "use")
(a)
T[1][0: : 2]
(b)
"a" in T [1] [ 0 ]
(c)
T [ : 1 ] + T[ 1 ]
(d)
T[ 2 : : 2 ]
(e)
T[2][2] in T[1]
Q3. Carefully read the given code fragments and figure out the errors that the code may produce.
(a)
t = ('a', 'b', 'c', 'd', 'e')
print(t[5])
(b)
t = ('a', 'b', 'c', 'd', 'e')
t[0] = 'A'
(c)
t1 = (3)
t2 = (4, 5, 6)
t3 = t1 + t2
print(t3)
(d)
t2 = (4, 5, 6)
t3 = (6, 7)
print(t3 - t2)
(e)
t3 = (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
t6 = t3 * (3,)
print(t4)
print(t5)
print(16)
(f)
t = ('a', 'b', 'c', 'd', 'e')
1, 2, 3, 4, 5, = t
(g)
t = ('a', 'b', 'c, d', 'e')
1n, 2n, 3n, 4n, 5n = t
(h)
t = ('a', 'b', 'c', 'd', 'e')
x, y, z, a, b = t
(i)
t = ('a', 'b', 'c', 'd', 'e')
a, b, c, d, e, f = t
Q4. What would be the output of following code if ntpl = ("Hello", "Nita", "How's", "life?")
(a, b, c, d) = ntpl
print ( "a is:", a)
print("b is:", b)
print("c is:", c)
print("d is:", d)
ntpl = (a, b, c, d)
print (ntpl[0][0] + ntpl[1][1], ntpl[1])
Q5. Predict the output:
tuple_a = 'a', 'b'
tuple_b = ('a', 'b')
print (tuple_a == tuple_b)
Q6. Find the error. Following code intends to create a tuple with three identical strings. But even after successfully executing following code (No error reported by Python). The len() returns a value different from 3 Why ?
tup1 = ('Mega') * 3
print(len(tup1))
Q7. Predict the output:
tuple1 = ('Python') * 3
print(type(tuple1))
Q9. What will the following code produce?
Tup1 = (1,) * 3
Tup1 [0] = 2
print (Tup1)
Q10. What will be the output of the following code snippet?
Tup1 = ((1, 2),) * 7
print (len(Tup1 [3: 8 ]))
Where can we access the answers??
ReplyDeletePlease click on Questions...
Deletehas sumitha arora book for python 2021-22 edition been released?
ReplyDeleteclass 12 ^
DeleteNo.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )