0% found this document useful (0 votes)
15 views2 pages

Lab 2 - Introduction To Programming BBA

python task

Uploaded by

sinehachawla123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
15 views2 pages

Lab 2 - Introduction To Programming BBA

python task

Uploaded by

sinehachawla123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Introduction to Programming BBA-IV

Lab-2 Python Lists


Lab Instructor: Noor Nabi

Learning Outcomes:
Declare, Initialize, insert elements, remove elements, and deleting different type lists,
Print the lists using for loop and without loops,
Sort the lists, max and min elements of the lists,
Multiple Lists: sum, difference, product, squares, average, and quotient.
range( ), copy( ), insert( ), list( ), len( ), type( ), max( ), min( ), sum( ), print( “hi”, end= “”).

1) Character Lists:
• Declare an empty list chars.
• Initialize the chars: [‘h’,’e’,’l’,’l’,’o’]
• Print the chars using for loop and direct print(chars). Observe the output.
• Print the list chars both forward and reversed.
• Print all the characters of chars on the same line: h e l l o
• Find the length and type of chars.
• Find the max and min character from the chars.
• Create another list named chars2 having 4 characters: [‘m’, ‘e’, ‘l’, ‘o’].
Add the chars, and chars2 store the result in a new list named result then
print list result both using loop and manual by indexing.
Print the indices of result with characters:
0: h
1: e
• Clear list: Remove all the elements of the chars and chars2.
• Delete the lists. [ You can use the del keyword]

2) Numerical Lists:
• Create a list named numbers having five integers: [3, 5, 25, 1, 3]
• Print the list numbers both forward and reversed.
• Find the length and type of numbers.
• Find the maximum and minimum element from numbers.
• Find the average and sum of list numbers.
• Insert the 27 at the end of list.
• Print the last element of list.
• Sort the list numbers in ascending and descending order.
3) Multiple Lists:
• Declare two lists num and digits having size 10 respectively.
• Take 10 elements as input from user for both lists.
• For each lists print the sum, difference, product, squares, average, and
quotient of lists using for loop and store the results of each operation in
new list named sum, diff, prod, squares, and quotients respectively.

4) Write a Python program to find the even and odd numbers from 0 to 10.
Store the even numbers in even list, odd numbers in odd list. Print the lists.
Print the total number of even and odd numbers.
5) Write a Python program to find those numbers which are divisible by 3 and
multiple of 2, between 100 and 600 (both included).
6) Write down the code of copying a List:
You cannot copy a list simply by typing list2 = list1, because: list2 will only be
a reference to list1, and changes made in list1 will automatically also be made
in list2.

There are ways to make a copy, one way is to use the built-in List method copy().

Example: Make a copy of a list with the copy() method:


thislist = ["apple", "banana", "cherry"]
mylist = thislist.copy()
print(mylist)
Another way to make a copy is to use the built-in method list().
Example: Make a copy of a list with the list() method:
thislist = ["apple", "banana", "cherry"]
mylist = list(thislist)
print(mylist)

You might also like