Page 2 - Home Assignment
P. 2

Home Assignment

               B) Answer the following:

               1.   Which of the following commands will create a list?
                   a) list1 = list()    b) list1 = []    c) list1 = list([1, 2, 3])   d) all of the mentioned

               2.   What is the output when we execute list(“hello”)?
                   a) [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]     b) [‘hello’]    c) [‘olleh’]   d) error

               3.   Suppose list_Example is ['h', 'e', 'l', 'l', 'o'], what is len(list_Example)?
                   a) 5       b) 4          c) None        d) Error

               4.   Suppose list1 is [2445, 133, 12454, 123], what is max(list1) ?
                   a) 2445    b) 133        c) 12454       d) 123 7.

               5.  Suppose list1 is [1, 5, 9], what is sum(list1) ?
                   a) 1       b) 9          c) 15          d) Error

               6.   Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1] ?
                   a) [2, 33, 222, 14]   b) Error          c) 25                d) [25, 14, 222, 33, 2].

               7.   What is the output when following code is executed ?
                   >>>names = ['Amir', 'Bear', 'Charlton', 'Daman']
                   >>>print(names[-1][-1])
                   a) A            b) Daman        c) Error       d) n

               8.   Suppose list1 is [1, 3, 2], What is list1 * 2 ?
                   a) [2, 6, 4]      b) [1, 3, 2, 1, 3]     c) [1, 3, 2, 1, 3, 2]   d) [1, 3, 2, 3, 2, 1]

               9.   Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is :
                   a) [0, 1, 2, 3]   b) [0, 1, 2, 3, 4]     c) [0.0, 0.5, 1.0, 1.5]   d) [0.0, 0.5, 1.0, 1.5, 2.0].

               10.  What is the output when following code is executed ?
                   >>>list1 = [11, 2, 23]
                   >>>list2 = [11, 2, 2]
                   >>>list1 < list2 is
                   a) True              b) False    c) Error      d) None

               11.  To add a new element to a list we use which command ?
                   a) list1.add(5)    b) list1.append(5)    c) list1.addLast(5)    d) list1.addEnd(5)

               12.  To insert 5 to the third position in list1, we use which command ?
                   a) list1.insert(3, 5)       b) list1.insert(5, 3)      c) list1.add(3, 5)    d) list1.append(3, 5)

               13.  Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5) ?
                   a) 0         b) 1          c) 4         d) 2

               14.  What is the output when following code is executed ?
                   names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
                   names2 = names1
                   names3 = names1[:]
                   names2[0] = 'Alice'
                   names3[1] = 'Bob'
                   sum = 0
                   for ls in (names1, names2, names3):
   1   2   3   4   5