Professional Documents
Culture Documents
Full Download Arihant Computer Science Term 2 Question Bank 2021 22 2021St Edition Arihant Online Full Chapter PDF
Full Download Arihant Computer Science Term 2 Question Bank 2021 22 2021St Edition Arihant Online Full Chapter PDF
https://ebookstep.com/download/ebook-43189802/
https://ebookstep.com/download/ebook-33802828/
https://ebookstep.com/product/crash-course-computer-science-
worksheet-1st-edition-carrie-anne-philbin/
https://ebookstep.com/download/ebook-10543478/
Intro to Python for Computer Science and Data Science:
Learning to Program with AI, Big Data and The Cloud 1st
Edition Deitel
https://ebookstep.com/product/intro-to-python-for-computer-
science-and-data-science-learning-to-program-with-ai-big-data-
and-the-cloud-1st-edition-deitel/
https://ebookstep.com/download/ebook-7049022/
https://ebookstep.com/download/ebook-49055652/
https://ebookstep.com/product/seduccion-2-amor-en-londres-2021st-
edition-lauren-smith/
https://ebookstep.com/product/seduccion-2-amor-en-londres-2021st-
edition-lauren-smith-3/
CBSE Term II
2022
Computer
Science
Class
XI
Complete Theory Covering NCERT
Author
Neetu Gaikwad
© Publisher
No part of this publication may be re-produced, stored in a retrieval system or by any means,
electronic, mechanical, photocopying, recording, scanning, web or otherwise without the written
permission of the publisher. Arihant has obtained all the information in this book from the sources
believed to be reliable and true. However, Arihant or its editors or authors or illustrators don’t take any
responsibility for the absolute accuracy of any information published and the damage or loss suffered
thereupon.
All disputes subject to Meerut (UP) jurisdiction only.
Head Office
Kalindi, TP Nagar, Meerut (UP) - 250002, Tel: 0121-7156203, 7156204
Sales & Support Offices
Agra, Ahmedabad, Bengaluru, Bareilly, Chennai, Delhi, Guwahati,
Hyderabad, Jaipur, Jhansi, Kolkata, Lucknow, Nagpur & Pune.
ISBN : 978-93-25796-87-4
PO No : TXT-XX-XXXXXXX-X-XX
Published by Arihant Publications (India) Ltd.
For further information about the books published by Arihant, log on to
www.arihantbooks.com or e-mail at info@arihantbooks.com
Follow us on
CBSE Term II
2022
Contents
CHAPTER
Lists in Python -
CHAPTER
Tuples -
CHAPTER
Dictionary -
CHAPTER
Introduction to Python Modules -
CHAPTER
Society, Law and Ethics -
Practice Papers - -
Syllabus
CBSE Term II Class XI
Computer Science
Marks
. Computational Thinking and Programming -
. Society, Law and Ethics
Total
dsUnh;
z ek/;fed f'k{kk cksMZ
(f'k{kk ea=ky;] Hkkjr ljdkj ds v/khu ,d Lok;r laxBu)
Hkkjr
CENTRAL BOARD OF SECONDARY EDUCATION
(An Autonomous Organisation under the Ministryof Education, Govt. of India)
dsUnh;
z ek/;fed f'k{kk cksMZ
(f'k{kk ea=ky;] Hkkjr ljdkj ds v/khu ,d Lok;r laxBu)
To cover this
situation, we
have given
both MCQs and
Subjective
Questions in
each Chapter.
dsUnh;
z ek/;fed f'k{kk cksMZ
(f'k{kk ea=ky;] Hkkjr ljdkj ds v/khu ,d Lok;r laxBu)
CHAPTER 01
Lists in Python
In this Chapter...
l Creating a List l Membership Operators
For example, It will return min value of character using ASCII value.
>>>l = [45, 23, 87, 5, 9] >>>l3 = [‘Rahul’, ‘Shiv’, ‘Sandhaya’, ‘Ankit’]
>>>sum (l) >>>min (l3)
169
‘Ankit’
sum ( ) method is used for only numeric values otherwise it
gives an error. (ix) max ( )
>>>l = [45, 23, 87, 5, ‘Hello’]
>>>sum (l)
It is used to return the maximum element out of elements of
list.
Trackback (most recent call last) :
File “<pyshell# 17>”, line 1, in <module> Syntax max (list_name)
sum(l) For example,
TypeError: unsupported operand type (s) for >>>l1 = [34, 76, 89, 33, 54, 65]
+ : ‘int’ and ‘str’ >>>max (l1)
89
(v) count ( ) >>>l2 = [‘t’, ‘e’, ‘E’, ‘U’, ‘v’]
This method is used to calculate total occurrence of given >>>max (l2)
element of list. ‘v’
Syntax list_name. count (element) It will return max value of character using ASCII value.
For example,
>>>list1 = [4, 3, 5, 2, 54, 4, 2, 6, 4, 4, 5]
(x) reverse ( )
>>>list1. count(4) Using the reverse ( ) method, we can reverse the contents of
4 the list object in-place, i.e. we don’t need to create a new list
instead we just copy the existing elements to the original list
(vi) len ( ) in reverse order.
This method is used to calculate the total length of list. Syntax list_name. reverse ( )
Syntax len (list_name) For example,
For example, >>>list1 = [34, 76, 89, 33, 54, 65]
>>>list1 = [4, 3, 5, 2, 54, 4, 2, 6, 4, 4, 5] >>>list1. reverse( )
>>>len (list1) >>>print (list1)
11 [65, 54, 33, 89, 76, 34]
>>>l = [‘Hii’, ‘Hello’, ‘Hey’, ‘Namesty’]
(vii) index () >>>l.reverse ( )
It returns the index of first occurrence. Start and end index >>>print (l)
are not necessary parameters. [‘Namesty’, ‘Hey’, ‘Hello’, ‘Hii’]
Syntax list_name.index (element[, start [, end]])
(xi) pop ( )
For example,
This function is used to remove the element and return last
>>>list1 = [3, ‘New’, 2, 6, ‘Hello’, 2]
value from the list or the given index value.
>>>list1.index (‘Hello’)
4
Syntax list_name.pop (index)
For example,
(viii) min ( ) >>>l1 = [34, 65, 22, 90, 87, 61]
It is used to return the minimum element out of elements of >>>l1.pop (3)
list. 90
Syntax min (list_name) >>>print (l1)
[34, 65, 22, 87, 61]
For example,
>>>l1 = [45, 87, 23, 90, 12] If you do not give any index value, then it will remove last
>>>min (l1) value from the list.
12 >>>l1. pop ( )
61
>>>l2 = [‘A’, ‘B’, ‘c’, ‘e’, ‘a’]
>>>print (l1)
>>>min (l2)
[34, 65, 22, 87]
‘A’
CBSE Term II Computer Science XI 7
Chapter
Practice
Ans. (c) insert () function is used to insert an element at specified
PART 1 position in the list. This method takes two arguments : one
for index number and second for element value.
Objective Questions Syntax list_name.insert(index, element)
6. Choose the correct option for the following.
l
Multiple Choice Questions l1 = [2, 5, 7]
1. Which value is used to represent the first index of l = l1 + 5
list? print (l)
(a) [7, 10, 12]
(a) 1 (b) 0
(b) [2, 5, 7, 5]
(c) −1 (d) a
(c) [5, 2, 5, 7]
Ans. (b) To access the list’s elements, index number is used. The
index number should be an integer. Index of 0 refers to first (d) TypeError
element, 1 refers to second element and so on. Ans. (d) + operator cannot add list with other type as number or
string because this operator is used only with list types.
2. Choose the output of following Python code. So, it will give TypeError as it can only concatenate list (not
1 = list () “int”) to list.
print ( 1)
(a) [] (b) ()
7. What is the output of following code?
l1 = [3, 2, 6]
(c) [,] (d) Empty
l = l1 * 2
Ans. (a) Empty list can be created in Python using []. To create
empty list, list () is also used.
print (l)
(a) [3, 2, 6, 3, 2, 6]
3. Suppose list (b) [6, 4, 12]
1 = [10, 20, 30, 40, 50, 60, 70] (c) [3, 4, 12]
print( 1[ −3]) (d) TypeError
(a) 30 (b) 50 Ans. (a) * operator can repeat the elements of the list.
(c) 40 (d) Error Syntax list = list1 * digit
Ans. (b) The index of −1 refers to the last element, −2 refers to the
8. Which of the following is true regarding lists in
second last element and so on. Hence, −3 refers to third last
element, i.e. 50.
Python?
(a) Lists are immutable.
4. Choose the output from following code. (b) Size of the lists must be specified before its initialisation.
list1 = [‘A’, ‘R’, ‘I’,‘H’,‘A’,‘N’,‘T’] (c) Elements of lists are stored in contiguous memory
print (list1 [7]) location.
(d) size(list1) command is used to find the size of lists.
(a) T (b) N
(c) A (d) Error Ans. (c) Elements of lists are stored in contiguous memory
location, so it is true regarding lists in Python.
Ans. (d) In the given code, we are trying to access 8th element
from the list which does not exist as we are having total 7 9. Suppose list1 is [56, 89, 75, 65, 99], what is the
elements for which the last index is 6. So, Python will give output of list1 [− 2]?
an IndexError. (a) Error (b) 75
5. Which function is used to insert an element at (c) 99 (d) 65
specified position in the list? Ans. (d) −1 corresponds to the last index in the list, −2 represents
(a) extend () (b) append () the second last element and so on.
So, the output for list1 [− 2] is 65 because 65 is second last
(c) insert () (d) add ()
element of list1.
CBSE Term II Computer Science XI 9
10. Identify the output of following code. 16. Which method will empty the entire list?
List1=[1, 2, 3, 7, 9] (a) pop() (b) clear()
(c) sort() (d) remove()
L=List1.pop(9)
Ans. (b) clear() method is used to remove all the items of a list.
print(L)
This method will empty the entire list.
(a) Syntax error (b) 9
Syntax
(c) [1, 2, 3, 7] (d) None of these
list_name.clear()
Ans. (a) In pop(9), parentheses put index number instead of
element. In the given list, maximum index number is 4, then 17. Which of the following allows us to sort the list
9 is out of index range. elements in descending order?
11. Suppose list1 is [2445,133,12454,123], what is the (a) reverse = True
output of max(list1)? (b) reverse = False
(a) 2445 (b) 133 (c) sort (descending)
(c) 12454 (d)123 (d) sort. descending
Ans. (c) max() returns the maximum element in the list. From Ans. (a) sort() is used to sort the given list in ascending order. The
given options, 12454 is the element with maximum value. sort() has an argument called reverse = True. This allows us
to sort the list elements in descending order.
12. To add a new element to a list, which command will
we use? 18. Identify the correct output.
(a) list1.add(8) >>>l1 = [34, 65, 23, 98]
(b) list1.append(8) >>>l1. insert(2, 55)
(c) list1.addLast(8) >>> l1
(a) [34, 65, 23, 55] (b) [34, 55, 65, 23, 98]
(d) list1.addEnd(8)
(c) [34, 65, 55, 98] (d) [34, 65, 55, 23, 98]
Ans. (b) We use the function append() to add an element to the
Ans. (d) insert() is used to insert an element at specified position
list.
in the list. This method takes two arguments : one for index
13. What will be the output of the following Python number and second for element value.
code? Syntax
list1=[9, 5, 3, 5, 4] list_name.insert(index, element)
list1[1:2]=[7,8] 19. Find the output from the following code.
print(list1) list1=[2, 5, 4, 7, 7, 7, 8, 90]
(a) [9,5, 3, 7, 8] (b) [9, 7, 8, 3, 5, 4] del list1[2 : 4]
(c) [9,[ 7, 8], 3, 5,4] (d) Error print(list1)
Ans. (b) In the piece of code, slice assignment has been (a) [2, 5, 7, 7, 8, 90] (b) [5, 7, 7, 7, 8, 90]
implemented. The sliced list is replaced by the assigned (c) [2, 5, 4, 8, 90] (d) Error
elements in the list. Ans. (a) del keyword is used to delete the elements from the list.
14. Consider the declaration a=[2, 3, ‘Hello’, 23.0]. 20. Slice operation is performed on lists with the use of
Which of the following represents the data type of (a) semicolon (b) comma
‘a’? (c) colon (d) hash
(a) String (b) Tuple Ans. (c) In Python list, there are multiple ways to print the whole
(c) Dictionary (d) List list with all the elements, but to print a specific range of
Ans. (d) List contains a sequence of heterogeneous elements elements from the list, we use slice operation. Slice
which store integer, string as well as object. It can created to operation is performed on lists with the use of colon (:).
put elements separated by comma (,) in square brackets [].
15. Identify the output of the following Python
l
Case Based MCQs
statement. 21. Suppose that list L1
x = [[1, 2, 3, 4], [5, 6, 7, 8]] [“Hello”, [“am”, “an”], [“that”, “the”, “this”], “you”,
y = x [0] [2] “we”, “those”, “these”]
print(y) Based on the above information, answer the
(a) 3 (b) 4 following questions.
(c) 6 (d) 7
(i) Find the output of len (L1).
Ans. (a) x is a list, which has two sub-lists in it. Elements of first
(a) 10 (b) 7
list will be represented by [0] [i] and elements of second list
will be represented by [1] [i]. (c) 6 (d) Error
10 CBSE Term II Computer Science XI
(ii) Find the output of L1[3 : 5]. 2. list1 = [45, 77, 87, ‘Next’, ‘Try’, 33, 43]
(a) [“that”, “the”, “this”] (b) [“we”, “those”] Observe the given list and find the answer of
(c) [“you”, “we”] (d) [you, we] questions that follows.
(iii) What will be the output of L1[5:] +L1[2]? (i) list1[−2] (ii) list1[2]
(a) [‘those’, ‘these’, ‘that’, ‘the’, ‘this’] Ans. (i) 33 (ii) 87
(b) [‘those’, ‘these’]
3. Distinguish between string and list.
(c) [‘that’, ‘the’, ‘this’]
Ans. Strings are immutable, which means the values provided to
(d) Error
them will not change in the program. While lists are
(iv) Choose the correct output of mutable which means the values of list can be changed at
print (L1[6:]) any point of time in program.
(a)“those” (b) “these” 4. What is the output of below questions?
(c) “those”, “these” (d) None of these l2 = [75, 43, 40, 36, 28, 82]
(v) Give the correct statement for (i) l2.sort ( )
[‘Hello’, [‘am’, ‘an’], [‘that’, ‘the’, ‘this’], ‘you’, ‘we’, (ii) l2.sort (reverse = True)
‘those’, ‘these’] Ans. (i) [28, 36, 40, 43, 75, 82]
(a) L1[] (b) L1[:] (ii) [82, 75, 43, 40, 36, 28]
30. Write a program to read a list of elements. Modify x = int(input(“Enter the element:
this list, so that it does not contain any duplicate ”))
elements, i.e. all elements occurring multiple times list1.append(x)
in the list should appear only once. [NCERT] print(“Original list: ”,list1)
Ans. list1=[] print()
num=int(input(“Enter the number of pos = int(input(“Enter the position of
elements: ”)) the element you want to delete: ”))
for i in range(num): del list1[pos]
x=int(input(“Enter the element: ”)) print(“List after deletion:”,list1)
list1.append(x) (ii) num = int(input(“Enter the number of elements: ”))
print(“New list: ”) list1 = list()
print(list(set(list1))) for i in range(num):
x = int(input(“Enter the element:
31. Write a program to read a list of elements. Input an
”))
element from the user that has to be inserted in the
list1.append(x)
list. Also, input the position at which it is to be
print(“Original list: ”,list1)
inserted. Write a user defined function to insert the
x = int(input(“Enter the element you
element at the desired position in the list. [NCERT]
want to delete: ”))
Ans. num = int(input(“Enter the number of elements: ”))
list1.remove(x)
list1 = list()
print(“List after deletion: ”,list1)
for i in range(num):
x = int(input(“Enter the element: ”)) 33. In Python, list is a type of container in data
list1.append(x) structures, which is used to store multiple data at
print(“Original list: ”,list1) the same time. It can store integer, string as well as
print() object in a single list. Lists are mutable which
pos = int(input(“Enter the index means they can be changed after creation. Each
position: ”)) element of a list is assigned a number its position or
ele = int(input(“Enter the new element: ”)) index. The first index is 0, the second index is 1, the
list1.insert(pos, ele) third index is 2 and so on.
print() Based on the above information, answer the
print(“New list: ”,list1) following questions.
32. Write a program to read elements of a list. (i) List is defined by which type of bracket?
(i) The program should ask for the position of the (ii) List contains a sequence of what type of
element to be deleted from the list. Write a elements?
function to delete the element at the desired (iii) Lists are mutable. What is it mean?
position in the list. (iv) Which method is also used to create list of
(ii) The program should ask for the value of the characters and integers through keyboard?
element to be deleted from the list. Write a (v) How to represent the first index of list?
function to delete the element of this value from Ans. (i) []
the list. [NCERT] (ii) Heterogeneous
Ans. (i) num = int(input(“Enter the number of (iii) Lists are mutable, which means they can be changed
elements: ”)) after creation
list1 = list() (iv) list ()
for i in range(num): (v) 0
Chapter Test
Multiple Choice Questions 8. What will be the output of following code?
1. What is the output of following code? l = []
list1=[4, 3, 7, 6, 4, 9, 5, 0, 3, 2] for i in range (20, 40) :
l1=list1[1:10:3] if(i % 7 == 0 ) and (i % 5 ! = 0 ) :
print(l1) l . append (str(i))
(a) [3, 7, 6] (b) [3, 4, 0] print (‘.’. join(l))
(c) [3, 6, 9] (d) [7, 9,2] 9. What are the output of below questions?
2. Identify the output of following Python statement. L = [45, 89, 74, 12, 9, 83]
a = [[0, 1, 2], [3, 4, 5, 6]] (i) L.remove ()
b = a [1] [2] (ii) L.remove (12)
print (b)
(a) 2 (b) 1 (c) 4 (d) 5
10. Predict the output.
L1 = [3, 2, 1]
3. Identify the output of following code. L2 = [5, 9, 8]
list1 = [2, 3, 9, 12, 4]
(i) L1 * L2
list1.insert(4, 17)
(ii) L2.sort ( )
list1.insert(2, 23)
print(list1 [−4]) (iii) L1.reverse ( )
(a) 4 (b) 9 (c) 12 (d) 23 11. Write a program to input a list and print it in reverse
4. What will be the output of the following Python code? order.
books = [‘Hindi’, ‘English’, ‘Computer’] 12. Give the output.
if ‘put’ in books: (i) str1 = ‘aeiou’
print(True) list1 = list(str1)
else: print(list1)
print(False)
(ii) list1 = [2, 3, 4, 5]
(a) True (b) False (c) None (d) Error
list1. append(1)
5. Identify the output of the following Python statement. print(list1)
list1=[4,3,7,9,15,0,3,2]
s = list1[2:5] Long Answer Type Questions
print(s) 13. Write the best suited method’s name for the following
(a) [7,9,15,0] (b) [3,7,9,15] conditions.
(c) [7,9,15] (d) [7,9,15,0,3]
(i) Remove the value from the list.
6. What will be the output of following code? (ii) Sort the elements in descending order.
list1=[2, 5, 4, [9, 6], 3] (iii) Calculate the sum of all the elements of list.
list1[3][2] =10
(iv) Return the minimum element out of elements.
print(list1)
(a) [2, 5, 4, [9, 10], 3] (b) [2, 5, 4, 10, [9, 6], 3]
14. Write program to find the minimum and maximum
elements from the entered list.
(c) Index out of range (d) None of these
15. Write program to calculate the sum and mean of the
Short Answer Type Questions elements which are entered by user.
7. What will be the output of the following Python code? 16. Write program to count the frequency of elements in a
list1 = [11, 12, 13, 14, 15] list entered by user.
for i in range (1, 5) :
17. Write program to search for an element with its
list1[i−1] = list1[i] respective index number.
for i in range (0, 5) :
18. Write program to enter the elements of a list and
print(list1[i],end = “ ”) reverse these elements.
CHAPTER 02
Tuples
In this Chapter...
l Tuple vs List l Comparing Tuples
A tuple is a collection of Python objects separated by commas Here is the two ways to create empty tuple as
(,) and put the elements in parentheses. Tuples are >>>t = ()
immutable by design which means they cannot be changed >>>print (t)
after creation. Tuple holds a sequence of heterogeneous ()
elements. Tuples store a fixed set of elements and do not >>>t = tuple ()
allow changes. >>>print(t)
()
Chapter
Practice
PART 1 4. Is the following Python code valid?
>>>tup1=(56, 25,36, 15)
Objective Questions >>> result=tup1.update(4,)
(a) Yes, tup1=(56, 25, 36, 15,4) and result=(56, 25, 36, 15,4)
(b) Yes, tup1=(56, 25, 36,15) and result=(56, 25, 36, 15,4)
l
Multiple Choice Questions (c) No, because tuples are immutable
(d) No, because wrong syntax for update() method
1. Which of the following is a collection of Python
Ans. (c) Tuple does not have any update() attribute because it is
objects separated by commas and represent as (,)?
immutable and cannot be changed after creation.
(a) List (b) Tuple
(c) Dictionary (d) String 5. What is the output of following code?
Ans. (b) A tuple is a collection of Python objects separated by t=(4,0, ‘Hello’, 90, ‘Two’, (‘One’, 45), 34, 2)
commas and represent as (,). Tuples are immutable by t1=t[1]+t[−2]
design which means they cannot be changed after creation. print(t1)
It holds a sequence of heterogeneous elements. (a) 34 (b) 38
e.g. T = (3, 4, 7, 6) (c) Hello34 (d) 45
Ans. (a) Value of t[1] is 0 because index number is 1 and value of
2. What will be the output of the following Python t[ −2 ] is 34 because index number is started from −1 at the
code? end point. t1 will store the sum of both values, i.e.
>>> a=(1,2,(4,5)) 0+34=34.
>>> b=(1,2,(3,4))
>>> a<b
6. What is the output of following code?
(a) False t=(1, 2, ‘Hello’, ‘The’, 3, 4)
(b) True print(max(t))
(a) ‘Hello’ (b) 4
(c) Error, < operator is not valid for tuples.
(c) ‘The’ (d) Error
(d) Error, < operator is valid for tuples but not if there are
Ans. (d) This code will give an error because ‘>’ (max) not
sub-tuples.
Ans. (a) Since the first element in the sub-tuple of ‘a’ is larger supported between instances of ‘str’ and ‘int’.
that the first element in the sub-tuple of ‘b’, hence False is 7. To create a tuple in Python, put all the elements in
printed. a
3. What is the output of the following code? (a) () (b) []
t1=(70, 56, ‘Hello’, 22, 2, ‘Hi’, ‘The’, ‘World’, 3) (c) {} (d) <>
print(t1 [2:4]) Ans. (a) To create a tuple in Python, put all the elements in a
(a) (56, ‘Hello’) parentheses (), separated by commas. We can have tuple of
(b) (‘Hello’, 22) same type of data items as well as mixed type of data items.
>>> t = ()
(c) (‘Hello’, 22,2)
>>> print(t)
(d) (56, ‘Hello’, 22) ()
Ans. (b) (:) is a slice operator, which returns the sub-part of any
data type as string, list, tuple etc. Index number is started
8. Suppose t1 = (3, 4, 5,8, 2, 1)
from 0, so the value of index number 2 is ‘Hello’ and this Find the value of t1[3.5].
will display the elements till last index number − 1, i.e. (4 − (a) 8 (b) 2
1=)3. (c) 5 (d) Error
So, the correct output is (‘Hello’, 22). And. (d) It will give TypeError because tuple’s index must be
integers or slices, not float.
CBSE Term II Computer Science XI 23
9. Suppose tuple t1 = (3, 4, 5, 6, 7, 8) Ans. (b) t1[4] = 7 means updation which is not possible in tuple
because tuple is immutable which cannot be changed after
Choose the correct option for t1[6].
creation.
(a) 1 (b) 8
(c) None (d) Error 15. What is the output of following code?
Ans. (d) It will give IndexError because tuple index is out of T = (100)
range. Its maximum index is 5 because index is started from print (T * 2)
0 but in t1[6] asked about index number 6, so it will give an (a) Syntax error (b) (200,)
error. (c) 200 (d) (100, 100)
10. Tuple packs elements or value together, so this is Ans. (c) Tuple T contains a single element, so * is used as
multiplication operator.
called
So, T * 2 = 100 * 2 = 200
(a) pickling (b) unpacking
(c) packing (d) unpickling 16. What will be the output of the following Python
Ans. (c) Tuple packs elements or value together, so this is called code?
packing. In packing, we put values together into a new tuple >>> a=(5,6)
while in unpacking we extract those values into a single >>> b=(2,6)
variable. >>> c=a+b
>>> c
11. Choose the correct output. (a) (7,12)
a = (2, 4, 3, 4) (b) (5,6,2,6)
b = (5, 8, 9)
(c) Error as tuples are immutable
t =a + b
(d) None
print(t)
Ans. (b) In the above piece of code, the values of the tuples are
(a) (2, 4, 3, 4, 5, 8, 9) (b) (7, 12, 12, 4)
not being changed. Both the tuples are simply concatenated.
(c) (2, 10, 13, 4, 9) (d) Error
Ans. (a) To concatenate tuples, (+) operator is used in Python. 17. Choose the correct option.
This operator can easily add the whole of one tuple to other (a) In Python, a tuple can contain only integers as its
tuple and perform concatenation. This operator cannot add elements.
one tuple with other type as number or string, otherwise it (b) In Python, a tuple can contain only strings as its
will give error in such conditions. elements.
(c) In Python, a tuple can contain both integers and strings
12. Suppose tuple t1 = (4, 7, 3, 6, 8, 9) as its elements.
Choose the correct option for t1[: 4]. (d) In Python, a tuple can contain either string or integer but
(a) (3, 6, 8, 9) (b) (4, 7, 3, 6) not both at a time.
(c) (6) (d) (8, 9) Ans. (c) In Python, a tuple can contain both integers and strings
as its elements is the correct option.
Ans. (b) To display a specific range of elements from the tuple, we
use slicing operation. This operation in performed on tuples
with the use of colon (:).
l
Case Based MCQs
To display elements from beginning to a range, use [: index]. 18. Suppose that tuple
So, t1[: 4] will print the element from starting to index−1.
t1=(“Hello”, (“am”, “an”), (“that”, “the”, “this”), “you”,
13. Given a tuple t1= (1, 2, 3, 4, 5, 6, 7, 8, 9). What will “we”, “those”, “these”)
be the output of print (t1 [3 : 7 : 2])? Based on the above information, answer the
(a) (4, 5, 6, 7, 8) (b) (4, 5, 6, 7) following questions.
(c) (4, 5, 6) (d) (4, 6)
(i) Choose the correct option for len(t1).
Ans. (d) t1[3 : 7 : 2] starts from index number 3 to index number (a) 7 (b) 10
7 with gap of 2 elements.
(c) None (d) Error
In t1= (1, 2, 3, 4, 5, 6, 7, 8, 9), element of index number 3 is 4
and after two elements of gap, element is 6. So, output is (ii) What is the output of following code?
(4, 6). print(t1[3 :5])
(a) (‘the’, ‘this’) (b) (‘am’, ‘an’)
14. Given a tuple t1= (1, 2, 3, 4, 5). Identify the (c) (‘you’, ‘we’) (d) (‘you’, ‘we’, ‘those’)
statement that will display an error.
(a) print (t1[3])
(iii) Identify the output of t1[5 : ] + t1[2].
(a) (‘those’, ‘these’, ‘that’)
(b) t1[4] = 7
(b) (‘those’, ‘these’, ‘that’, ‘the’, ‘this’)
(c) print (len (t1))
(c) (‘the’, ‘this’)
(d) print (max (t1)) (d) Error
24 CBSE Term II Computer Science XI
(iv) Identify the output of print (t1[6:]). 2. Explain the mixed data types tuple with an
(a) (‘these’,) example.
(b) (‘those’) Ans. Mixed data types can be created to place different
(c) ‘these’ data types such as integers, strings, double etc into one
(d) Error tuple. For example,
(v) Find the correct output of print (t1[−3]*2). tuple1=(‘English’, 90, ‘Rahul’,‘Meerut’, ‘99.5’)
(a) wewe 3. Observe the following tuple and answer the
(b) youyou questions that follow.
(c) None
t1=(76, 56, ‘Harish’, ‘Ansh’, 98, (45, 34), ‘Muskan’)
(d) IndexError
Ans. (i) (a) len() is used to count the number of elements that
(i) len(t1) (ii) t1[−6]
present in the tuple. Given tuple is a nested tuple, so (iii) t1[3] (iv) t1[: 2]
(“am”, “an”) will considered as one element and (“that”, Ans. (i) 7
“the”, “this”) will considered as one element. Then, this
(ii) 56
will give 7 as output.
(ii) (c) To display a specific range of elements from the tuple, (iii) 'Ansh'
we use slicing operation. This operation is performed on (iv) (76, 56)
tuples with the use of colon (:).
t1[3 : 5] displays the element from index number 3, i.e.
4. Explain sum() method of tuple with an example.
‘you’ to index number ( 5 − 1 = ) 4 i.e. we. So, output will Ans. sum() method is used to calculate the sum of elements of
be (‘you’, ‘we’). tuple. The elements of tuple must be integer.
(iii) (b) To display elements from specific index till the end, Syntax sum(tuple_name)
use [index :], so t1[5:] will display the elements from For example,
index number 5 to till end i.e. (‘those’, ‘these’). >>>price=(100, 150, 95, 120, 80)
To access a particular element, use [index], so t1[2] will >>>sum(price)
display the element of index number 2, i.e. (‘that’, ‘the’, Output
‘this’).
+ operator is used to concatenate the tuples. 545
(iv) (a) To display elements from specific index till the end, 5. Observe the following tuples and answer the
use [Index :]. questions that follow.
So, t1[6:] will display the element from index number 6, t1=(4, 7, 8, 9)
i.e. ‘these’ till the end. t2=(0, 4, 3)
(v) (a) Index number − 3 represents the third element from
end i.e. ‘we’. * is the replication operator that can repeat (i) >>>t=t1+t2
the elements of the tuple. >>>print(t)
So, ‘we’ will be repeat two times because * 2 is given. (ii) >>>t=t1*t2
>>>print(t)
Ans. (i) (4, 7, 8, 9, 0, 4, 3)
PART 2 (ii) It gives TypeError because cannot multiply sequence by
non-int of type ‘tuple’.
Subjective Questions 6. Write a Python program to find maximum and
minimum elements in a tuple.
l
Short Answer Type Questions Ans. tuple1 = (23,45,−65,−45,20,45,65,− 24)
print(“The tuple is:”,tuple1)
1. Distinguish between tuple and list. min1 = tuple1.index (min(tuple1))
Ans. Differences between tuple and list are as follows max1 = tuple1.index (max(tuple1))
Tuple List print(“Maximum element in the tuple is :”, max(tuple1),“ at
index number ”,max1)
Elements of a tuple are Elements of a list are
immutable. mutable. print(“Minimum element in the tuple is :”, min(tuple1),“ at
index number ”,min1)
Tuple is declared in List is declared in square
parenthesis (). brackets [ ]. 7. What do you mean by membership operators in
Tuples cannot be changed Lists can be changed after
Python?
after creation. creation. Ans. Membership operators are used to check whether a
value/variable exists in the sequence like string, list, tuple
Iterating over the elements Iterating over the elements of etc. These operators return True or False as per conditions
of a tuple is fast. a list is slow. met.
CBSE Term II Computer Science XI 25
17. Write a Python code to display all the elements of (iii) Equal to (= =) operator
the following tuple except ‘H’. (iv) Packing
t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’) Ans. (i) Tuple is a collection of Python objects separated by
Ans. t = (‘A’, ‘R’, ‘I’, ‘H’, ‘A’, ‘N’, ‘T’) commas (,) and put the elements in parentheses ( ).
t = t[0 : 3] + t[−3 : ] (ii) in operator is used to check, if a value exists in a sequence.
print (t) (iii) Equal to (= =) operator returns True if the values on
either side of the operator are equal.
Output
(iv) Tuples put all the elements or values together in a
(‘A’, ‘R’, ‘I’, ‘A’, ‘N’, ‘T’) parentheses, is called packing.
18. TypeError occurs while statement 2 is running. 21. Answer the following questions;
Give reason. How can it be corrected?
(i) t1=(25, 78, (45, (65, 89)), 90, (34, 8))
>>> tuple1 = (5) #statement 1 len (t1)
>>> len(tuple1) #statement 2 [NCERT] (ii) t2=(45,(‘The’,78,(‘This’),67),‘The’,67, 67)
Ans. The ‘statement 1’ is creating a variable, tuple1 which is of t2.count(67)
‘int’ data type. The ‘statement 2’ is checking for the length of
the variable, but the argument passed is an ‘int’ data type. (iii) t1=(3,)
The len() function can return the length only when the t2=()
object is a sequence or a collection. This is the reason for t=t1+t2
the type error. any(t)
The error can be corrected by adding one comma after ‘5’ in (iv) t3=(87, 89, 56, 99, 75, 45, 100)
statement 1, as this will create a tuple and as a tuple is a
max(t3)
collection, len() function will not return an error.
Ans. (i) 5 (ii) 2 (iii) True (iv) 100
The correct statement will be
>>> tuple1 = (5,) 22. Write a Python program to count the number of
>>> len(tuple1) elements in a given range using traversal. Also,
19. Prove with the help of an example that the variable display its output.
is rebuilt in case of immutable data types. [NCERT] Ans. c=0
l=40
Ans. When a variable is assigned to the immutable data type, the
r=80
value of the variable cannot be changed in place.
tuple1=(10, 20, 30, 40, 50, 40, 40, 60, 70)
Therefore, if we assign any other value of the variable, the for x in tuple1:
interpreter creates a new memory location for that value and
if x>=l and x<=r:
then points the variable to the new memory location. This is
c+=1
the same process in which we create a new variable. Thus, it
can be said that the variable is rebuilt in case of immutable print(“Tuple:”, tuple1)
data types on every assignment. print(“Elements in a tuple:”,c)
Program to represent the same: Output
v = 20 Tuple : (10, 20, 30, 40, 50, 40, 40, 60, 70)
print(“Before: ”,id(v)) Elements in a tuple : 6
v = 21
print(“After: ”,id(v))
23. Write a Python program to find the common
elements in two tuples.
Output
Ans. tuple1=(45,87,56,−78,36,−12)
Before: 140705582623120
tuple2=(65,32,45,−78,36,−75)
After: 140705582623152
a_set = set(tuple1)
It can be seen that the memory location a variable is pointing
after the assignment is different. The variable is entirely new b_set = set(tuple2)
and it can be said that the variable is rebuilt. if (a_set & b_set):
print(“Common elements are:”,a_set &
l
Long Answer Type Questions b_set)
else:
20. Write the short note on following terms. print(“No common elements”)
(i) Tuple Output
(ii) in operator Common elements are: {−78, 36, 45}
CBSE Term II Computer Science XI 27
24. Write a Python program to calculate the sum and Find the output of the following statements.
mean of the elements in a tuple. (i) print(tuple1.index(45))
Ans. tuple1 = (23,45,20,45,65,24) (ii) print(tuple1.count(45))
print(“The tuple is:”,tuple1)
(iii) print(tuple1 + tuple2)
sm=0
for i in range(len(tuple1)): (iv) print(len(tuple2))
sm=sm+tuple1[i] (v) print(max(tuple1))
mean=sm/num (vi) print(min(tuple1))
print(“SUM = ”,sm)
(vii) print(sum(tuple2))
print(“MEAN = ”,mean)
Output (viii) print(sorted(tuple1))
The tuple is: (23, 45, 20, 45, 65, 24) print(tuple1) [NCERT]
SUM = 222 Ans. (i) 2
MEAN = 44.4 (ii) 3
25. Write a program to find the occurrence of a given (iii) (23, 1,45, 67,45, 9, 55, 45, 100, 200)
element. (iv) 2
Ans. t = (23,45,20,−45,65,24,−45,−23) (v) 67
print(“The tuple is:”,t) (vi) 1
k=0 (vii) 300
num=int(input(“Enter the number to be (viii) [1, 9, 23, 45, 45, 45, 55, 67]
counted:”))
(23,1,45,67,45,9,55,45)
for j in t:
if(j==num): 28. Write a program to read email IDs of n number of
k=k+1 students and store them in a tuple. Create two new
print(“Number”,num,“is appear”,k, “times.”) tuples, one to store only the usernames from the
Output email IDs and second to store domain names from
The tuple is: (23, 45, 20, − 45, 65, 24, − 45, − 23) the email IDs. Print all three tuples at the end of
Enter the number to be counted:45 the program.
Number 45 is appear 1 times. [Hint You may use the function split()] [NCERT]
26. Write a Python program to search an element with Ans. num = int(input(“Enter number of students: ”))
its index number. list1=[]
Ans. tuple1=(12,65,78,−63,−2,3,78,−12) for i in range(num):
sm=0
email=input(“Enter email: ”)
x = int(input(“Enter number to be searched:”))
found = False list1.append(email)
for i in range(len(tuple1)): tuple1=tuple(list1)
if(tuple1[i] == x): username=[]
found = True
print(“%d found at %drd domain=[]
position”%(x,i)) for i in tuple1:
break n,d = i.split(“@”)
if(found == False):
username.append(n)
print(“%d is not in tuple”%x)
Output domain.append(d)
Enter number to be searched: − 63 username = tuple(username)
− 63 found at 3rd position domain = tuple(domain)
print(“Names = ”,username)
27. Consider the following tuples, tuple1 and tuple2.
print(“Domains = ”,domain)
tuple1 = (23,1,45,67,45,9,55,45)
print(“Tuple = ”,tuple1)
tuple2 = (100,200)
28 CBSE Term II Computer Science XI
29. A tuple is a collection of objects which ordered and (iii) Write the syntax to create tuple from an existing
immutable. Tuples are sequences, just like lists. sequence.
The differences between tuples and lists are, the (iv) Observe the output of giving code.
tuples cannot be changed unlike lists and tuples >>>t=[“T”, “U”, “P”, “L”, “E”]
use parentheses, whereas lists use square brackets. >>>t2 = tuple(t)
We can use the index operator [] to access an item >>>t2
in a tuple, where the index starts from 0. (v) What is traversing a tuple in Python?
So, a tuple having 6 elements will have indices Ans. (i) Tuples hold a sequence of heterogeneous elements.
from 0 to 5. Trying to access an index outside of the (ii) Nested tuples are tuple objects where the elements in
tuple index range(6,7,... in this example) will raise the tuples can be tuples themselves.
an IndexError. (iii) new_tuple_name=tuple(sequence)
(iv) (‘T’, ‘U’, ‘P’, ‘L’, ‘E’)
(i) Which types of elements are stored in tuple? (v) Traversing a tuple is a technique to access an individual
(ii) What do you mean by nested tuples? element of that tuple.
Chapter Test
Multiple Choice Questons 9. Suppose the tuple t1 = (2, 3, 4, 7, 1, 6). Find
1. Consider the declaration obj = (2 , ‘Hello’, 3, 4). What (i) t1.index(4)
will be the data type of obj? (ii) t1.count(4)
(a) List (b) Tuple 10. Suppose the tuple t1 = (2, 3, 2, 2, 3, 4, 6, 7).
(c) Dictionary (d) String (i) count (t1) (ii) len(t1)
2. What is the output of followig code? 11. Observe the given tuples and answers the questions
t1=(1, 2, 3, 4, 5, 6, 7, 8) t1 = (1, 2, 3, 4 )
print (t1[2 : 4]) t2 = (5, 6, 7)
(a) (3, 4) (b) (2, 3) (i) >>> t = t1 + t2
(c) (4, 5, 6) (d) (3, 4, 5) >>> print(t)
3. Choose the correct option with respect to Python. (ii) >>> t = t1* t2
(a) Both tuples and lists are immutable. >>> print(t)
(b) Tuples are immutable while lists are mutable.
(c) Both tuples and lists are mutable.
12. Consider the tuple t = (2 ,3 , ‘Hello’, 2, 5, 9) and find out
(d) Tuples are mutable while lists are immutable. the error if any in following code
tuple1 = t + 5
4. Which of the following options will not result in an print(tuple1)
error when performed on tuples in Python where
tupl=(5,2,7,0,3)?
13. Compare the tuple and write the output.
(i) t1 = (4, 5, 6, 9)
(a) tupl[1]=2
t2 = (6, 9, 5, 6)
(b) tupl.append(2)
print(t1 < t2)
(c) tupl1=tupl+ tupl (ii) t1 = (4, 5, 6, 9)
(d) tupl.sort() t2 = (4.0, 5.0, 6.0, 9.0)
5. What will be the output of the following Python code? print(t1 = = t2)
>>>my_tuple = (10, 20, 30, 40)
Long Answer Type Questions
>>>my_tuple.append((50, 60))
>>>print (len(my_tuple)) 14. Write a Python program to count the positive numbers
(a) 1 (b) 6 and negative numbers in a tuple.
(c) 4 (d) Error 15. Write the most appropriate tuple methods for the
6. Is the following Python code valid? following conditions.
>>> a,b=1,2,3 (i) To count the number of elements in a tuple.
(a) Yes, this is an example of tuple unpacking, where a=1 and (ii) Calculate total occurence of given element.
b=2. (iii) Returns the element with maximum value.
(b) Yes, this is an example of tuple unpacking, where a=(1,2) (iv) Returns the element with minimum value.
and b=3.
(v) To sort the given tuple in ascending order.
(c) No, too many values to unpack.
(vi) Returns true if atleast one element is present in the
(d) Yes, this is an example of tuple unpacking, where a=1 and
tuple.
b=(2,3).
(vii) Returns the index of first occurrence of element.
Short Answer Type Questions (viii) Converts string and list into tuple.
7. Observe the following tuple and answer the questions 16. Write a Python program to test if a variable is a list or
that follow tuple.
t = (1, 2, 3, 4, 5,6 ,7,8, 9,10)
17. Write a Python program to sort a list of tuples by the
(i) t[−3] second Item.
(ii) t[: 2]
18. Write a Python program to sort a list of tuples
8. Explain the any () method of tuple with an example. alphabetically.
CHAPTER 03
Dictionary
In this Chapter...
l Creating a Dictionary l Adding Elements to Dictionary
In Python, dictionary is an unordered collection of data Key : Value Pair Key Value
values that stored the key : value pair instead of single value “Abhi” : “Manager” “Abhi” “Manager”
as an element. Keys of a dictionary must be unique and of “Manish” : “Project Manager” “Manish” “Project Manager”
immutable data types such as strings, tuples etc. Immutable
means they cannot be changed after creation. But in “Aasha” : “Analyst” “Aasha” “Analyst”
dictionary, key-value can be repeated and be of any type. “Deepak” : “Programmer” “Deepak” “Programmer”
A dictionary is used to map or associate things you want to “Ishika” : “Tester” “Ishika” “Tester”
store the keys you need to get them. A dictionary in Python is We can also create empty dictionary.
just like a dictionary in the real world. Each key-value pair in
a dictionary is separated by a colon (:) whereas each key is For example, dic1 = { }
separated by a comma (,). In dictionary, key will be a single Dictionaries are also called mappings or hashes or associative
element and values can be a list or list within a list, numbers arrays.
etc. If you give list as key, then it will give an Error
>>> dic = {[1, 2]: “math”}
Creating a Dictionary Trackback (most recent call last):
To create a dictionary in Python key : value pair is used. File “<pyshell#7>”, line 1, in <module>
Dictionary is listed in curly brackets, inside these curly dic = {[1, 2]: “math”}
brackets, keys and values are declared. TypeError : unhashable type : ‘list’
Syntax dictionary_name = {key1 : value1, key2 : value2, …}
For example, Properties of Dictionary Keys
>>>Employees = {“Abhi” : “Manager”, “Manish” : “Project There are following points while using dictionary keys as
Manager”, “Aasha” : “Analyst”, “Deepak” : “Programmer”, follows
“Ishika” : “Tester”} (i) More than one entry per key is not allowed (no
>>> Employees duplicate key is allowed).
Here is the example of dictionary named Employees in (ii) Dictionaries’ keys are case sensitive, same key name
which Emplyees’ names stored as keys and designation but with the different case are treated as different in
stored as values of respected keys. Python.
Output (iii) The values in the dictionary can be of any type while
{‘Abhi’: ‘Manager’, ‘Manish’ : ‘Project Manager’, the keys must be immutable like numbers, tuples or
‘Aasha’ : ‘Analyst’, ‘Deepak’ : ‘Programmer’, ‘Ishika’ : ‘Tester’} strings.
We can separate these dictionaries as follows
CBSE Term II Computer Science XI 31
Syntax Syntax
dict.fromkeys(seq, value) dict.setdefault (key[, default_value])
For example, For example,
>>>key = {1, 2, 3, 4, 5} >>>dic = {‘Akshat’ : 26, ‘Riya’: 24, ‘Shrey’:27}
>>>value = dict.fromkeys (key) >>>dic1 = dic.setdefault (‘Riya’)
>>>print (value) >>>print (‘Dictionary : ’, dic)
{1: None, 2 : None, 3 : None, 4 : None, 5 : None} Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
>>>value1 = dict.fromkeys (key, ‘Hello’) >>>print (‘Founded key : ’, dic1)
>>>print (value1) Founded key : 24
{1 : ‘Hello’, 2 : ‘Hello’, 3 : ‘Hello’, 4 : ‘Hello’, 5 : ‘Hello’}
>>> dic1 = dic.setdefault (‘Muskan’)
(x) copy() >>> print (‘Dictionary :’, dic)
This method returns a shallow copy of the dictionary. Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27, ‘Muskan’ :
None}
Syntax
dict.copy( ) >>> print (‘Founded key : ’ , dic1)
Founded key : None
Here, copy( ) method does not take any parameters.
For example, (xiii) max ()
dic = {1 : ‘One’, 2 : ‘Two’, 3 : ‘Three’} This method is used to return the maximum key from the
dic1 = dic. copy ( ) dictionary.
print (‘Original dictionary : ’, dic) Syntax
print (‘Copied dictionary : ’, dic1) max(dict)
Output For example,
Original dictionary : {1 : ‘One’, 2 : ‘Two’, 3 : ‘Three’} dic = {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
Copied dictionary : {1 : ‘One’, 2 : ‘Two’, 3 : ‘Three’} dic1 = max(dic)
(xi) popitem () print (‘Dictionary : ’, dic)
This method in dictionary helps to achieve similar purpose. print (‘Maximum key : ’, dic1)
It removes the arbitrary key value pair from the dictionary Output
and returns it as a tuple. There is an update for this method Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
from Python version 3.7 onwards.
Maximum key : Shrey
Syntax
dict.popitem( ) (xiv) min ()
For example, This method is used to return the minimum key from the
dic = {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27} dictionary.
print (‘Before deletion : ’, dic) Syntax
dic1 = dic.popitem ( ) min(dict)
print (‘Deleted element’, dic1) For example,
print (‘After deletion :’, dic) dic = {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
Output dic1 = min(dic)
Before deletion : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27} print (‘Dictionary :’, dic)
Deleted element : (‘Shrey’, : 27) print (‘Minimum key :’, dic1)
After deletion : {‘Akshat’ : 26, ‘Riya’ : 24} Output
(xii) setdefault () Dictionary : {‘Akshat’ : 26, ‘Riya’ : 24, ‘Shrey’ : 27}
Minimum key : Akshat
This method returns the value of a key (if the key is in
dictionary). If not, it inserts key with a value to the
dictionary.
Another random document with
no related content on Scribd:
slaughtered in camp and the presents at the end of the journey are
exclusively his. A man guilty of preceding the Pagazi is liable to fine,
and an arrow is extracted from his quiver to substantiate his identity
at the end of the march. Pouring out of the kraal in a disorderly mob,
the porters stack their goods at some tree distant but a few hundred
yards, and allow the late and lazy and the invalids to join the main
body. Generally at this conjuncture the huts are fired by neglect or
mischievousness. The khambi, especially in winter, burns like tinder,
and the next caravan will find a heap of hot ashes and a few charred
sticks still standing. Yet by way of contrast, the Pagazi will often take
the trouble to denote by the usual signposts to those following them
that water is at hand; here and there a little facetiousness appears in
these directions, a mouth is cut in the tree trunk to admit a bit of
wood simulating a pipe, with other representations still more
waggish.
“After the preliminary halt, the caravan forming into the order of
march, winds like a monstrous land serpent over hill, dale, and plain.
The kirangozi is followed by an Indian file; those nearest to him are
heavily laden with ivory. When the weight of the tusk is inordinate it
is tied to a pole and is carried palanquin fashion by two men. The
ivory carriers are succeeded by the bearers of cloth and beads, each
man poising on either shoulder, and sometimes raising upon the
head for rest, packs that resemble huge bolsters, six feet long by two
in diameter, cradled in sticks which generally have a forked
projection for facility in stacking and reshouldering the load. The
sturdiest fellows are usually the lightest loaded in Eastern Africa; as
elsewhere, the weakest go to the wall. The maximum of burden may
be two farasilah, or seventy pounds avoirdupois. Behind the cloth
bearers straggles a long line of porters and slaves laden with the
lighter stuff—rhinoceros teeth, hides, salt, tobacco, brass wire, iron
hoes, boxes and bags, beds and tents, pots and water gourds, mats,
and private stores. With the Pagazi, but in separate parties, march
the armed slaves, who are never seen to quit their muskets; the
women and the little toddling children, who rarely fail to carry
something, be it only of a pound weight; and the asses neatly laden
with saddle-bags of giraffe and buffalo hide. A Mganga also
universally accompanies the caravan, not disdaining to act as a
common porter. The rear is brought up by the master, or the
masters, of the caravan, who often remain far behind for the
convenience of walking and to prevent desertion.
“All the caravan is habited in its worst attire; the East African
derides those who wear upon a journey the cloth which should be
reserved for display at home. If rain fall they will doff the single goat-
skin hung round their sooty limbs and, folding it up, place it between
the shoulders and the load. When grain is served out for a long
march, each porter bears his posho or rations fastened like a large
‘bustle’ to the small of his back. Upon this again he sometimes binds,
with its legs projecting outwards, the three-legged stool, which he
deems necessary to preserve him from the danger of sitting upon the
damp ground. As may be imagined, the barbarians have more
ornament than dress. Some wear a strip of zebra’s mane bound
round the head with the bristly parti-coloured hair standing out like a
saint’s gloria, others prefer a long bit of stiffened ox-tail rising like a
unicorn’s horn at least a foot above the forehead. Other ornaments
are the skins of monkeys and ocelots, roleaus and fillets of white,
blue, or scarlet cloth, and huge bunches of ostrich, crane, and jay’s
feathers crowning the heads like the tufts of certain fowls. Their arms
are decorated with massive ivory bracelets, heavy bangles of brass
and copper, and thin circlets of the same metal, beads in strings and
bands adorn their necks, and small iron bells strapped below the
knee or round the ancle by the more aristocratic. All carry some
weapon; the heaviest armed have a bow and a bark quiver full of
arrows, two or three long spears and assegais, and a little battle-axe,
borne on the shoulder.
“The normal recreations of a march are whistling, singing,
shouting, hooting, horning, drumming, imitating the cries of birds and
beasts, repeating words which are never used except on journeys.
There is gabble enough and abundant squabbling; in fact, perpetual
noise, which the ear, however, soon learns to distinguish for the
hubbub of a halt. The uproar redoubles near a village where the flag
is unfurled and where the line lags to display itself. All give vent to
loud shouts: ‘Hopa, hopa! go on, go on—Mgogolo! a stoppage—
food, food—don’t be tired—the kraal is here—home is near—hasten,
Kirangozi—oh! we see our mothers—we go to eat.’ On the road it is
considered prudent, as well as pleasurable, to be as loud as
possible, in order to impress upon plunderers an exaggerated idea of
the caravan’s strength; for equally good reasons silence is
recommended in the kraal. When threatened with attack, and no
ready escape suggests itself, the porters ground their loads and
prepare for action. It is only self-interest that makes them brave. I
have seen a small cow trotting up with tail erect break a line of 150
men carrying goods not their own. If a hapless hare or antelope
cross the path, every man casts his pack, brandishes his spear, and
starts in pursuit; the animal, never running straight, is soon killed and
torn limb from limb, each hunter devouring his morsel raw. When two
parties meet, that commanded by an Arab claims the road. If both
are Wanyamwezi, violent quarrels ensue; fatal weapons, which are
too ready at hand, are turned to more harmless purposes, the bow
and spear being used as whip and cudgel. These affrays are not
rancorous till blood is shed. Few tribes are less friendly for so trifling
an affair as a broken head; even a slight cut, or a shallow stab, is
little thought of; but if returned with interest great loss of life may
arise from the slenderest cause. When friendly caravans meet, the
two Kirangozis sidle up with a stage pace, a stride and a stand, and
with sidelong looks prance till arrived within distance, then suddenly
and simultaneously ducking, like boys ‘give a back,’ they come to
loggerheads and exchange a butt violently as fighting rams. Their
example is followed by all with a crush which might be mistaken for
the beginning of a faction; but it ends, if there be no bad blood, in
shouts of laughter. The weaker body, however, must yield
precedence and offer a small present as blackmail.”
After all, however, there is some reason in the African’s objection
to be hurried on a march, or to exert himself overmuch in the
interests of a traveller, whose private affairs are nothing to him and
whom, when discharged, he will in all probability never see again. He
does not particularly wish to see him, as he is perfectly comfortable
at home. According to the last quoted authority he rises with the
dawn from his couch of cow’s-hide. The hut is cool and comfortable
during the day; but the barred door, impeding ventilation at night,
causes it to be close and disagreeable. The hour before sunrise
being the coldest time, he usually kindles a fire and addresses
himself to his constant companion the pipe. When the sun becomes
sufficiently powerful, he removes the reed-screen from the entrance
and issues forth to bask in the morning beams. The villages are
populous, and the houses touching one another enable the
occupants, when squatting outside and fronting the central square,
to chat and chatter without moving. About 7 a.m., when the dew has
partially disappeared from the grass, the elder boys drive the flocks
and herds to pasture, with loud shouts and sounding applications of
the quarter staff. They return only when the sun is sinking behind the
western horizon. At 8 p.m. those who have provisions at home enter
the hut to refection with ugali or holcus-porridge, those who have not
join a friend. Pombe, when procurable, is drunk from the earliest
dawn.
After breaking his fast, the African repairs, pipe in hand, to the
Iwanza, the village public previously described. Here in the society of
his own sex he will spend the greater part of the day talking and
laughing, smoking, or torpid with sleep. Occasionally he sits down to
play. As with barbarians generally, gambling in him is a passion. The
normal game is our “heads and tails,” the implement, a flat stone, a
rough circle of tin, or the bottom of a broken pot. The more civilised
have learned the “bas” of the coast, a kind of “tables” with counters
and cups hollowed in a solid plank. Many of the Wanyamwezi have
been compelled by this indulgence to sell themselves into slavery
after playing through their property; they even stake their aged
mothers against the equivalent of an old lady in these lands,—a cow
or a pair of goats. As may be imagined, squabbles are perpetual,
they are almost always, however, settled amongst fellow-villagers
with bloodless weapons. Others, instead of gambling, seek some
employment which, working the hands and leaving the rest of the
body and the mind at ease, is ever a favourite with the Asiatic and
the African; they whittle wood, pierce and wire their pipe sticks—an
art in which all are adepts,—shave one another’s heads, pluck out
their beards, eyebrows, and eyelashes, and prepare and polish their
weapons.
“At about one p.m., the African, unless otherwise employed,
returns to his hut to eat the most substantial and the last meal of the
day, which has been cooked by his women. Eminently gregarious,
however, he often prefers the Iwanza as a dining room, where his
male children, relatives, and friends meet during the most important
hour of the twenty-four. With the savage and the barbarian food is
the all and all of life, food is his thought by day, food is his dream by
night. The civilized European who never knows hunger nor thirst
without the instant means of gratifying every whim of appetite, can
hardly conceive the extent to which his wild brother’s soul is swayed
by stomach; he can scarcely comprehend the state of mental
absorption in which the ravenous human animal broods over the
carcase of an old goat, the delight which he takes in superintending
every part of the cooking process, and the jealous eye with which he
regards all who live better than himself. After eating, the East African
invariably indulges in a long fit of torpidity from which he awakes to
pass the afternoon as he did the forenoon, chatting, playing,
smoking, and chewing sweet earth. Towards sunset all issue forth to
enjoy the coolness; the men sit outside the Iwanza, whilst the
women and the girls, after fetching water for household wants from
the well, collecting in a group upon their little stools, indulge in the
pleasures of gossiping and the pipe. This hour, in the more favoured
parts of the country, is replete with enjoyment. As the hours of
darkness draw nigh, the village doors are carefully closed, and after
milking his cows, each peasant retires to his hut, or passes his time
squatting round the fire with his friends in the Iwanza. He has not yet
learned the art of making a wick, and of filling a bit of pottery with oil.
When a light is wanted he ignites a stick of the oleaginous msásá-
tree—a yellow, hard, close-grained, and elastic wood with few knots,
much used in making spears, bows, and walking staves—which
burns for a quarter of an hour with a brilliant flame. He repairs to his
hard couch before midnight and snores with a single sleep till dawn.
For thorough enjoyment, night must be spent in insensibility, as the
day is in inebriety, and though an early riser he avoids the ‘early to
bed’ in order that he may be able to slumber through half the day.
“Such is the African’s idle day, and thus every summer is spent.
As the wintry rains draw nigh, the necessity of daily bread suggests
itself. The peasants then leave their huts about six or seven a.m.,
often without provision which now becomes scarce, and labour till
noon or two p.m., when they return home, and find food prepared by
the wife or the slave girl. During the afternoon they return to work,
and sometimes, when the rains are near, they are aided by the
women. Towards sunset all wend homeward in a body, laden with
their implements of cultivation, and singing a kind of ‘dulce domum’
in a simple and pleasing recitative.”
Let us conclude this brief sketch of the perils and inconveniences
that menace the explorer of savage shores by presenting the reader
with a picture of the approach of one of the ships bearing some of
the earliest English visitants to the cannibal shores of the Southern
Seas:
“Notwithstanding,” says Mr. Ellis, “all our endeavours to induce the
natives to approach the ship, they continued for a long time at some
distance viewing us with apparent surprise and suspicion. At length
one of the canoes, containing two men and a boy, ventured
alongside. Perceiving a lobster lying among a number of spears at
the bottom of the canoe, I intimated by signs my wish to have it, and
the chief readily handed it up. I gave him in return two or three
middle-size fish-hooks, which, after examining rather curiously, he
gave to the boy, who having no pocket to put them in, or any article
of dress to which they might be attached, instantly deposited them in
his mouth, and continued to hold with both hands the rope hanging
from the ship.
“The principal person in the canoe appeared willing to come on
board. I pointed to the rope he was grasping and put out my hand to
assist him up the ship’s side. He involuntarily laid hold of it, but could
scarcely have felt my grasp when he instantly drew back his hand
and raising it to his nostrils smelt at it most significantly as if to
ascertain with what kind of being he had come in contact. After a few
moments’ pause he climbed over the ship’s side, and as soon as he
had reached the deck our captain led him to a chair on the quarter-
deck, and pointing to the seat signified his wish that he should be
seated. The chief, however, having viewed it for some time, pushed
it aside and sat down on the deck. Our captain had been desirous to
have the chief aboard that he might ascertain from him whether the
island produced sandal-wood, as he was bound to the Marquesas in
search of that article. A piece was therefore procured and shown
him, with the qualities of which he appeared familiar, for after
smelling it and calling it by some name he pointed to the shore.
“While we had been thus engaged, many of the canoes had
approached the ship, and when we turned round a number of the
natives appeared on deck, and others were climbing over the
bulwarks. They were certainly the most savage-looking natives I had
ever seen; and these barbarians were as unceremonious as their
appearance was uninviting. A gigantic, fierce-looking fellow seized a
youth as he was standing by the gangway and endeavoured to lift
him over the deck, but the lad struggling escaped from his grasp. He
then seized our cabin-boy, but the sailors coming to his assistance
and the native finding that he could not disengage him from their
hold, pulled his woollen shirt over his head and was about to leap
into the sea when he was arrested by the sailors. We had a large
ship-dog chained to his kennel on the deck, and although this animal
was not only fearless but savage, yet the appearance of the natives
seemed to terrify him. One of them caught the dog in his arms and
was proceeding over the ship’s side with him, but perceiving him
fastened to his kennel by the chain he was obliged to relinquish his
prize, evidently much disappointed. He then seized the kennel with
the dog in it, when, finding it nailed to the deck, he ceased his
attempts to remove it and gazed round the ship in search of some
object which he could secure. We had brought from Port Jackson
two young kittens; one of these now came up from the cabin, but she
no sooner made her appearance on the deck, than a native,
springing like a tiger on its prey, caught up the unconscious animal
and instantly leaped over the ship’s side into the sea. Hastening to
the side of the deck I looked over the bulwarks and beheld him
swimming rapidly towards a canoe which lay about fifty yards from
the ship. As soon as he had reached this canoe, holding the cat with
both hands, he exhibited it to his companions with evident exultation.
“Orders were given to clear the ship. A general scuffle ensued
between the islanders and the seamen, in which many of the former
were driven headlong into the sea, where they seemed as much at
home as on solid ground; while others clambered over the vessel’s
sides into their canoes. In the midst of the confusion and the
retreating of the natives the dog, which had hitherto slunk into his
kennel, recovered his usual boldness and not only increased the
consternation by his barking, but severely tore the leg of one of the
fugitives who was hastening out of the ship near the spot where he
was chained. The decks were now cleared; but as many of the
people still hung about the shrouds and chains the sailors drew the
long knives with which, when among the islands, they were
furnished, and by menacing gestures, without wounding any,
succeeded in detaching them altogether from the ship. Some of
them seemed quite unconscious of the keenness of the knife, and I
believe had their hands deeply cut by snatching at the blades.”
Boatmen of Rockingham Bay.
The True Word expounded to a Potentate of Western Africa.
PART XI.
RELIGIOUS RITES AND SUPERSTITIONS.
CHAPTER XXVI.
The mysterious “still small voice”—Samoan mythology—The man who
pushed the Heavens up—The child of the Sun—A Figian version
of the “Flood”—The Paradise of the Figian—Lying Ghosts—
Singular case of abduction—The disobedient Naiogabui—All fair
in love and war—The fate of poor Rokoua—The Samoan hades
—Miscellaneous gods of the Samoans—A god for every village—
The cup of truth—Mourning the destruction of a god’s image—
The most fashionable god in Polynesia—Families marked for
human sacrifice—“Tapu” or “tabu”—Its antiquity and wide-spread
influence—Muzzled pigs and blindfolded chickens—Ceremony of
releasing the porkers—Tremendous feast of baked pig—The tapu
in New Zealand—A terrible tinder box—The sacred pole and the
missionaries—The chief’s backbone—The Pakeka and the iron
pot—One of the best uses of tapu—Its general advantages and
disadvantages—Tapu among the Samoans—Witchcraft in New
Zealand—Visit of a European to a “retired” witch—The religion of
the Dayak—“Tapa,” “Tenahi,” “Iang,” and “Jirong”—Warriors’
ghosts—Religious rites and superstitions of the Sea Dayaks—
The great god Singallong Burong—Belief in dreams among the
Sea Dayaks—Story of the stone bull—Of the painted dog.