Q. Find the output generated by following code fragments:
(a)
plane = ("Passengers", "Luggage")
plane[1] = "Snakes"
plane = ("Passengers", "Luggage")
plane[1] = "Snakes"
(b)
(a, b, c) = (1, 2, 3)
(a, b, c) = (1, 2, 3)
(c)
(a, b, c, d) = (1, 2, 3)
(a, b, c, d) = (1, 2, 3)
(d)
a, b, c, d = (1, 2, 3)
a, b, c, d = (1, 2, 3)
(e)
a, b, c, d, e = (p, q, r, s, t) = t1
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?
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)
t2 = ('a')
type(t2)
(h)
t3 = ('a',)
type(t3)
t3 = ('a',)
type(t3)
(i)
T4 = (17)
type(T4)
T4 = (17)
type(T4)
(j)
T5 = (17,)
type(T5)
T5 = (17,)
type(T5)
(k)
tuple = ('a', 'b', 'c', 'd', 'e')
tuple = ('A',) + tuple [1:]
print (tuple)
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)
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)
t3 = (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
print(t4)
print(t5)
(n)
t1 = (3, 4)
t2 = ('3', '4')
print(t1 + t2)
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[:]
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[:]
Answer :-
(a) It will generate an error because tuple is immutable.
(b) After running the program, we get that answer:
>>> a
1
>>> b
2
>>> c
3
>>> type(a)
<class 'int'>
>>> type((a,b,c))
<class 'tuple'>
>>>
>>> a
1
>>> b
2
>>> c
3
>>> type(a)
<class 'int'>
>>> type((a,b,c))
<class 'tuple'>
>>>
(c) It will give an error because there not enough value for unpacking of tuple.
(d) It will generate an error because there not enough value for unpacking of tuple.
(e) If value of t1 = (1, 2, 3, 4, 5) Then after running the program.
>>> a
1
>>> p
1
>>> type(a)
<class 'int'>
>>> type(p)
<class 'int'>
>>>
>>> a
1
>>> p
1
>>> type(a)
<class 'int'>
>>> type(p)
<class 'int'>
>>>
(f) If value of t1 = (1, 2, 3, 4, 5) Then after running the program.
>>> a
1
>>> p
1
>>> type(a)
<class 'int'>
>>> type(p)
<class 'int'>
>>> b
2
>>> q
2
>>> c
3
>>> r
3
>>> d
4
>>> s
4
>>> e
5
>>> t
5
>>> type(c)
<class 'int'>
>>> type(t)
<class 'int'>
>>>
>>> a
1
>>> p
1
>>> type(a)
<class 'int'>
>>> type(p)
<class 'int'>
>>> b
2
>>> q
2
>>> c
3
>>> r
3
>>> d
4
>>> s
4
>>> e
5
>>> t
5
>>> type(c)
<class 'int'>
>>> type(t)
<class 'int'>
>>>
(g) <class 'str'> because ("a") is string ( "a" ,) is tuple.
(h) <class 'tuple'>
(i) <class 'int'>
(j) It generate: -
('A', 'b', 'c', 'd', 'e')
(k) It give output: -
(6, 7, 4, 5, 6)
(4, 5, 6, 6, 7)
>>>
(6, 7, 4, 5, 6)
(4, 5, 6, 6, 7)
>>>
(l)
(6, 7, 4, 5, 6)
(4, 5, 6, 6, 7)
>>>
(6, 7, 4, 5, 6)
(4, 5, 6, 6, 7)
>>>
(m) Output: -
(6, 7, 6, 7, 6, 7)
(6, 7, 6, 7, 6, 7)
(6, 7, 6, 7, 6, 7)
(6, 7, 6, 7, 6, 7)
(n) Output: -
(3, 4, '3', '4')
>>>
(3, 4, '3', '4')
>>>
(o) Values are: -
>>> a
()
>>> b
(80, 88, 83, 86)
>>> c
(88, 85)
>>> d
(88, 85, 80, 88)
>>> e
83
>>> f
(80, 88)
>>> g
()
>>> h
(88, 85, 80, 88, 83, 86)
>>> a
()
>>> b
(80, 88, 83, 86)
>>> c
(88, 85)
>>> d
(88, 85, 80, 88)
>>> e
83
>>> f
(80, 88)
>>> g
()
>>> h
(88, 85, 80, 88, 83, 86)
e ans should be (83,86) pls check
ReplyDeleteOk I will Check.
Delete83 is correct.
DeleteIn which part.
DeleteL part is missing ...
ReplyDeletePlease check.
Please check again I have corrected it
DeleteDidn't understand part g
ReplyDeletebecause ("a") is string ( "a" ,) is tuple.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )