0% found this document useful (0 votes)
223 views

List and Tuples

The document contains questions about Python lists, tuples, and basic operations on them like indexing, slicing, concatenation, etc. Some questions test basic list/tuple operations like indexing, slicing, modifying elements. Other questions involve more complex operations like searching/filtering lists based on conditions, calculating sums of list elements after applying functions, inserting/deleting elements at specific indexes.

Uploaded by

RAUNAK DEY
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)
223 views

List and Tuples

The document contains questions about Python lists, tuples, and basic operations on them like indexing, slicing, concatenation, etc. Some questions test basic list/tuple operations like indexing, slicing, modifying elements. Other questions involve more complex operations like searching/filtering lists based on conditions, calculating sums of list elements after applying functions, inserting/deleting elements at specific indexes.

Uploaded by

RAUNAK DEY
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/ 4

LIST AND TUPLES WORKSHEET

1. Write the output of the following code:


t=(10,22,3,6)
s=(11,3,10,35)
for i in t:
if i in s:
print(i)

2. What will be the output of the following Python code:


>>>X="GoodWork"
>>>tuple(X)

3. Find and write the output of the following python code:


Data = ["P",20,"R",10,"S",30]
Times = 0
Alpha =""
Add = 0
for C in range(1,6,2):
Times= Times +C
Alpha= Alpha + Data[C-1]+"$"
Add = Add + Data[C]
print( Times, Add,Alpha)

4 Refer the following code for answering the questions below :


>>>a=[1,2,3]
>>>b=[4,5,6]
>>>c=a+b
>>>d=c[0:3]
>>>e=d
>>>a[0]=10
>>>c[4]=20
>>>e[2]=30
What will be the output of the following statements?
i. print(a[1])
ii. print((b[0])
iii. print(d)
iv. print(c[:])

5. Start with the list [8, 9, 10]. Do the following using list functions
i. Set the second entry (index 1) to 17
ii. Remove the first entry from the list.
iii. Sort the list.
iv. Insert 25 at index 3
7 If a=[4,3,2,5,6] and S = “WELCOME”, write the output of the following:
(i) print(a[:-3:-1])
(ii) print(a[-3:4])
(iii) print(S[::-1])

9 WAP to search and display those strings from the list of Names, which are ending with ‘A’.
For example,
If the Names contain [“JAYA”, “KAREEM”, “TARUNA”, “KAMINI”]
The function should display
JAYA
TARUNA

10 WAP to add and display the sum of ten times the even value present in the list of VALUES.
For example ,
If list contains VALUES= [5,2,3,6,3,4]
The program should display
Sum of (2x10 +6x10+4x10) ie. 120

11 WAP python program to remove an element ‘3’ from the following tuple:
T1=(1,2,3,4,5)
o/p=(1,2,4,5)

13 Kritika was asked to accept a list of even numbers but she did not put the relevant condition
while accepting the list of numbers. You are required to write a program that accepts the List L
from the user and convert all the odd numbers into even by multiplying them by 2.

14 Name the error which will be displayed while executing the following code:
L=[1,2,3,4,5]
print(L[5])

16 Find the output of the following Python code:-


l1=[500,600]
l2=[35,45]
l1.append(700)
l1.extend(l2)
l1.insert(2,25)
print(l1)
print(l2*2)
print(l1.index(35))

17 Find the output of the following Python code:-


t=(10,20,30,40,50,60,70,20,30,50)
i. print(t)
ii. print(max(t))
iii. print(t.count(20)
iv. print(t[0]+5)
v. print(t.index[40])
vi. print(min(t)+len(t))

18 Give the elements of the following string which are present at the given index numbers:
str="Hard work pays off"
str [2]
str [-3]
str [2:5]
str [2:5:2]
str [:5]
str [3:]
str [::2]
str [::-2]
str [-5:-2]
str [5:2:-1]
str [-2:-5:-1]
str [-2:-5:-2]

19 Find the incorrect statement/s out of the following:


a) >>> tup1=(1,'2',3,4,5,"6",7,8,9)
b) >>>tup4=(170,)
c) >>>tup6= (500)
d) >>>tup7=tuple()
e) >>>tup10=5, 10, 15, 20

20 If
>>>tup1=("bag", "book", "copy", "lunch box", "pencil box")
>>>tup2=(5, 10, 15, 20, 25, 30, 35)
Give the output:
a) >>>tup3= tup1[:]
b) >>>tup4= tup2[1:5]

21 Consider the list planets and states and give the output of the following Python statements:
planets=['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']
states=['Delhi', 'Kerala', 'Tamil Nadu', 'Bihar', 'Delhi']
a) planets=planets+”Tamil”
b) states=states*2
c) len(planets)
d) max(planets)
e) min(planets)
f) states.count(‘Delhi’)
22 Consider the following list:
monuments=[ 'Kutub Minar', 10, 'Taj Mahal', 20, 'India Gate', 30, 'Char Minar', 40]
states=['Delhi', 'Kerala', 'Tamil Nadu', 'Bihar']
Write Python statements for the following:
a) To insert “Red Fort” at index number 5
b) To add 50 at the end of the list
c) To add list states at the end of the list monuments
d) To replace 3rd, 4th and 5th element of the monuments list by “India”.
e) To remove the third element from the list monuments.
f) To delete 3rd to 5th elements from the list monuments.
g) To display the index number of the element “Kerala” from the states list.
h) To check whether the element 20 is present in the list or not.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy