Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Practical File

List Lab Programs

1.create a list and print the elements of the list using For
loop.

list = [10, 20, 30, 40, 50] # Declaring a list


print("List elements are: ")# printing using FOR and IN
for L in list:
print(L)
print() # prints new line
output:

2.Claculate the sum of the elements in the list.

list = [10, 20, 30, 40, 50] # calculating Sum of all elements
sum = 0
for L in list:
sum += L
print("Sum is: ", sum)
output:

3.Sort the elements in the list in descending order.

num = [10, 30, 40, 20, 50] # List of integers


num.sort(reverse=True) # sorting and printing
print(num)
fnum = [10.23, 10.12, 20.45, 11.00, 0.1] # List of float numbers
fnum.sort(reverse=True) # sorting and printing
print(fnum)
str = ["Banana", "Cat", "Apple", "Dog", "Fish"]# List of strings
str.sort(reverse=True) # sorting and printing
print (str)
output:

4.Python program to create three lists of numbers, their squares


and cubes
# declare lists
numbers = []
squares = []
cubes = []
#start and end numbers
start = 1
end = 10
# run a loop from start to end+1
for count in range(start, end + 1):
numbers.append(count)
squares.append(count**2)
cubes.append(count**3)
# print the lists
print("numbers: ", numbers)
print("squares: ", squares)
print("cubes : ", cubes)

output:

You might also like