Wednesday 20 November 2019

ASSIGNMENT ON PYTHON LISTS CLASS-XI (CS)






Q1. Find the output of the following:
(i)           a=[1,2,3,4,5,6,7,8,9]
          print(a[::2])

(ii)                   a=[1,2,3,4,5]
          print(a[3:0:-1])
 
(iii)                    arr = [1, 2, 3, 4, 5, 6]
         for i in range(1, 6):
         arr[i - 1] = arr[i]
         for i in range(0, 6): 
                        print(arr[i], end = " ")

(iv) list1 = [‘physics’, ‘chemistry’, 1997, 2000];
       list2 = [1,2,3,4,5,6, 7];
       print “list1[0]”, list1[0]
(v)
aList = [123, ‘xyz’, ‘zara’, ‘abc’, 123];
bList = [2009, ‘manni’];
aList.extend (bList)
print “Extended List :”, aList;
Q2. Differentiate between append() and extend() functions of list.
Q3. Consider a list:
 list1 = [6,7,8,9]
What is the difference between the following operations on list1:
a. list1 * 2
b. list1 *= 2
c. list1 = list1 * 2




Q4. Write Python statements to create the following lists:
(i) A list of 5 fruit names and name it as fruit.
(ii) A list of 5 city names and name it as City.
(iii) A list containing 3 strings and 2 integers and name it as Mixed.
(iv) A list containing 3 integers and a list of 2 strings and name it as Box.
(v) A list of 10 random integers each in the range 10 to 50 and name it as R10.
(vi) A list of 10 random floating point numbers in the range 10.00 to 49.99 and name it as F10.
Q5.. Assuming that A is a list, differentiate between:
(i) A[2] and A[2:]
(ii) A[2:] and A[:2]
(iii) A[2::] and A[::2]
(iv) A*3 and [A,A,A]


Q6. Consider the lists A and B given below and state the values (True/False) of the expressions that
follow:
A=[5, 3, 8]
B=[A, 8, 66, 45]
(i) A in B                      (ii) 'A ' in B                  (iii) [A] in B                  (iv) [5, 3, 8] in B
(v) 8 in B                      (vi) [8] in B                  (vii) [A, 8] in B             (viii) 66 in B
(ix) 45 in B                   (x) A not in B



Q7.. Write output of the following code segment:
a=[1,2,3,2,1]
for x in a:
print(a[x],end= '*')
Q8.Consider the lists A and B given below and write the output of the statements that follow:
A=[5, 3, 8]
B=[A, 8, 66, 45, 'A',['A',A], ["nested", "lists"]]
(i) print(A) (ii) print(B) (iii) print(A[0])
(iv) print(A[0:]) (v) print(A[:0]) (vi) print(B[0])
(vii) print(B[0][1]) (viii) print(B[0][1:]) (ix) print(B[4])
(x) print(B[5])

Q9. What will be the output of the following statements?
(i).
list1 = [12,32,65,26,80,10]
list1.sort()
print(list1)
(ii)
list1 = [12,32,65,26,80,10]
sorted(list1)
print(list1)
(iii)
list1 = [1,2,3,4,5,6,7,8,9,10]
list1[::-2]
list1[:3] + list1[3:]
(iv)
 list1 = [1,2,3,4,5]
list1[len(list1)-1]

Q10. Consider the following list myList. What will be the elements of myList after the following two
operations:
 myList = [10,20,30,40]
i. myList.append([50,60])
ii. myList.extend([80,90])

No comments:

Post a Comment