0% found this document useful (0 votes)
41 views5 pages

List Worksheet

Cs

Uploaded by

crisaswin28
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)
41 views5 pages

List Worksheet

Cs

Uploaded by

crisaswin28
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/ 5

OMSAKTHI

G B PUBLIC SCHOOL
DEPARTMENT OF COMPUTER SCIENCE
CLASS XI LIST WORKSHEET
Q1. Identify the output of the following Python statements.
L1=[6,4,2,9,7]
L1[3:]= “100”
(a) [6,4,2,9,7,100] (b) [6,4,2,100] (c) [6,4,2,1,0,0] (d) [6,4,2, ‘1’,’0’,’0’]
Q2. What will be the output of following Python Code:
data=[10,"ram",20,"sham",30,"anil"]
data.append("Sunil")
data[2]="Raj"
data.pop()
del data[1]
data[-1]="Magic"
print(data)
Q3. What will be the output of following Python Code:
numbers=[10,15,20,25]
for i in range(len(num)):
if num[i]%2==0:
num[i]/=2
else:
num[i]*=2
Q4. What will be the output of following Python Code:
data=[10,20,30,40,50,60]
for x in range(0,len(num),2):
num[x], num[x+1]=num[x+1], num[x]
Q5. Identify the output of the following Python statements:
L= [3,1,4]
M= [11, 5, 9]
L.insert(1,21)
M.insert(0,7)
l = len(L)
N= [ ]
for a in range (l) :
N.append(L[a]+M[a])
print(N)
Q6. L = [12, 25, 8, 75]
for i in range (N):
if M[i]%5 == 0:
M[i] //= 5
if M[i] %3 == 0:
M[i] //= 3
for i in L:
print(i, end = "#")
Q7. Identify the output of the following Python statements.
l1 = [10,15,16,18,20]
l1.remove(15)
l1.insert(1,30)
print (l1[::-2])
Q8. Identify the output of the following Python statements.
lst = [40, 15, 20, 25, 30]
lst.sort()
lst.insert(3, 4)
lst.append(23)
print(lst)
Q9. Write the output of the following code:
L = [30,5,13]
for i in range(N):
if M[i]%2 == 0:
M[i]//=2
if M[i]%5 == 0:
M[i]//=5
for i in L:
print(i,end=" @ ")
Q10. Write the output of the following:
print(list(i*2 for i in range(4)))
print(list(range(4)))
Q11. What will be the output of the following Python code : (5)
mylist =[‘java’,’c++’,’python’,’vb’,’vc++’,’php’,’cobol’]
print(mylist.pop())
mylist.append(‘c#’)
print(len(mylist))
mylist.insert(3,’basic’)
print(mylist)
mylist.sort()
print(mylist)
mylist.index(‘php’)
Q12. Predict the output of the following code:
S='AIM'
L=[10,21,33,4]
for i in range(len(S)):
if i%2==0:
L.insert(i,S[i])
else:
L.pop(i)
print(L)
else:
print(L.clear(),len(L))
Q13. Given Lst=[30,10,90,80], which of the following will remove all the elements in the
list and make it an empty list:
a. del Lst[:] b. Lst[:] = [] c. del Lst[0:len(Lst)] d. All of the above
Q14. Write the Python statement(Single statement only) for each of the following tasks
using BUILT-IN functions/methods only:
(i) To return the list L sorted in descending order
(ii) To search a substring SS in the main string MS and return
the index of the substring SS if found otherwise an error.
(iii) To add the elements of list L2 in L1
(iv) To check whether a string named, sample ends with a full stop/period or not
Q15. Consider:
Str,Lst=”Global warming”,[‘E’,’X’,’A’,’M’,’2023’]
Write Python statement(single statement only) for each of the
following tasks using BUILT-IN functions/methods only:
(i) To replace all occurrences of letter ‘a’ in the string with ‘*’
(ii) To return the highest and the least value in the list
(iii) To check if the string is in title case
(iv) To arrange the list elements in alphabetical order.
Q16. Give the output of the following code::
L=[10,31,11,34,23,46]
for i in range(len(L)):
if L[i]%2!=0 and i%2==0:
L[i]+=10
elif L[i]%2==0:
L[i]*=3
else:
L[i]=0
print(L)

Q17. Write the correct output of the following code:


z= [y for y in range(50) if y % 2 == 0 if y % 5 == 0]
print(z)
k = ["Ok" if i%3!=0 else "OKOk" for i in range(5)]
print(k)

Q18. Identify the output of the following Python statements


L1, L2 = [10, 15, 20, 25], []
for i in range(len(L1)) :
L2. insert( i,Ll.pop())
print (LI, L2,sep="&")
(a) []&[25, 20, 15, 10]
(b) [10, 15, 20, 25]&[25, 20, 15, 10]
(c) [10, 15, 20, 25]&[10, 15, 20, 25]
(d) [25, 20, 15, 10]&[]
Q19. What will be the output of the following Python code ?
L = [10, 20]
L1=[30, 40]
L2=[50, 60]
L.append(L1)
L.extend(L2)
print(L)
(a) [60, 50, 40, 30, 20, 10] (b) [10, 20, 30, 40, 50, 60]
(c) [10, 20, 30, 40, [50, 60]] (d) [10, 20, [30, 40], 50, 60]
Q20. What is the output of the following Python code ?
def ListChange():
for i in range(len(L)):
if L[i]%2 == 0:
L[i]=L[i]*2
if L[i]%3 == 0:
L[i]=L[i]*3
else :
L[i]=L[i]*5
L = [2,6,9,10]
ListChange()
for i in L:
print(i,end="#")
(a) 4#12#27#20# (b) 6#18#27#50#
(c) 20#36#27#100# (d) Error
Q21. Which of the following option can be the output for the following Python
code ?
Ll = [10,20,30,20,10]
L2 = []
for i in Ll:
if i not in L2:
L2.append(i)
print(Ll, L2,sep="&")
(a) [10,20,30,20,10]&[10,20,30,20,10]
(b) [10,20,30,20,10][10,20,30,20,10]&
(c) [10,20,30,20,10]&[30,20,10]
(d) [10,20,30,20,10]&[10,20,30]
Q22. Write the output of the following
lst=["HTML","C++", "JAVA"," PYTHON","VB","BASIC","FORTRAN"]
del lst[4]
lst.remove("JAVA")
lst.pop(3)
print(lst)
Q23. Given a list t=[11,2,3,4,5,6,7,8,9]. What will be the output of
print (t[3:7:2])?
Q24. Gven a list a=[1,2,3,4,5,5,7,1].
Write python statements for the following.
(l) i. Find the position of element 2.
ii.Add the list b=[8,9,10] to the end of list a so that the length of the list a becomes
11.
Q25. Given a list a= [1,2,3,4,5,5,7,1]. Write Python statements for the following: (2)
i. Find, how many times the element 5 occurs in the list a
ii. Find the position of element 2
iii. Add the list b= [8,9,10] to the end of list a so that the length of
the list a becomes 11.
iv. Arrange the elements of list a in ascending order.
Q26. Find the output of the following code: (2)
x=[10,20,30,40]
for k in range(1,4,2):
x[k]= x[k] * 2
x[k-1]=x[k-1] // 2
print(x)
Q27. Consider the list L = ["Science", [ "Commerce", "Humanities", "Arts"] ]. Which of
the following statements gives the output „man‟?
a) print(L[1] [1] [2 : 5]) b) print(L [1][2][2 : 5])
c) L[2] [0] d) L[2] [0 : 2]
Q28. Start with the list [8,9,10]. Do the following:
(a) Set the second entry (index 1) to 17
(b) Add 4, 5, and 6 to the end of the list
(c) Remove the first entry from the list
(d) Sort the list
(e) Double the list
(f) Insert 25 at index 3
Q29. Create the following lists using a for loop.
(a) A list consisting of the integers 0 through 49
(b) A list containing the squares of the integers 1 through 50.
(c) The list ['a','bb','ccc','dddd', . . . ] that ends with 26 copies of the letter z.
Q30. Find the output for the following code (2)
colors = ['red', 'orange', 'green']
colors.extend(['black', 'blue'])
colors.append('purple')
colors.insert(2, 'yellow')
colors.remove('black')
print(colors)

You might also like