0% found this document useful (0 votes)
6 views23 pages

Python Programs for Class XI IP

The document contains a collection of Python programs and MySQL queries designed for Class XI students. It includes programs for calculating averages, grades, sale prices, interest, profit/loss, EMI, tax, and more, along with MySQL commands for creating and managing a student database. Each program is accompanied by example outputs demonstrating their functionality.
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)
6 views23 pages

Python Programs for Class XI IP

The document contains a collection of Python programs and MySQL queries designed for Class XI students. It includes programs for calculating averages, grades, sale prices, interest, profit/loss, EMI, tax, and more, along with MySQL commands for creating and managing a student database. Each program is accompanied by example outputs demonstrating their functionality.
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

IP Practical File

Class XI
Python Programs
1. To find average and grade for given marks.

sub1=int(input("Enter marks of the first subject: "))

sub2=int(input("Enter marks of the second subject: "))

sub3=int(input("Enter marks of the third subject: "))

sub4=int(input("Enter marks of the fourth subject: "))

sub5=int(input("Enter marks of the fifth subject: "))

avg=(sub1+sub2+sub3+sub4+sub5)/5

#printing average
print ("The average marks",avg)

if(avg>=90):

print("Grade: A")

elif(avg>=80 and avg<90):

print("Grade: B")

elif(avg>=70 and avg<80):

print("Grade: C")

elif(avg>=60 and avg<70):

print("Grade: D")

else:

print("Grade: F")

Output:
Enter marks of the first subject: 45
Enter marks of the second subject: 78
Enter marks of the third subject: 87
Enter marks of the fourth subject: 95
Enter marks of the fifth subject: 99
The average marks 80.8
Grade: B
2. To find the sale price of an item with a given cost and discount (%).

cost_price=float(input("Enter Price : "))

discount_In_Percentage=float(input("Enter discount % : "))

discount=cost_price*discount_In_Percentage/100

saleing_price=cost_price-discount

print("Cost Price : ",cost_price)

print("Discount: ",discount)

print("Selling Price : ",saleing_price)

Output:
Enter Price : 560
Enter discount % : 10
Cost Price : 560.0
Discount: 56.0
Selling Price : 504.0
>>>
3. To calculate perimeter/circumference and area of shapes such as triangle, rectangle, square and circle.

import math
print("Choose a shape:")
print("1. Triangle")
print("2. Rectangle")
print("3. Square")
print("4. Circle")

choice = input("Enter the number corresponding to the shape: ")

if choice == '1':
a = float(input("Enter the length of side a: "))
b = float(input("Enter the length of side b: "))
c = float(input("Enter the length of side c: "))
perimeter = a + b + c
area = 0.5 * b * c
elif choice == '2':
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
perimeter = 2 * (length + width)
area = length * width
elif choice == '3':
side = float(input("Enter the length of the square's side: "))
perimeter = 4 * side
area = side * side
elif choice == '4':
radius = float(input("Enter the radius of the circle: "))
perimeter = 2 * [Link] * radius
area = [Link] * radius * radius
else:
print("Invalid choice. Please choose a number between 1 and 4.")
exit()

print(f"\nPerimeter/Circumference: {perimeter}")
print(f"Area: {area}")
Output:
Choose a shape:
1. Triangle
2. Rectangle
3. Square
4. Circle
Enter the number corresponding to the shape: 1
Enter the length of side a: 23
Enter the length of side b: 20
Enter the length of side c: 12

Perimeter/Circumference: 55.0
Area: 120.0
4. To calculate Simple and Compound interest.

# Simple and Compound Interest

# Reading principal amount, rate and time


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

# Calcualtion
simple_interest = (principal*time*rate)/100
compound_interest = principal * ( (1+rate/100)**time - 1)

# Displaying result
print('Simple interest is: ',simple_interest)
print('Compound interest is: ' compound_interest)

Output:
Enter amount: 500
Enter time: 5
Enter rate: 12
Simple interest is: 300.000000
Compound interest is: 381.170842
>>>
5. To calculate profit-loss for a given Cost and Sell Price.

cp=float(input("Enter the Cost Price : "));

sp=float(input("Enter the Selling Price : "));

if cp==sp:

print("No Profit No Loss")

else:

if sp>cp:

print("Profit of ",sp-cp)

else:

print("Loss of ",cp-sp)

Output:
Enter the Cost Price : 575
Enter the Selling Price : 623
Profit of 48.0
>>>
Enter the Cost Price : 545
Enter the Selling Price : 545
No Profit No Loss
>>>
Enter the Cost Price : 545
Enter the Selling Price : 523
Loss of 22.0
>>>
6. To calculate EMI for Amount, Period and Interest.

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

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

p = float(input("Enter principal amount: "))


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

# Calculating interest rate per month


r = R/(12*100)

# Calculating Equated Monthly Installment (EMI)


emi = p * r * ((1+r)**n)/((1+r)**n - 1)

print("Monthly EMI = ", emi)

