You are on page 1of 11

COMPUTER SCIENCE WITH PYTHON

CLASS XI
CHAPTER 6
Lists
QUESTION BANK/ASSIGNMENT

1. What are the various ways to create a list?


2. What are the similarities between strings and lists?
3. Why are lists called mutable data type?
4. Define the following functions:
a) len()
b) pop()
c) sort()
d) append()
e) remove()
f) sorted()
g) max()
h) count()
i) sum()

5. What is the difference between insert() and append() methods of a list?

6. Suppose L= [10, ["few", "facts", "fun"], 3, 'Good' ]


Consider the above list and answer the following:
a) L[::2]
b) 6 LI3:1
c) (iii) L[1:21
d) (iv) L(1) [1]
7. Find the output of the following:
L1= [1, 2, 3]
12=(4,5,6)
print(Ll+list ("45"))
print (L1.pop () )
L1. remove (2)
print (Ll)
Li.extend (L2)
print (L2)
8. What will be the output of the following statements?
(i) list1 = [12, 32, 65,26, 80, 10]
listl.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[:31 + list1[3:]
(iv) list1 = [1,2,3,4,5]
listl [len (list1)-1]
9. What will be the output of the following code segment?
myList = [1,2, 3,4,5, 6,7,8,9,10]
for i in range (0, len (myList)):
if 182 == 0:
print (myList [i])
10. What will be the output of the following code segment?
(i) myList = [1,2, 3,4, 5, 6, 7,8, 9, 10]
del myList [3:]
print (myList)
(hi) myList = [1,2,3,4,5, 6,7,8,9, 10]
del myList(:5]
print (myList)

(il) mylist = (1,2,3,4,5,6,7, 8, 9, 10)


del myList (::2)
print (myList)
41. write the output of the following Python program code:
Str2= list ("Cam@123*")
for 1 in range (len (Str2)-1):
1f le=5:
str2(1)= Str2 [1]*2
elif (Str2 (il.isupper ()) :
str2 [il = Str2 [1]*2
elif (Str2 (il.isdigit ()):
Str2 (i] = 'D'
print (Str2)
12. Differentiate between append() and extend() methods of list.
13. Write a program to read a list of n integers (positive as well as negative).
Create two new lists, one having all positive numbers and the other having all
negative numbers from the given list. Print all three lists.
14. Write a program to find the largest and the second largest elements in a
given list of elements.
15. Write a program to read a list of n integers and find their median.
Note: The median value of a list of values is the middle one when they are
arranged in order. If there are two middle values, then take their average.
Hint: Use an inbuilt function to sort the list.
16. What is the basic principle of sorting in insertion sort?
17. Which sorting is more efficient-bubble sort or insertion sort? Give reason.
18. Write a program to read a list of elements. Modify this list so that it does not
contain any duplicate elements, ie., all elements occurring multiple times in the
list should appear only once.
19. Write a program to create a list of elements. Input an element from the user
that has to be inserted in the list. Also, input the position at which it is to be
inserted.
20. Write a program to read elements of a list and do the following:
(i) The program should ask for the position of the element to be deleted from
the list and delete the element at the desired position in the list.
(il) The program should ask for the value of the element to be deleted from the
list and delete this value from the list.
21. WAP that takes an array S as an argument and add all the odd values and
display the sum.
22. Write a program to calculate mean of a given list of numbers.
23. WAP in Python to delete all duplicate elements in a list.
For example,
If list is: 15. 2, 4, -5, 12, 2, 7, 4)
After deleting duplicate elements, new list should be: (5, 2, 4, -5, 12, 7]
24. Write a program to calculate the minimum element of a given list of
numbers.
25. Write a code to calculate and display total marks and percentage of a student
from the given list storing marks of a student.
26. WAP to multiply an element by 2 if it is odd index for a given list
containing both numbers and strings.
27. WAP to count the frequency of an element in a given list.
2. WAP to shift elements of a list so that first element moves to the second
index and second index moves to the third index, etc., and last element shifts to
the first position.
Suppose list is [10.20.30 40]
After shifting it should look like: [20,30,40,10|
Lets in Python
7.59

29. An array Num contains the following elements:


3, 25, 13, 6, 35, 8, 14, 45
wire a unction to swap the content with next value divisible by 5 so that the
resultant array looks le
25, 3, 13, 35, 6, 8, 45, 14
30. The record of a student (Name, Roll No, Marks in five subjects and
percentage of marks) is stored in the following list:
studRecord = ('Rinku', 'A-36', [56, 98, 99,72, 691, 78.8]
Write Python statements to retrieve the following information from the list
studRecord. (il Percentage of the student (iil Marks in the fifth subject (if)
Maximum marks of the student (iv) Roll No. of the student
(v) Change the name of the student from 'Rinku' to 'Rajat'
31. What will be the status of the following list after fourth pass of insertion sort
and fourth pass of bubble sort used for arranging elements in ascending order?
12, 14, -54, 64, 90, 24
32. Write the steps to arrange the following elements using insertion sort:
12, 5, 14, 8, 3, 54, 25, 10, 27, 30
CASE-BASED/SOURCE-BASED INTEGRATED QUESTIONS
1. A bank is a financial institution involved in borrowing and lending of money.
With advancements in technology, online banking, also known as internet
banking, allows customers of a bank to conduct a range of financial transactions
through the bank's website any time, anywhere.
Two basic operations performed in an account are Deposit and Withdrawal.
Write a menu-driven program that accepts either of the two choices of Deposit
and Withdrawal, then accepts an amount, performs the transaction and
accordingly displays the balance. The program should display the following
options:
Open a savings bank account
Add a customer
Deposit money
Display sorted records
Close/delete account
Ans.

Pojective Type Questions


Mutiple Choice Questions
List can contain values of these types:
6. Given a list L= [10, 20, 30, 40, 50, 60, 70], what
(a) integers
(b) floats
would LI1: 4] return ?
(c) Lis.:
(d) tuples
(a) [10, 20, 30, 40] (b) [20, 30, 40, 50]
(e) all of these
(c) [20, 30, 40)
(d) 130, 40, 50]
2 Which of the following will create an empty
7. Given a list L= [10, 20, 30, 40, 50, 60, 701, what
list?
would LI2: -21 return?
(a) L= [1
(b) L = list(0)
(a) [10, 20, 30, 40] (b) [20, 30, 40, 50]
(c) L = list )
(d) L = List(empty)
(c) [20, 30, 40] (d) [30, 40, 50]
3. Which of the following will return the last
8. Given a list L= [10, 20, 30, 40, 50, 60, 70], what
element of a list Lwith 5 elements ?
would LI-4: -1] return ?
(a) L(5]
(b) L[4]
(a) [20, 30, 40] (b) [30, 40, 50]
(c) L 1-1]
(d) L[6]
(c) [40, 50, 60] (d) 150, 60, 701
4. IfL = [1, 2] then L * 2 will yield
9. Given a list L= [10, 20, 30, 40, 50, 60, 70), what
(a) [1, 2] * 2
would LI-3: 991 return?
(b) [1, 2, 2]
(c) (1, 1, 2, 2] (d) [1, 2, 1, 2]
(n) [20, 30, 40] (b) [30, 40, 501
5, IfL1 =(1, 3, 5) and L2 = [2, 4, 6] then L1 + 12 will
(c) [40, 50, 60] (d) [50, 60, 70]
yield
10. To find the last element of list namely 'smiles'
(0) 1,2,3,4,5,61 (6) 11,3,5.2,4,61
in Python,
will be used.
(c) (3, 7, 11]
(d) [1, 3, 5, [2, 4, 6]]
(a) smiles|0]
(b) smiles(-1]
(c) smiles[lpos]
(d) smiles[:-1)
402
COMPUTER SCIENCE WITH PATHOR
11. Out of the following what is correct syntax to 20. Which of the following
can add
copy one list into another ?
elements to a list?
(a) listA = listBi I
(a) add()
(b) append()
(b) listA - listB[:] (c) listA - listB[ I)
(c) extend()
(d) none of these
(d) listA - list(listB)
[21. Which of the following will always retuma.
12. What is printed by the Python code?
(a) max()
(b) min()
(c) sort()
print(list(range (3)))
(d) sorted()
(a) [0, 1, 2, 3] (b) [1, 2, 3]
(c) 10, 1, 2]
(d) 0, 1, 2
22. Which of the following can delete an elemen
from a list if the index of the element is given;
(a) pop()
(b) remove )
13. Which of the following commands will create a list?
(c) del
(d) all of these
(a) listl = list )
(b) listl = []
23. Which of the following can delete an eleme
(c) list1 = list([1, 2, 31) (d) all of these
from a list, if its value is given ?
14. What is the output
when we execute
(a) pop()
(b) remove()
(c) del
(d) all of these
list("hello")?
(a) ['h', 'e', 'I', l', 'o'].
24. Which of the following searches for an elem in a list and returns its index ?
(b) ['hello'].
(c) ['llo'].
(a) search()
(b) find()
(d) l'olleh'].
(c) index()
(d) Isearch()
15. What gets printed ?
names = ['Hasan', 'Balwant", 'Sean', 'Dia']
25. Which of the following can copy a list b another list?
print (names [-1][-11)
(a) list()
(b) n
(e) a
(b) new()
(d) = operator
(а) H
(c) сору( )
(d) Dia
(c) Hasan
16. What is the output of the following
1 = [None] * 10
print(len(1))
_ can be
(b) 0
(a) 10
(c) Syntax Error (d) None
17. Consider the list aList = ["SIPO", [1, 3, 5, 71 ].
What would the following code print?
print(alist[0][1], aList[1][1])
operator
(b) S, 1
(a) S, 3
(d) I, 1
(c) 1, 3
18. Which of the following is a standard Python library function and not an
exclusively list function?
(b) remove()
(a) append()
(d) len()
(c) pop()
19. Which of the following can add only one value to a list?
(a) add()
(b) append()
(d) none of these

Fill in the Blanks


1. Lists are
data types and thus their
values can be changed.
2. To create an empty list, function
can be
used.
3. The
operator adds one list to the end of
another list.
4. The
operator replicates a list.
5. To check if an element is in list,
_ operator
is used.
6. To delete a list slice from a list, is used.
7. A
list contains another list as its member.
8. The
function is used to insert an
element at a designated position in a list.
9. The
function is used to delete an
element to remove an element from a designated index in a list.
10. The
function can append a list of
elements to a list.

A __________ is a standard library that returns the total number of elements of


the list.
What will be the output of: l = [[1,2,3],[4,5,6],7]; print(len(l))?
3
7
2
None of these

Which of the following function is used to convert any sequence/object into a


list object?
l[]
list()
convert_list()
l.list()
You cannot convert any tuple, dictionary object into the list. (True/False)
What will the output of l=[22,33,45,67,89]; print(l.index(67))?
4
3
67
-2
When the element is not present in the list and user try to find out the index of a
given element, it returns:
index not found
Error – Element is not in list
0
None
Which of the following method is used to add a single element to the existing
list?
add()
extend()
addelement()
append()
Which of the following method is used to insert multiple elements into the list?
add()
append()
extend()
insert()
The append() and extend() method add an element to the end of the list.
(True/False)
The _____________ method add an element at specified index or position.
The ___________ method removes the last element from the list.
The ___________ list method removes the specified element.
The ________________ list method removes all the elements from the list.
Which of the following method will count the frequency of the list elements?
count()
list_count()
countElement()
countFrequency()
The reverse method returns the list in reverse order of the elements in place.
(True/False)
Which of the following parameter is required to return the list in descending
order with sort method?
order=descending
sort!=ascending
reverse=True
orderby=descending
Which of the following method returns a new list after rearranging the list
elements?
sort()
sorted()
list_sort()
sort()=new list()
You can print the maximum and minimum values from the list using max() and
min() methods.
Which of the following list method is used to return the addition of all list
elements?
add()
sum()
autosum()
listSum()
You can remove an element by specifying its index using the pop method.
(True/False)
Let’s have a look at answers for objective type questions QnA List methods
class 11.

len()
3
list()
False
3
Error – is not in list
append()
extend()
True
insert()
pop()
remove()
clear()
count()
True
reverse=True
sorted()
True
sum()
True
Subjective Type questions
Write the significance use of following standard methods.
len
list
Find the output:
l=list(‘ListMethods’);print(l)
l=((78,90,12,34));print(l)
l=list({‘Karthik’:90,’Manoj’:85})
What is the use of index() method? Explain with example.
Explain the ValueError exception with example.
Differentiate between append(),extend() and insert() methods.
Differentiate between pop(), remove() and clear() methods.
What is the use of count() method? Explain with example.
Justify the statement: “reverse() does not return anything.”
Differentiate between sort() and sorted() methods.
What do you mean two-dimensional lists?
How to create and traverse 2D lists?

Output Questions:
[1]
l1 = [78,89,67,45,69,42,89,]
n = l1.index(89) + l1.index(42)
print(l1.count(89))
l1.append(l1.count(100)+34)
print(l1.len())
[2]
l1=[56,45,23,12,'ABC']

l1.extend([85,63])

l1.insert(3,99)

l1.pop()

print(l1)

l1.insert(0,101)

l1.insert(2,111)
l1.pop(2)

l1.remove('ABC')

print(l1)
[3]

l = [9,5,3,6,7,8]

l.sort()

l.reverse()

print(l)

n=sum(l)+max(l)+min(l)

print(n)
Now let’s see some error questions for QnA List methods Class 11:

Error Based Questions


[1]

l = (9,5,3,6,7,8)
print(l.len())

[2]

rno=int(input("Enter the rollno:"))


stu_name=input("Enter the name:")
fees=int(input("Enter the Fees:"))
stu_rec=list(rno,stu_name,fees)
print(stu_rec)
l.index(fees)
l.append('Manali')
l.insert(56)
[3]

l=['Jan','Feb','Mar','Apr']
l.index(2)
l.remove('Jun')
print(sort(l))
n = l.max()

You might also like