Tuesday, 28 May 2019

Assessment 4



Assignment 4


1.  Print “t” in the below tuple: t=(“p”, “y”, “t”, “h”, “o”, “n”)
2.  a = ["apple", "banana", "cherry"]. In this list change the “banana” to “mango” and display the list.
3.  Remove “Chennai” and display the deleted item from the list: 
     a = ["Hyd", "Vijayawada", "Tirupathi",'Chennai',2.6,4+5j]
4.  Display element 20 in the following list: a=["python",[10,20,30]] 
5.  List out the differences between list and tuple.
6.  Display starting element to below 6th element from the list: words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really']
7. Swap the two number without using third variable.(input values are: a=10, b=20)
8. What will be the output when we run the below code:
>>> a = ('rama', "sitha", True)
>>> a
('rama', 'sitha', True)
>>> del a
>>> print(a)

9. (i) What do you understand the following statement? 
           raj=3,4,True,'Ram'

   (ii) display in the following output:
a=3
b=4
c=True
e=’Ram’
>>> a,b,c,e=raj

10.  t=('c','a','t') :How do you test element ‘t’ is exists in the tuple are not?

Answers:

1.      print(t[2]) or t[2] 
2.      a[1]= "mango"
       print(a)
3.       a.pop(3)

4.      a[1][1]

5.      Differences: 
a.       Lists are mutable while tuples are immutable.
b.      Lists can be copied but Tuples cannot be copied (The reason is that tuples are immutable).
c. A list is created using square brackets [] whereas the tuple is created using parenthesis ().

6.      words[0:6]

7.      a = 10
 b = 20
 a = a + b
 b = a - b
 a = a - b
print(a, b) 

8.      Error 

9.      (i) Its Packing the tuples. 
(ii) Unpacking the tuples is >>> a,b,c,e=raj
print(‘t’ in t)

Next
Previous Assessment: Assessment Exam2

No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(...