Output:
Enter principal amount: 12000
Enter annual interest rate: 12.5
Enter number of months: 18
Monthly EMI = 734.57478867545
>>>
7. To calculate tax – GST / Income Tax.

Original_price=float(input("Enter original Price:-"))

Net_price = float(input("Enter Net Price:-"))

GST_amount = Net_price - Original_price

GST_percent = ((GST_amount * 100) / Original_price)

print("GST = ",end='')

print(GST_percent,end='')

print("%")

Output:
Enter original Price:-345
Enter Net Price:-356
GST = 3.1884057971014492%
>>>
8. To find the third largest/smallest number in a list.

#create empty list

mylist = []

number = int(input('How many elements to put in List: '))

for n in range(number):

element = int(input('Enter element '))

[Link](element)

# Sort list elements


sorted_list = sorted(mylist)

print("Sorted elements in list : ",sorted_list)

print(("The Third smallest element in list is:",sorted_list[2]))

print(("The Third largestest element in list is:",sorted_list[-3]))

Output:
How many elements to put in List: 6
Enter element 34
Enter element 45
Enter element 23
Enter element 32
Enter element 65
Enter element 56
Sorted elements in list : [23, 32, 34, 45, 56, 65]
('The Third smallest element in list is:', 34)
('The Third largestest element in list is:', 45)
>>>
9. To find the sum of squares of the first 100 natural numbers.

sum = 0

for numbers in range(1, 101):

sum = sum + (numbers*numbers)

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

Output:
Sum of squares is : 338350
>>>
10. Python Program to find the sum of square of given number.

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

sum = 0

for numbers in range(1,number+1):

sum = sum + (numbers*numbers)

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

Output:
Enter any number : 4
Sum of squares is : 30
>>>

Enter any number : 3

Sum of squares is : 14

>>>
11. To print the first ‘n’ multiples of a given number.

# Python Program to print the first ‘n’ multiples of a given number

num=int(input("Enter a number whose multiples to find-"))

length=int(input("Enter length upto which you want to find multiples-"))

for i in range (1,length+1):

print(i*num)

Output:
Enter a number whose multiples to find-5
Enter length upto which you want to find multiples-4
5
10
15
20
>>>

Enter a number whose multiples to find-2


Enter length upto which you want to find multiples-13
2
4
6
8
10
12
14
16
18
20
22
24
26
>>>
12. To count the number of vowels in a user entered string.

# Vowels & Consonants count

str = input("Type the string: ")


vowel_count=0
consonants_count=0
vowel = set("aeiouAEIOU")
for alphabet in str:
if alphabet in vowel:
vowel_count=vowel_count +1
elif alphabet == chr(32):
consonants_count=consonants_count
else:
consonants_count=consonants_count+1

print("Number of Vowels in ",str," is :",vowel_count)


print("Number of Consonants in ",str," is :",consonants_count)

# Upper and lower case count

uppercase_count=0
lowercase_count=0
for elem in str:
if [Link]():
uppercase_count += 1
elif [Link]():
lowercase_count += 1

print("Number of UPPER Case in ",str,"' is :",uppercase_count)


print("Number of lower case in ",str,"' is :",lowercase_count)
13. To print the number of occurrences of a given alphabet in a given string.

# Python Program to Count Occurrence of an alphabate in a String

string = input("Enter any String: ")


char = input("Enetr any alphabate to count its occurrence: ")

count = 0
for i in range(len(string)):
if(string[i] == char):
count = count + 1

print("Total Occurrence count of", char, " in string is = ",count)

Output:
Enter any String: "practical file for class 11 informatics practices "
Eneter any alphabate to count its occurrence: "i"
('Total Occurrence count of', 'i', ' in string is = ', 5)
>>>
Enter any String: "practical file for class 11 informatics practices "
Enetr any alphabate to count its occurrence: "z"
('Total Occurrence count of', 'z', ' in string is = ', 0)
>>>
14. To print the words starting with a particular alphabet in a user entered string.

string1 = input("Enter a sentence: ")


start = input("Enter the alphabet to filter words: ")

words = [Link]()
selected_words = [word for word in words if
[Link]().startswith([Link]())]

if selected_words:
print(f"Words starting with '{start}':")
for selected_word in selected_words:
print(selected_word)
else:
print(f"No words found starting with '{start}'.")

Output:

Enter a sentence: Welcome to P P SAVANI SCHOOL

Enter the alphabet to filter words: S

Words starting with 'S':

SAVANI

SCHOOL
15. Create a dictionary to store names of states and their capitals.

states = dict()

no_of_states = int(input("Enter the number of states :"))

for i in range(no_of_states):

state_name = input("Enter name of state :")

state_capital = input("Enter capital of state :")

states[state_name] = state_capital

print("Dictionary is created :",states)

name = input("Enter the name of state to display capital:")

print(states[name])

Output:
Enter the number of states :3
Enter name of state :"UTTAR PRADESH"
Enter capital of state :"LUCKNOW"
Enter name of state :"UTTRAKHAND"
Enter capital of state :"DEHRADUN"
Enter name of state :"PUNJAB"
Enter capital of state :"CHANDIGARH"
('Dictionary is created :', {'PUNJAB': 'CHANDIGARH', 'UTTRAKHAND':
'DEHRADUN', 'UTTAR PRADESH': 'LUCKNOW'})
Enter the name of state to display capital:"PUNJAB"
CHANDIGARH
>>>
16. Create a dictionary of students to store names and marks obtained in 5 subjects.

students = dict()

no_of_student = int(input("Enter number of students :"))

for i in range(no_of_student):

std_name = input("Enter names of student :")

marks= []

for j in range(5):#Range for 5 subjects

mark = int(input("Enter marks :"))

[Link](mark)

students[std_name] = marks

print("Dictionary of student created :")

print(students)

Output:
Enter number of students :3
Enter names of student :"Amit"
Enter marks :67
Enter marks :78
Enter marks :78
Enter marks :98
Enter marks :87
Enter names of student :"Sumit"
Enter marks :56
Enter marks :67
Enter marks :89
Enter marks :98
Enter marks :87
Enter names of student :"Neetu"
Enter marks :88
Enter marks :78
Enter marks :79
Enter marks :67
Enter marks :87
Dictionary of student created :
{'Amit': [67, 78, 78, 98, 87], 'Neetu': [88, 78, 79, 67, 87], 'Sumit':
[56, 67, 89, 98, 87]}
MySQL Queries
[1] Create Database name class11
CREATE DATABASE CLASS11;

[2] Open database


USE CLASS11;

[3] To create a student table with the student id, class, section, gender, name, dob, and marks as
attributes where the student id is the primary key.
CREATE TABLE STUDENT
(
STUDENTID INT(4) PRIMARY KEY,
CLASS CHAR(2),
SECTION CHAR(1),
GENDER CHAR(1),
NAME VARCHAR(20),
DOB DATE,
MARKS DECIMAL(5,2)
);

[4] View the structure of the table


DESC STUDENT;
[5] To insert the details of at least 10 students in the above table.
INSERT INTO STUDENT VALUES
(1101,'XI','A','M','AKSH','2005/12/23',88.21),
(1102,'XI','B','F','MOKSHA','2005/03/24',77.90),
(1103,'XI','A','F','ARCHI','2006/04/21',76.20),
(1104,'XI','B','M','BHAVIN','2005/09/15',68.23),
(1105,'XI','C','M','KEVIN','2005/08/23',66.33),
(1106,'XI','C','F','NAADIYA','2005/10/27',62.33),
(1107,'XI','D','M','KRISH','2005/01/23',84.33),
(1108,'XI','D','M','AYUSH','2005/04/23',55.33),
(1109,'XI','C','F','SHRUTI','2005/06/01',74.33),
(1110,'XI','D','F','SHIVI','2005/10/19',72.30);

[6] Display the details of the student table.


SELECT * FROM STUDENT;

[7] To delete the details of a particular student in the above table.


Delete record of students who secured less than 65 marks.
DELETE FROM STUDENT WHERE MARKS <65;

[8] To increase marks by 5% for those students who have studentid more than 1105.
UPDATE STUDENT SET MARKS=MAKRS+(MARKS*0.05) WHERE STUDENTID>1105;
[9] To display the content of the table of female students.
SELECT * FROM STUDENT WHERE GENDER = 'F';

[10] To display studentid, Name and Marks of those students who are scoring marks more than 50.
SELECT STUDENTID, NAME, MARKS FROM STUDENT WHERE MARKS>50;

[11] To find the average of marks from the student table.


SELECT AVG(MARKS) FROM STUDENT;

[12] To find the number of students, who are from section ‘A’.
SELECT COUNT(*) FROM STUDENT WHERE SECTION = 'A';
[13] To add a new column email in the above table with the appropriate data type.
ALTER TABLE STUDENT
ADD COLUMN EMAIL VARCHAR(20);

[14] To add the email ids of each student in the previously created email column.
UPDATE STUDENT
SET EMAIL='A@[Link]';

[15] To display the information of all the students, whose name contains ‘sh’
SELECT * FROM STUDENT WHERE NAME LIKE 'SH%';

[16] To display the information of all the students, whose name starts with ‘sh’
SELECT * FROM STDUENT WHERE NAME LIKE 'SH%';
[17] To display studentid, Name, DOB of those students who are born between ‘2005- 01-01’ and
‘2005-12-31’.
SELECT STUDENTID, NAME, DOB FROM STUDENT WHERE DOB BEETWEEN '2005-01-01' AND
'2005-12-31';

[18] To display studentid, Name, DOB, Marks, Email of those male students in ascending order of their
names.
SELECT STUDENTID, NAME, DOB FROM STUDENT ORDER BY NAME;

[19] To display stduentid, Gender, Name, DOB, Marks, Email in descending order of their marks.
SELECT STUDENTID, GENDER, NAME, DOB, MARKS, EMAIL FROM STUDENT ORDER BY MARKS
DESC;
[20] To display the unique section available in the table.
SELECT DISTNICT SECTION FROM STUDENT;

You might also like