0% found this document useful (0 votes)
30 views20 pages

Practical

class 12 ip

Uploaded by

mrjaganiscool
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)
30 views20 pages

Practical

class 12 ip

Uploaded by

mrjaganiscool
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/ 20

Program: 1

Aim: Python Program to input a message and display it.


Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File
Source Code :
message = input ("Enter your message: ")
name = input ("Enter your name: ")
print (message, "dear", name)

Result : Code executed successfully.

Output (On Blank Sheet):


Program: 2
Aim: Python Program to Input two numbers and display the larger / smaller number.
Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File
Source Code :
num1 = int (input ("Enter the first number: "))
num2 = int (input ("Enter the second number: "))
if num1 > num2:
print (num1,"is larger than", num2)
else:
print (num1,"is smaller than", num2)

Result : Code executed successfully.


Program: 3
Aim: Find the average and grade for given marks

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
English =float(input("Enter English Marks:"))
CS =float(input("Enter Computer Science Marks:"))
Physics =float(input("Enter Physics Marks:"))
Chemistry =float(input("Enter Chemistry Marks:"))
Mathematics =float(input("Enter Mathematics Marks:"))
average =float((English+CS+Physics+Chemistry+Mathematics)/5)
print("Average of Marks is",average)
if average>90:
print("You scored GRADE A")
elif average<=90 and average >80:
print("You scored GRADE B")
elif average<=70 and average <80:
print("You scored GRADE C")
elif average<=60 and average <70:
print("You scored GRADE D")
elif average<=50 and average <60:
print("You scored GRADE E")

Result : Code executed successfully.


Program: 4
Aim: To find sale price of an item with given cost and discount(%).

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
cost_price=float(input("Enter the price of item:"))
discount=float(input("Enter the discount %:"))
selling_price=float(((100-discount)/cost_price)*100)
print("The selling price of item is:",selling_price)

Result : Code executed successfully.


Program: 5
Aim: To calculate perimeter/circumference and area of shapes such a triangle,
rectangle, square and circle.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
import math
radius = float(input("Enter the radius of the Circle :- "))
area = math.pi * radius * radius
circumference = 2 * math.pi * radius
print("Area of a Circle is :- ",area)
print("Circumference of a Circle is : – ",circumference)

# Square
side = float(input("Enter side of the Square :-"))
area = side * side
perimeter = 4 * side
print("Area of Square is ",area)
print("Perimeter of Square is ",perimeter)

# rectangle
length = float(input("Enter the length of a rectangle :-"))
breadth = float(input("Enter the Breadth of a rectangle :-"))
area = length * breadth
perimeter = 2 *(length + breadth)
print("Area of Rectangle is ",area)
print("Perimeter of Rectangle is ",perimeter)
# Triangle
side1 = float(input("Enter Side 1 of the traingle :-"))
side2 = float(input("Enter Side 2 of the traingle :-"))
side3 = float(input("Enter Side 3 of the traingle :-"))
s =(side1 +side2 + side3)/2
area = math.sqrt(s*(s-side1)*(s-side2)*(s-side3))
per = side1 + side2 + side3
print("Area of Triangle is ",area)
print("Perimeter of Triangle is ",per)
Result : Code executed successfully.
Program: 6
Aim: To calculate Simple and Compound interest.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
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:", simple_interest)
print("Compound interest is:", compound_interest)

Result : Code executed successfully.


Program: 7
Aim: To calculate profit-loss for given Cost and Sell Price.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
sp = float(input("Enter the Selling Price :- "))
cp = float(input("Enter the Cost Price :- "))
if sp > cp :
profit = sp - cp
profit_per = (profit * 100)//cp
print("The Profit is :- ",profit)
print("The Profit percentage is :- ", profit_per)
elif sp <cp:
loss = cp - sp
loss_per = (loss * 100)//cp
print("The Loss is :- ",loss)
print("The Loss percentage is :-",loss_per)
else:
print("No Profit No Loss")

Result : Code executed successfully.


Program: 8
Aim: To calculate EMI for Amount, Period and Interest.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
amount = float(input("Enter the base amount :- "))
period = float(input("Enter the time period :- "))
rate = float(input("Enter rate of Interest :- "))
interest = amount * period * rate /100
total = amount + interest
emi = total /(period * 12)
print("EMI amount is ",emi)

Result : Code executed successfully.


Program: 9
Aim: To calculate tax – GST.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
op=float(input("Enter original Price:-"))
np = float(input("Enter Net Price:-"))
GST_amt = np - op
GST_per = ((GST_amt * 100) / op)
print("GST Rate = %.2f"%GST_per,"%")
print("GST Amount = ",GST_amt)

Result : Code executed successfully.


Program: 10
Aim: To find the largest and smallest numbers in a list.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
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))

Result : Code executed successfully.


Program: 11
Aim: To find the third largest/smallest number in a list.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
NumList = []
Number = int(input("Please enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Please enter the Value of %d Element : " %i))
NumList.append(value)
print("The Smallest Element in this List is : ", min(NumList))
print("The Largest Element in this List is : ", max(NumList))

Result : Code executed successfully.


Program: 12
Aim: To find the sum of squares of the first 100 natural numbers.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
sum1 = 0
for i in range(1, 101):
sum1 = sum1 + (i*i)
print("Sum of squares is : ", sum1)

Result : Code executed successfully.


Program: 13
Aim: To print the first ‘n’ multiples of given number.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
#input
n = int(input("Enter the number to display multiples:"))
m = int(input("Enter the number to display n multiples:"))
#computing multiples
multiple = range(n, (n * m) + 1, n)
print(list(multiple))

Result : Code executed successfully.


Program: 14
Aim: To count the number of vowels in user entered string.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
txt = input("Enter string:")
vowels = 0
for i in txt:
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:", vowels)

Result : Code executed successfully.


Program: 15
Aim: To print the words starting with an alphabet in a user entered string.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
txt=input("Enter the text:")
al=input("Enter alphabet to print the words:")
for i in txt.split():
if i.startswith(al):
print(i)

Result : Code executed successfully.


Program: 16
Aim: To print number of occurrences of a given alphabet in each string.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
string = input("Please enter your own String : ")
char = input("Please enter your own Character : ")
count = 0
for i in range(len(string)):
if(string[i] == char):
count = count + 1
print("The total Number of Times ",char, "has Occurred = " , count)

Result : Code executed successfully.


Program: 17
Aim: Create a dictionary to store names of states and their capitals.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
dict1 = { }
ans = 'y'
while(ans=='y'):
st_name = input("Enter name of the State:")
capital = input("Enter its capital:")
dict1[st_name]=capital
ans = input("Do you want to insert more records y/n")
print(dict1)

Result : Code executed successfully.


Program: 18
Aim: Create a dictionary of students to store names and marks obtained in 5 subjects.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
students = dict()
n = int(input("How many students are there :"))
for i in range(n):
sname = input("enter name of the student :")
marks = []
for j in range(5):
mark = float(input("Enter marks: "))
marks.append(mark)
students[sname]= marks
print("Created dictionary of students is ",students)

Result : Code executed successfully.


Program: 19
Aim: To print the highest and lowest values in the dictionary.

Procedure:
i. Go to start Menu
ii. Go to programs  Python 3.11.0  IDLE
iii. File  New File

Source Code:
my_dict = {'x': 500, 'y': 5874, 'z': 560}
val = my_dict.values( )
print('max value' , max(val))
print('min value' , min(val))

Result : Code executed successfully.


20. To create a database
21. To create student table with the student id, class, section, gender, name, dob, and
marks as attributes where the student id is the primary key.
22. To insert the details of at least 10 students in the above table.
23. To display the entire content of table.
24. To display Rno, Name and Marks of those students who are scoring marks more
than 50.
25. To display Rno, Name, DOB of those students who are born between ‘2005- 01-01’
and ‘2005-12-31’.

You might also like