/**/ Sanjeev Study Hub – Class 11 & 12 Notes, Question Papers, IP & CS Study Material

Tuesday, November 23, 2021

LIST MANIPULATION IN PYTHON (CLASS - XI)

LIST MANIPULATION 
CLASS - XI

It is a collections of items and each item has its own index value.

Index of first item is 0 and the last item is n-1.Here n is  number of items in a list. 


Creating a list

Lists are enclosed in square brackets [ ] and each item  is separated by a comma.

e.g.

list1 = [‘English', ‘Hindi', 1997, 2000]

list2 = [11, 22, 33, 44, 55 ]

list3 = ["a", "b", "c", "d"]

Access Items From A List

List items can be accessed using its index position. 

e.g.

list =[3,5,9]  

print(list[0]) 

print(list[1]) 

print(list[2])

print('Negative indexing')

print(list[-1])

print(list[-2])

print(list[-3])

Do your self: Find the output of the above example

Iterating Through A List

List elements can be accessed using looping  statement.

e.g.

list =[3,5,9]

for i in range(0, len(list)):  print(list[i])

Output 

3

5

9

Slicing of A List

List elements can be accessed in subparts.

e.g.

list =['I','N','D','I','A']

print(list[0:3])

print(list[3:])

print(list[:])

Output

 ['I', 'N', 'D']  ['I', 'A']

['I', 'N', 'D', 'I', 'A']


Updating Lists

We can update single or multiple elements of lists by  giving the slice on the left-hand side of the assignment  operator.

e.g.

list = ['English', 'Hindi', 1997, 2000]

print ("Value available at index 2 : ", list[2])

list[2:3] = 2001,2002 #list[2]=2001 for single item update  print ("New value available at index 2 : ", list[2])

print ("New value available at index 3 : ", list[3])

Output

('Value available at index 2 : ', 1997)  ('New value available at index 2 : ', 2001)  ('New value available at index 3 : ', 2002)


Add Item to A List

append() method is used to add an Item to a List.

e.g.  list=[1,2]

print('list before append', list)  list.append(3)

print('list after append', list)

Output

('list before append', [1, 2])

('list after append', [1, 2, 3])

NOTE :- extend() method can be used to add  multiple item at a time in list.eg - list.extend([3,4])


Add Two Lists

e.g.

list = [1,2]

list2 = [3,4]

list3 = list + list2  print(list3)

OUTPUT  [1,2,3,4]


Delete Item From A List  

e.g.

list=[1,2,3]

print('list before delete', list)  del list [1]

print('list after delete', list)

Output

('list before delete', [1, 2, 3])

('list after delete', [1, 3])

e.g.

del list[0:2] # delete first two items  del list # delete entire list


Basic List Operations


Python  Expression

Results

Description

len([4, 2, 3])

3

Length

[4, 2, 3] + [1, 5, 6]

[4, 2, 3, 1, 5, 6]

Concatenation

[‘cs!'] * 4

['cs!', 'cs!', 'cs!',  'cs!']

Repetition

3 in [4, 2, 3]

True

Membership

for x in [4,2,3] :

print (x,end = ' ')

4 2 3

Iteration

 

Important methods and functions of List

Function

Description

list.append()

Add an Item at end of a list

list.extend()

Add multiple Items at end of a list

list.insert()

insert an Item at a defined index

list.remove()

remove an Item from a list

del list[index]

Delete an Item from a list

list.clear()

empty all the list

list.pop()

Remove an Item at a defined index

list.index()

Return index of first matched item

list.sort()

Sort the items of a list in ascending or descending order

list.reverse()

Reverse the items of a list

len(list)

Return total length of the list.

max(list)

Return item with maximum value in the list.

min(list)

Return item with min value in the list.

list(seq)

Converts a tuple, string, set, dictionary into list.

 

Programs on List

* find the largest number in a list

#Using sort  a=[]

n=int(input("Enter number of elements:"))  for i in range(1,n+1):

b=int(input("Enter element:"))  a.append(b)

a.sort()

print("Largest element is:",a[n-1])


#using function definition

def max_num_in_list( list ):  max = list[ 0 ]

for a in list:  if a > max:

max = a  return max

print(max_num_in_list([1, 2, -8, 0]))

Find the Maximum Value

list1, list2 = [123, 'xyz', 'zara', 'abc'], [456, 700, 200]  

print "Max value element : ", max(list1)

print "Max value element : ", max(list2)  

Output

Max value element : zara  Max value element : 700


Programs on List

* find the mean of a list

def Average(lst):

return sum(lst) / len(lst)

# Driver Code

lst = [15, 9, 55, 41, 35, 20, 62, 49]

average = Average(lst)

# Printing average of the list

print("Average of the list =", round(average, 2))

Output

Average of the list = 35.75

Note : The inbuilt function mean() can be used to calculate the mean(

average ) of the list.e.g. mean(list)

Programs on List

* Linear Search

list_of_elements = [4, 2, 8, 9, 3, 7]

x = int(input("Enter number to search: "))

found = False

for i in range(len(list_of_elements)):

if(list_of_elements[i] == x):

found = True

print("%d found at %dth position"%(x,i))  

break

if(found == False):

print("%d is not in list"%x)


Programs on List

* Frequency of an element in list  import collections

my_list = [101,101,101,101,201,201,201,201]

print("Original List : ",my_list)

ctr = collections.Counter(my_list)  print("Frequency of the elements in the List : ",ctr)

OUTPUT

Original List :            [101, 101,101, 101, 201, 201, 201, 201]

Frequency of the elements in the List : Counter({101: 4, 201:4})


Note: Same can be done using count and other functions.


===============================

  


Sunday, October 17, 2021

CBSE IP CLASS 11 PRACTICAL FILE (TERM-1)

INFORMATICS PRACTICES (065)

CLASS - XI

PRACTICAL LIST

========================================

EXPERIMENT – 1

Objective: The marks obtained by a student in 3 different subjects are input by the user. Your program should calculate the average of subjects and display the grade. The student gets a grade as per the following rules:

Average           Grade

90-100             A

80-89              B

70-79              C

60-69              D

0-59               F

Solution:

sub1 = int(input("Enter marks obtained in subject 1: "))

sub2 = int(input("Enter marks obtained in subject 2: "))

sub3 = int(input("Enter marks obtained in subject 3: "))

avg_marks =(sub1+sub2+sub3)/3

print("Average mark:",avg_marks)

if avg_marks>=90:

    print("Grade is A")

elif avg_marks>=80:

    print("Grade is B")

elif avg_marks>=70:

    print("Grade is C")

elif avg_marks>=60:

    print("Grade is D")

else:

    print("Grade is F")


EXPERIMENT – 2

Objective: WAP in Python to find the sale price of an item with a given cost and discount (%).

Solution:
price=float(input("Enter Price : "))
dp=float(input("Enter discount % : "))
discount=price*dp/100
sp=price-discount
print("Cost Price : ",price)
print("Discount: ",discount)
print("Selling Price : ",sp)

EXPERIMENT – 3
Objective: To calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and circle.

Solution:

import math
def area_square(a):
    area1=float(a*a);
    print("Area of square is:",area1)
def area_circle(r):
    area2=float(3.14*r*r);
    print("Area of circle is:",area2)
def area_rectangle(a,b):
    area3=float(a*b);
    print("Area of rectangle is:",area3)
def area_triangle(x,y):
    area4=float((x*y)/2);
    print("Area of triangle is:",area4)
def peri_square(a):
    peri1=float(4*a);
    print("Perimeter of square is:",peri1)
def peri_circle(r):
    peri2=float(2*3.14*r);
    print("Perimter of circle is:",peri2)
def peri_triangle(a,b):
    hypotenuse=float(math.sqrt(a*a+b*b))
    peri3=float(a+b+hypotenuse)
    print("Perimter of right angled triangle is:",peri3)
def peri_rectangle(a,b):
    peri4=float(2*(a+b))
    print("Perimter of rectangle is:",peri4)

side=float(input("enter the side of square:"))
area_square(side)
print()
peri_square(side)
radius=float(input("enter the radius of circle:"))
area_circle(radius)
peri_circle(radius)
length=float(input("enter the length of rectangle:"))
breadth=float(input("enter the breadth of rectangle:"))
area_rectangle(length,breadth)
peri_rectangle(length,breadth)
base=float(input("enter the base of right angled triangle:"))
height=float(input("enter the height of right angled triangle:"))
area_triangle(base,height)
peri_triangle(base,height)

EXPERIMENT - 4

Objective: To calculate Simple and Compound interest.

Solution:

principal = float(input('Enter amount: '))
time = float(input('Enter time: '))
rate = float(input('Enter rate: '))

simple_interest = (principal*time*rate)/100
compound_interest = principal * ( (1+rate/100)**time - 1)
print('Simple interest is: %f' % (simple_interest))
print('Compound interest is: %f' %(compound_interest))

EXPERIMENT - 5
Objective: Write a python program to input cost price, selling price of product from user and check whether is profit or loss and also print the Profit/loss amount

Solution:

cp=float(input("Enter the Cost Price : "));
sp=float(input("Enter the Selling Price : "));
if cp==sp:
    print("No Profit No Loss")
elif sp>cp:
    print("Profit of ",sp-cp)
else:
    print("Loss of ",cp-sp)

                                EXPERIMENT - 6
Objective: Python program to calculate monthly EMI (Equated Monthly Instalments)

Solution:

# EMI Formula = p * r * (1+r)^n/((1+r)^n-1)

# Monthly Interest Rate (r) = R/(12*100)

# p = Principal or Loan Amount
# r = Interest Rate Per Month
# n = Number of monthly instalments

p = float(input("Enter principal amount: "))
R = float(input("Enter annual interest rate: "))
n = int(input("Enter number of months: " ))

r = R/(12*100)
emi = p * r * ((1+r)**n)/((1+r)**n - 1)
print("Monthly EMI = ", emi)

EXPERIMENT – 7

Objective: To calculate tax - GST / Income Tax.

Solution:

item=input("Enter item name :")

sp_cost=float(input("How much is selling price of item:"))

gst_rate=float(input("What is GST rate % :"))

cgst=sp_cost*((gst_rate/2)/100)

sgst=cgst

amt=sp_cost+cgst+sgst

print("CGST (@",(gst_rate/2),"%) :",(cgst))

print("SGST(@",(gst_rate/2),"%) :",(sgst))

print("Amount payable: ",(amt))

EXPERIMENT – 8

Objective: To find the largest and smallest numbers in a list.

Solution:

lst = [ ]

num = int(input('How many numbers: '))

for n in range(num):

    numbers = int(input('Enter number '))

    lst.append(numbers)

print("Maximum element in the list is :", max(lst), "\nMinimum

 element in the list is :", min(lst))

EXPERIMENT – 9

Objective: To find the third largest/smallest number in a list.

Solution:

num = [2,3,7,4,5,6,10,11,120]

largest_num = num[0]

second_largest_num = num[0]

third_largest_num = num[0]

for i in num :

    if i > largest_num :

        third_largest_num = second_largest_num

        second_largest_num = largest_num

        largest_num = i

    elif i > second_largest_num :

        third_largest_num = second_largest_num

        second_largest_num = i

    elif i > third_largest_num :

        third_largest_num = i

print("Third largest number of the list is {}".format(third_largest_num))

EXPERIMENT – 10

Objective:To find the sum of squares of the first 100 natural

 numbers.

Solution:

n = int(input("Enter nth number : "))

sum = 0

for s in range(1, n+1):

   sum = sum + (s*s)

print("Sum of squares is : ", sum)


EXPERIMENT – 11

Objective:To print the first ‘n’ multiples of a given number.

Solution:

number = int(input("Enter number: "))

print("The multiples are: ")

for i in range(1,11):

    print(number*i, end =" ")


EXPERIMENT – 12

Objective: To count the number of vowels in a user entered

 string.

Solution:

string=input("Enter string:")

vowels=0

for i in string:

      if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):

            vowels=vowels+1

print("Number of vowels are:")

print(vowels)

==================================


Class 12 Informatics Practices 2026 Question Paper with Answers (Full Solution)

  CBSE Class 12 IP 2026 बोर्ड पेपर + Solutions 1. State whether the following statement is True or False: In Pandas Series, the Positional...