100% found this document useful (1 vote)
587 views12 pages

Python Practical Program List-2024-25

Uploaded by

poornimagidagar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
100% found this document useful (1 vote)
587 views12 pages

Python Practical Program List-2024-25

Uploaded by

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

Python Practical Program List (2024-2025)

Program No:1 To print personal information like Name, Father’s Name, Class, Age, School
Name.

#To print personal information like Name, Father’s Name, Class, Age, School Name

Name=input("Enter Name:")

FName=input("Enter Father's Name:")

Class=input("Enter Class:") #class is a keyword whereas Class isn't.

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

school=input("Enter School Name:")

print(Name,FName,Class,Age,school)

print("\n")

print(Name)

print(FName)

print(Class)

print(Age)

print(school)
Output of the program
Enter Name: Syam

Enter Fathers Name: Mohan

Enter Class:9

Enter Age:15

Enter School Name: PM Shri Kendriya Vidyalaya ASC Centre(S)

Syam

Mohan

15

PM Shri Kendriya Vidyalaya ASC Centre(S)


Program No:2 To print the following patterns using multiple print commands-

* *****
** ****
*** ***
**** **
***** *

# Pattern Printing using ‘for loop’


rows = 5
# outer loop
for i in range(1, rows + 1):
# inner loop
for j in range(1, i + 1):
print("*", end=" ")
print('')
Output of the program
*
**
***
****
*****

# Pattern Reverse using ‘While loop’


i=6
# outer while loop # 5 rows in pattern
while i > 0:
j=0
# nested while loop
while j < i:
print('*', end=' ')
j=j+1
# end of nested while loop
# new line after each row
print('')
i = i-1
Output of the program

******
*****
****
***
**
*

Program No:3 To find the sum of two numbers 15 and 20.


#To find the sum of two numbers 15 and 20
a = 15
b = 20
sum=a+b
print("a = ",a)
print("b = ",b)
print("Sum = ", sum)

Output of the program


a = 15
b = 20
Sum = 35

Program No: 4 To convert length given in kilometres into meters.


# Python program to convert km to m
# Reading input
km = input("Enter distance in Kilometer: ")
# Converting to float data type
km = float(km)
# Converting to meter
m = km * 1000;
# Displaying output
print("%0.3f Kilometer = %0.3f Meter" %(km,m))
Output of the program
Enter distance in Kilometer: 6.173
6.173 Kilometer = 6173.000 Meter

Program No:5 To calculate Simple Interest if the principle amount = 2000 rate_of_interest = 4.5 time =
10
# Code to calculate the Simple Interest
principle_amount = 2000
roi = 4.5
time = 10
simple_interest = (principle_amount * roi * time)/100
print("Principle Amount : ", principle_amount)
print("Rate of Interest : ", roi)
print("Time Period : ", time)
print("Value of Simple Interest : ", simple_interest)
Output of the program
Principle Amount : 2000
Rate of Interest : 4.5
Time Period : 10
Value of Simple Interest : 900.0

Program No:6 To calculate Area and Perimeter of a rectangle


# To calculate Area and Perimeter of a rectangle
L=int(input("Length :"))
B=int(input("Breadth :"))
Area=L*B
Perimeter=2*(L+B)
print("Area:",Area)
print("Perimeter:",Perimeter)
Output of the program
Length:50
Breadth:20
Area:1000
Perimeter:140

Program No:7 To calculate Area of a triangle with Base and Height


# To calculate Area of a triangle with Base and Height
#Input Base
B=int(input("Base "))
#Input Height
H=int(input("Height "))
#Calculate Area
Area=1/2*B*H
#Display Area
print("Area:",Area)

Output of the program


Base:20
Height:10
Area:100.0

Program No:8 To calculating average marks of 3 subjects


#Input English Marks
Eng=int(input("English: "))
#Input Maths Marks
Mat=int(input("Maths : "))
#Input Science Marks
Sci=int(input("Science: "))
#Calculate Total Marks
Tot=Eng+Mat+Sci
#Calculate Average Marks
Avg=Tot/3
#Display Total Marks
print("Total Marks :",Tot)
#Display Average Marks
print("Average Marks: ",Avg)
Output of the program
English:80
Maths :75
Science:85
Total Marks: 240
Average Marks: 80.0

Program No:9 To calculate discounted amount with discount %


