[go: up one dir, main page]

0% found this document useful (0 votes)
17 views3 pages

PWP Pract-6

The document discusses Python programs to perform operations on lists including summing and multiplying list items, reversing a list, finding the largest and smallest items in a list, finding common items between two lists, and selecting even items from a list.

Uploaded by

tangiro2305
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)
17 views3 pages

PWP Pract-6

The document discusses Python programs to perform operations on lists including summing and multiplying list items, reversing a list, finding the largest and smallest items in a list, finding common items between two lists, and selecting even items from a list.

Uploaded by

tangiro2305
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/ 3

Practical No.

6: Write Python program to perform following operations on Lists:


Create list, Access list, Update list (Add item, Remove item), and Delete list

1. Write a Python program to sum all the items in a list.


def sumlist(list):
sum=0
for i in range(len(list)):
sum = sum+list[i]
return sum
list = [101,306,898,456]
print(list)
print("sum of list: ",sumlist(list))
#output
=== RESTART: C:/Users/OneDrive/Desktop/Python program/sumoflist.py ===
[101, 306, 898, 456]
sum of list: 1761

2. Write a Python program to multiplies all the items in a list.


def mul_list(list) :
product = 1
for i in list:
product = product * i
return product
list1 = [110,987,678,444]
print(list1)
print("product: ")
print(mul_list(list1))
#Output
== RESTART: C:/Users/OneDrive/Desktop/Python program/multiplylist.py ==
[110, 987, 678, 444]
product:
32683044240

3. Write a Python program to reverse a list.


def Reverse(lst):
new_lst = lst[::-1]
return new_lst
lst = [10, 11, 12, 13, 14, 15]
print(Reverse(lst))
#output
== RESTART: C:/Users/OneDrive/Desktop/Python program/reverselist.py ==
[15, 14, 13, 12, 11, 10]
4. Write a python program to get the largest number from a list.
list=[3,5,8]
print("list=",list)
print("Largest no is",max(list))

5.Write a python program to get the smallest number from a list.

list=[5,7,8,9]
print("list=",list)
print("The Smallest number from list",min(list))

6.Write a python program to find common items from two lists.

list1=[10,20,30,40,50]
list2=[30,40,50,60,70]
print("list1=",list1)
print("list2=",list2)
print("common items from list1 and list2=",set(list1)&set(list2))
7.Write a python program to select the even items of a list.

list=[1,2,3,4,5,6,7,8,9,10]

print("List=",list)

print("Even numbers from list=")

for i in list:

if i%2==0:

print(i)

You might also like