0% found this document useful (0 votes)
22 views2 pages

Worksheet - List

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Worksheet - List

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

GURU HARKRISHAN PUBLIC SCHOOL KALKAJI SUBJECT : COMP. SC. / I.P.

NEW DELHI-110019 CLASS : XI-A & XI-C


CHAPTER : LIST IN PYTHON
WORKSHEET - LIST

Key points to remember:


 List is a collection of comma separated values enclosed in square brackets.
 It is an indexed collection of data with positive and negative indexing
 List is a mutable/changeable data type
 List allow concatenation, membership, repetition, indexing, traversal and slicing operations.
 Lists are comparable using relational operators >, <, <=, >=, !=, ==
 Built in functions such as max(), min(), sum(), len(), sorted() etc. can also work with list.
 List functions are append(), extend(), insert(), remove(), pop(), clear(), index(), sort(), reverse(), count(),
copy()
 List can be nested

Multiple-Choice Questions (MCQs)


Q1. What is the output of the following code? (a) 2 (b) 3
list1 = [1, 2, 3] (c) Error (d) None
list2 = list1
list2[1] = 99 Q4. What is the output of the following code?
print(list1) list1 = [10, 20, 30, 40]
print(list1[1:3])
(a) [1, 2, 3] (b) [1, 99, 3]
(c) [99, 2, 3] (d) Error (a) [20, 30] (b) [10, 20]
(c) [30, 40] (d) [20, 30, 40]
Q2. Which of the following methods is used to add
an element at a specific position in a list? Q5. What does the following code return?
(a) append() (b) insert() list1 = [10, 20, 30, 40]
(c) extend() (d) pop() print(list1[1:3])

Q3. What does the following code return? (a) [5, 10] (b) [10, 20]
list1 = [1, 2, 3, 4] (c) [5, 15] (d) [15, 20]
list1.index(3)
True/False
1. A list in Python can be resized dynamically. 7. The index() method returns the index of the
2. The append() method can add multiple last occurrence of an element in the list.
elements to a list simultaneously. 8. Lists support both positive and negative
3. A list in Python can contain duplicate indexing.
elements. 9. The sort() method creates a new sorted list
4. Slicing a list modifies the original list. without modifying the original list.
5. Lists are always mutable in Python. 10. Lists in Python are similar to arrays in C but
6. The del keyword can be used to remove a slice allow heterogeneous data types.
of elements from a list.
Case Study-Based Questions
Case Study 1: Q1. Write the Python code to calculate the total
A student records marks in three subjects: marks.
marks = [85, 78, 92, 4, 67] Q2. Find the highest mark in the list.

1
GURU HARKRISHAN PUBLIC SCHOOL KALKAJI SUBJECT : COMP. SC. / I.P.
NEW DELHI-110019 CLASS : XI-A & XI-C
CHAPTER : LIST IN PYTHON
WORKSHEET - LIST

Q3. Add 5 grace marks to each subject and display


the updated list. Case Study 3:
A cricket team records scores of its players in a
Case Study 2: match:
A shopkeeper maintains a list of items available in scores = [15, 25, 10, 5, 0]
the store: Q1. Calculate the average score of the team.
items = ['soap', 'shampoo', 'detergent'] Q2. Sort the scores in descending order.
Q1. Write a Python program to check if Q3. Remove all scores that are below 10.
'toothpaste' is available in the list.
Q2. Add 'toothpaste' to the list if it is not present.
Q3. Remove the item 'soap' from the list.
Output Based Questions
Write the output of the following code:
1. 7. l = [None] * 10; print(len(l))
theList=[1, 2, [1.1, 2.2]] 8.
print(len(theList)) sampleList = [10, 20, 30, 40, 50]
2. sampleList.pop(); print(sampleList);
L=['apple','banana','mango'] sampleList.pop(2) print(sampleList)
for fruit in L: 9.
print("I like",fruit) A = [2, 4, 6, 8,10]
3. L = len(A)
odd = [1, 9] S = 0
odd.insert(1,3); print(odd) for I in range (1, L, 2):
odd[2:2] = [5, 7] S+=A[I]
print(odd) print("Sum=",S)
4. 10.
odd = [1, 3, 5] l=[10,20,30,40,50,60]
print(odd + [9, 7, 5]) for i in range(1,6):
print(["re"] * 3) l[i-1]=l[i]
5. for i in range(0,6):
L1 = list() print(l[i],end='')
L1.append([1, [2, 3], 4]) 11.
L1.extend([7, 8, 9]) l=[6,12,18,24,30]
print(L1[0][1][1] + L1[2]) for i in l:
6. for j in range(1,i%5):
List = [True, 50, 10] print(j,'#',end='')
List.insert(2, 5)
print(List, "Sum is: ", sum(List))

Coding Questions
Q1. Design a program for a group of friends to share Q2. Write a program to manage customer feedback
expenses. The program should: ratings for a product. The program should:
(a) Allow users to input the expenses for each person (a) Accept ratings out of (1,2,3,4,5) from customers
and store them in a list. and store them in a list.
(b) Calculate the total and average expense. (b) Calculate the average rating.
(c) Identify who spent the most and the least. (c) Count and display how many customers gave a
(d) Display the expense list in descending order. rating above 3.
(d) Remove ratings below a user-defined threshold.

You might also like