# To calculate discounted amount with discount Percentage
#Input Amount
Amt=int(input("Amount: "))
#Input Discount%
Dis_per=int(input("Discount Percentage : "))
#Calculate Discount
Dis=Amt*Dis_per/100
#Calculate Discounted Amount
Dic_amt=Amt-Dis
#Display Discount
print("Discount: ",int(Dis))
#Display Discounted Amount
print("Discounted Amt: ",int(Dic_amt))
Output of the program
Amount: 5000
Discount Percentage:10
Discount:500
Discounted Amt:4500
Program No:10 To calculate Surface Area and Volume of a Cuboid
# To calculate Surface Area and Volume of a Cuboid
# Surface area = 2 (lh + lw+ hw)
# Volume = lwh
#Input Length
l=int(input("Length : "))
#Input Width
w=int(input("Width : "))
#Input Height
h=int(input("Height "))
#Calculate Surface Area
S_Area = 2*((l*h) +(l*w) +(h*w))
#Calculate Volume
Vol=l*w*h
#Display Area
print("Surface Area :",S_Area)
#Display Volume
print("Volume :",Vol)
Output of the program
Length:20
Breadth:10
Height:15
Surface Area:1300
Volume:3000

LIST
Program No:11 Create a list in Python of children selected for science quiz with following
names- Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik
Perform the following tasks on the list in sequence-
○ Print the whole list
○ Delete the name “Vikram” from the list
○ Add the name “Jay” at the end
○ Remove the item which is at the second position.
# children = ["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]
# Create a list of children selected for science quiz with following
# names- Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik

# Perform the following tasks on the list in sequence-


children = ["Arjun", "Sonakshi", "Vikram", "Sandhya", "Sonal", "Isha", "Kartik"]
# Print the whole list
print("The whole list after creating :",children)

# Delete the name "Vikram" from the list


children.remove("Vikram")
print("The list after deleting Vikram : ",children)

# Add the name "Jay" at the end


children.append("Jay")
print("The list after adding Jay :",children)

# Remove the item which is at the second position


children.pop(1)
print("The list after removing the item which is at the second position :",children)

# Print the final list


print("The final list :",children)
Output of the program
The whole list after creating : ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
The list after deleting Vikram : ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik']
The list after adding Jay : ['Arjun', 'Sonakshi', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']
The list after removing the item which is at the second position : ['Arjun', 'Sandhya', 'Sonal', 'Isha',
'Kartik', 'Jay']
The final list : ['Arjun', 'Sandhya', 'Sonal', 'Isha', 'Kartik', 'Jay']

Program No:12 Program to check if a person can vote


#A program to check if a person can vote
age = int(input("Enter Your Age : "))
if age >= 18: print("You are eligible to vote")
else: print("You are not eligible to vote")
When you run the above program, the output will be:
Output1
Enter Your Age : 18
You are eligible to vote
Output2
Enter Your Age : 15
You are not eligible to vote

Program No:13 Input a number and check if the number is positive, negative or zero and
display an appropriate message
# In this program, we input a number
# check if the number is positive or
# negative or zero and display an appropriate message
# This time we use nested if
num = float(input("Enter a number: "))
if num >= 0 :
if num == 0 :
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
The output will be:
Output 1
Enter a number: 5
Positive number
Output 2
Enter a number: -1
Negative number
Output 3
Enter a number: 0
Zero

Program No:14 To print sum of first 10 or ‘n’ natural numbers


# Program to add natural numbers upto 10
# sum = 1+2+3+...+n
# To take input from the user,
n = int(input("Enter the number : "))
#n = 10
# initialize sum and counter
sum = 0
i=1
while i <= n:
sum = sum + i
# update counter
i = i+1
# print the sum
print("The sum of first",i-1," natural numbers is : ", sum)

The output of the program :


Enter the number : 5
The sum of first 1 natural numbers is : 1
The sum of first 2 natural numbers is : 3
The sum of first 3 natural numbers is : 6
The sum of first 4 natural numbers is : 10
The sum of first 5 natural numbers is : 15

Program 15: Create a list List_1=[10,20,30,40]. Add the elements [14,15,12] using extend
function. Now sort the final list in ascending order and print it.
# Create a list List_1 with the elements 10, 20, 30, and 40

List_1 = [10, 20, 30, 40]


print("A list with the elements 10, 20, 30, and 40 : ",List_1)

# Add the elements 14, 15, and 12 to List_1 using the extend function
List_1.extend([14, 15, 12])
print("The list after adding elements 14, 15, and 12 : ",List_1)

# Sort the final list in ascending order using the sort function
List_1.sort()
print("Final list after sorting in ascending order : ",List_1)

When you run the program, the output will be:


A list with the elements 10, 20, 30, and 40 : [10, 20, 30, 40]
The list after adding elements 14, 15, and 12 : [10, 20, 30, 40, 14, 15, 12]
Final list after sorting in ascending order : [10, 12, 14, 15, 20, 30, 40]

Program No:16 To check the grade of a student


#To check the grade of a student
marks = int(input("Enter Your marks between 10 and 100 : "))
if marks > 75: print("You get an A grade")
elif marks > 60: print("You get a B grade")
else: print("You get a C grade")
When you run the above program, the output will be:
Output1
Enter Your marks between 10 and 100 : 90
You get an A grade
Output2
Enter Your marks between 10 and 100 : 68
You get a B grade
Output3
Enter Your marks between 10 and 100 : 50
You get a C grade

You might also like