0% found this document useful (0 votes)
64 views4 pages

Py Set-2

This document contains code for 4 Python programming practical exercises. The first creates and manipulates lists using methods like append, extend, remove, and reverse. It also sorts lists in ascending and descending order. The second extracts elements from a nested list. The third copies a list using slice notation. The fourth performs math operations like sum, max, min on tuples. The learning outcomes cover list and tuple functions used.

Uploaded by

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

Py Set-2

This document contains code for 4 Python programming practical exercises. The first creates and manipulates lists using methods like append, extend, remove, and reverse. It also sorts lists in ascending and descending order. The second extracts elements from a nested list. The third copies a list using slice notation. The fourth performs math operations like sum, max, min on tuples. The learning outcomes cover list and tuple functions used.

Uploaded by

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

CE259: Programming in Python A.

Y:2022-23 [EVEN] 21DCE043

CHAROTAR UNIVERSITY OF SCIENCE & TECHNOLOGY


DEVANG PATEL INSTITUTE OF ADVANCE TECHNOLOGY & RESEARCH
Department of Computer Engineering

SET – 2
Practical: 2.1
AIM: Create a list and apply methods (append, extend, remove, reverse), arrange created
list in ascending and descending order.

Tools and Technologies used:


 Python IDLE
 Python Script
Program Code:
l1=[1,2,3,4,5,6]
l2=[20,30,40,50,60]
print("The original list is : ",l1)
print("The original list is : ",l2)
print("The list after appending element 7 is : ")
l1.append(7)
print(l1)
print("The original list after extending is : ")
l1.extend(l2)
print(l1)
print("The list after removing the element is : ")
l1.remove(6)
print(l1)
print("The reverse list is : ")
l1.reverse()
print(l1)
print("The list after sorting in the ascending order is : ")
l1.sort()
print(l1)
print("The list after sorting in the descending order is : ")
l1.sort(reverse=True)
print(l1)
print("21DCE043")

Page 1|2
CE259: Programming in Python A.Y:2022-23 [EVEN] 21DCE043

Output:

Practical: 2.2
AIM: List1 = [1, 2, 3, 4, ["python", "java", "c++", [10,20,30]], 5, 6, 7, ["apple",
"banana", "orange"]] From above list get word “orange” and “Python” & repeat this list
five times without using loops.
Tools and Technologies used:
 Python IDLE
 Python Script
Program Code:
Practical: 2.3
AIM: Create a list and copy it using slice function.
Tools and Technologies used:
 Python IDLE
 Python Script
Program Code:
list1 = [27, 13, -11, 60, 39, 15]
list2 = list1[:3]
print("The original list is : ",list1)
print("The list after copying is : ",list2)

Page 2|2
CE259: Programming in Python A.Y:2022-23 [EVEN] 21DCE043

print("21DCE043")

Output:

Practical: 2.4
AIM: Create a tuple and apply different type of mathematical operation on it (Sum,
Maximum, minimum etc.).
Tools and Technologies used:
 Python IDLE
 Python Script
Program Code:
t1=(1,2,3,4,5)
t2=(6,7,8,9,10)
print("The original tuple t1 is : ",t1)
print("The original tuple t2 is : ",t2)
print("The maximum element of tuple is : ",max(t1))
print("The minimum element of tuple is : ",min(t1))
print("The sum of all the elements of tuple is : ",sum(t1))
t3=t1+t2
print("The addition of t1 and t2 tuples in t3 is : ",t3)
print("21DCE043")

Output:

Page 3|2
CE259: Programming in Python A.Y:2022-23 [EVEN] 21DCE043

Learning Outcomes:
In this practical, following concepts were learnt:
I. The list functions such as insert,append,remove,sort
II. We learnt how we can print the list multiple times without using loops
III. We learnt that how we can copy the list using slice function.
IV. How we can define tuples, use the different tuple functions such as max,min and
sum.

Page 4|2

You might also like