Python Practical Programs
1. Write a program to accept two integers and print their sum.
# This program calculates the sum of two integers.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)
Sample Output:
Enter first number: 5
Enter second number: 7
Sum: 12
2. Write a program that accepts the radius of a circle and prints its area.
# This program calculates the area of a circle given the radius.
import math
radius = float(input("Enter the radius of the circle: "))
area = math.pi * radius ** 2
print("Area of the circle:", area)
Sample Output:
Enter the radius of the circle: 3
Area of the circle: 28.27
3. Write a program that accepts base and height and calculates the area of a triangle.
# This program calculates the area of a triangle.
base = float(input("Enter base of the triangle: "))
height = float(input("Enter height of the triangle: "))
area = 0.5 * base * height
print("Area of the triangle:", area)
Sample Output:
Enter base of the triangle: 10
Enter height of the triangle: 5
Area of the triangle: 25.0
4. Write a program that inputs a student's marks in three subjects (out of 100) and prints the percen
# This program calculates the percentage of marks in three subjects.
Python Practical Programs
marks1 = float(input("Enter marks in subject 1: "))
marks2 = float(input("Enter marks in subject 2: "))
marks3 = float(input("Enter marks in subject 3: "))
percentage = (marks1 + marks2 + marks3) / 3
print("Percentage marks:", percentage)
Sample Output:
Enter marks in subject 1: 85
Enter marks in subject 2: 90
Enter marks in subject 3: 80
Percentage marks: 85.0
5. Write a program to compute the area of square and triangle.
# This program calculates the area of a square and a triangle.
side = float(input("Enter the side of the square: "))
area_square = side ** 2
print("Area of the square:", area_square)
base = float(input("Enter base of the triangle: "))
height = float(input("Enter height of the triangle: "))
area_triangle = 0.5 * base * height
print("Area of the triangle:", area_triangle)
Sample Output:
Enter the side of the square: 4
Area of the square: 16.0
Enter base of the triangle: 10
Enter height of the triangle: 5
Area of the triangle: 25.0
6. Write a program to calculate simple interest.
# This program calculates simple interest.
principal = float(input("Enter principal amount: "))
rate = float(input("Enter annual interest rate (in %): "))
time = float(input("Enter time in years: "))
simple_interest = (principal * rate * time) / 100
print("Simple Interest:", simple_interest)
Python Practical Programs
Sample Output:
Enter principal amount: 1000
Enter annual interest rate (in %): 5
Enter time in years: 2
Simple Interest: 100.0