Sunday, September 28, 2025

Python Program Collection 04 - Calculate Simple Interest, Profit, Loss, Profit/Loss Percentage

 Python Program Collection 04 - Calculate Simple Interest, Profit, Loss, Profit/Loss Percentage




43. Display simple interest

principal = float(input("Enter the Principal amount: "))

time = float(input("Enter the Time (in years): "))

rate = float(input("Enter the Rate of Interest (% per annum): "))

simple_interest = (principal * time * rate) / 100

print("The Simple Interest is:", simple_interest)

 

44. Input principal, rate, time and display total amount.

principal = float(input("Enter the Principal amount: "))

time = float(input("Enter the Time (in years): "))

rate = float(input("Enter the Rate of Interest (% per annum): "))

simple_interest = (principal * time * rate) / 100

total_amount = principal + simple_interest

print("The Total Amount (Principal + Interest) is:", total_amount)

 

45. Input principal, rate, time and display simple interest and total amount.

principal = float(input("Enter the Principal amount: "))

time = float(input("Enter the Time (in years): "))

rate = float(input("Enter the Rate of Interest (% per annum): "))

 

simple_interest = (principal * time * rate) / 100

total_amount = principal + simple_interest

print("The Simple Interest is:", simple_interest)

print("The Total Amount (Principal + Interest) is:", total_amount)

 

46. Input amount, rate, time and display principal.

amount = float(input("Enter the Total Amount: "))

rate = float(input("Enter the Rate of Interest (% per annum): "))

time = float(input("Enter the Time (in years): "))

principal = amount / (1 + (rate * time) / 100)

print("The Principal is:", principal)

 

47. Input simple interest, rate, time and display principal.

simple_interest = float(input("Enter the Simple Interest: "))

rate = float(input("Enter the Rate of Interest (% per annum): "))

time = float(input("Enter the Time (in years): "))

principal = (simple_interest * 100) / (rate * time)

print("The Principal is:", principal)


48. Calculate profit

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

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

profit = sp - cp

print("The Profit is:", profit)

 

 

49. Calculate loss

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

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

loss = cp - sp

print("The Loss is:", loss)

 

50E. Python Program (Profit or Loss Calculator)

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

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

 

if sp > cp:

    profit = sp - cp

    print("Profit =", profit)

elif cp > sp:

    loss = cp - sp

    print("Loss =", loss)

else:

    print("No Profit, No Loss")

 

50. Calculate profit percentage

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

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

profit = sp - cp

profit_percent = (profit / cp) * 100

print("Profit =", profit)

print("Profit Percentage =", profit_percent, "%")

 

51. Calculate loss percentage

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

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

loss = cp - sp

loss_percent = (loss / cp) * 100

print("Loss =", loss)

print("Loss Percentage =", loss_percent, "%")

 

51E. Python Program (Profit or Loss Percentage)

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

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

if sp > cp:

    profit = sp - cp

    profit_percent = (profit / cp) * 100

    print("Profit =", profit)

    print("Profit Percentage =", profit_percent, "%")

elif cp > sp:

    loss = cp - sp

    loss_percent = (loss / cp) * 100

    print("Loss =", loss)

    print("Loss Percentage =", loss_percent, "%")

else:

    print("No Profit, No Loss")

 

52. Calculate selling price  where profit percentage and cost price is given

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

profit_percent = float(input("Enter the Profit Percentage: "))

sp = cp * (1 + profit_percent / 100)

print("The Selling Price (SP) is:", sp)

 

53. Calculate selling price  where loss percentage and cost price is given

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

loss_percent = float(input("Enter the Loss Percentage: "))

sp = cp * (1 - loss_percent / 100)

print("The Selling Price (SP) is:", sp)

 

54. Calculate cost price  where loss percentage and selling price is given

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

loss_percent = float(input("Enter the Loss Percentage: "))

cp = sp / (1 - loss_percent / 100)

print("The Cost Price (CP) is:", cp)

 

55. Calculate cost price  where profit percentage and selling price is given

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

profit_percent = float(input("Enter the Profit Percentage: "))

cp = sp / (1 + profit_percent / 100)

print("The Cost Price (CP) is:", cp)


Python Program Collection 03 - to display tsa, volume of sphere, hemisphere, cylinder, cuboid, cube

 


28. Display total surface area of sphere.

pi = 3.1416

r = float(input("Enter the radius of the sphere: "))

area = 4 * pi * r ** 2

print(f"The total surface area of the sphere with radius {r} is: {area:.2f}")

 

 

 

 

29. Display volume of sphere.

r = float(input("Enter the radius of the sphere: "))

pi = 3.1416

volume = (4/3) * pi * r ** 3

print(f"The volume of the sphere with radius {r} is: {volume:.2f}")

 

30. Display total surface area and volume of sphere.

r = float(input("Enter the radius of the sphere: "))

surface_area = 4 * (22/7) * r ** 2

volume = (4/3) * (22/7) * r ** 3

print(f"The total surface area of the sphere with radius {r} is: {surface_area:.2f}")

print(f"The volume of the sphere is: {volume:.2f}")

 

31. Display total surface area of hemisphere.

r = float(input("Enter the radius of the hemisphere: "))

tsa  = 3 * (22/7) * r ** 2

print(f"The total surface area of the hemisphere is: {tsa:.2f}")

 

32. Display volume of hemisphere.

r = float(input("Enter the radius of the hemisphere: "))

volume = (2/3) * (22/7) * r ** 3

print(f"The volume of the hemisphere with radius {r} is: {volume:.2f}")

 

33. Display total surface area and volume of hemisphere.

r = float(input("Enter the radius of the hemisphere: "))

TSA = 3 * (22/7) * r ** 2

volume = (2/3) * (22/7) * r ** 3

print(f"The total surface area of the hemisphere is: {TSA:.2f}")

print(f"The volume of the hemisphere is: {volume:.2f}")

 

34. Display total surface area of cylinder.

r = float(input("Enter the radius of the cylinder: "))

h = float(input("Enter the height of the cylinder: "))

TSA = 2 * (22/7) * r * (h + r)

print(f"The total surface area of the cylinder is: {TSA:.2f}")

 

35. Display volume of cylinder.

r = float(input("Enter the radius of the cylinder: "))

h = float(input("Enter the height of the cylinder: "))

volume = (22/7) * r ** 2 * h

print(f"The volume of the cylinder is: {volume:.2f}")

 

36. Display total surface area and volume of cylinder.

r = float(input("Enter the radius of the cylinder: "))

h = float(input("Enter the height of the cylinder: "))

TSA = 2 * (22/7) * r * (h + r)

volume = (22/7) * r ** 2 * h

print(f"The total surface area of the cylinder is: {TSA:.2f}")

print(f"The volume of the cylinder is: {volume:.2f}")

 

37. Display total surface area of cuboid / box.

l = float(input("Enter the length of the cuboid: "))

b = float(input("Enter the breadth of the cuboid: "))

h = float(input("Enter the height of the cuboid: "))

TSA = 2 * (l*b + b*h + h*l)

print(f"The total surface area of the cuboid is: {TSA:.2f}")

 

38. Display volume of cuboid / box.

l = float(input("Enter the length of the cuboid: "))

b = float(input("Enter the breadth of the cuboid: "))

h = float(input("Enter the height of the cuboid: "))

volume = l * b * h

print(f"The volume of the cuboid is: {volume:.2f}")

 

39. Display total surface area and volume of cuboid.

l = float(input("Enter the length of the cuboid: "))

b = float(input("Enter the breadth of the cuboid: "))

h = float(input("Enter the height of the cuboid: "))

TSA = 2 * (l*b + b*h + h*l)

volume = l * b * h

print(f"The total surface area of the cuboid is: {TSA:.2f}")

print(f"The volume of the cuboid is: {volume:.2f}")

 

40. Display total surface area of cube.

a = float(input("Enter the side of the cube: "))

TSA = 6 * a ** 2

print(f"The total surface area of the cube with side {a} is: {TSA:.2f}")

 

41. Display volume of cube

a = float(input("Enter the side of the cube: "))

volume = a ** 3

print(f"The volume of the cube with side {a} is: {volume:.2f}")

 

42. Display total surface area and volume of cube.

a = float(input("Enter the side of the cube: "))

TSA = 6 * a ** 2

volume = a ** 3

print(f"The total surface area of the cube with side {a} is: {TSA:.2f}")

print(f"The volume of the cube with side {a} is: {volume:.2f}")

Python Program Collection 02 - to display area, perimeter of rectangle, square, circle, triangle, area of 4 walls

 



Python Program Collection 02 - to display area, perimeter of rectangle, square, circle, triangle, area of 4 walls

15. Display area of rectangle.

length = int(input("Enter the length of rectangle: "))

breadth = int(input("Enter the breadth of rectangle: "))

area = length * breadth

print(f"Area of rectangle with length {length} and breadth {breadth} is {area}")

 

16. Display area of square.

side = int(input("Enter the side of the square: "))

area = side ** 2

print(f"Area of square with side {side} is {area}")

 

17. Display area of circle.

radius = float(input("Enter the radius of the circle: "))

area = 22 / 7 * (radius ** 2)

print(f"Area of circle with radius {radius} is {area}")

 

18. Display perimeter of rectangle.

length = int(input("Enter the length of rectangle: "))

breadth = int(input("Enter the breadth of rectangle: "))

perimeter = 2 * (length + breadth)

print(f"Perimeter of rectangle = {perimeter}")

 

19. Display perimeter of square.

side = int(input("Enter the side of the square: "))

perimeter = 4 * side

print(f"Perimeter of square with side {side} is {perimeter}")

 

20. Display circumference of circle.

radius = float(input("Enter the radius of the circle: "))

circumference = 2 * (22 / 7) * radius

print(f"Circumference of circle with radius {radius} is {circumference}")

 

21. Display area and perimeter of rectangle.

length = int(input("Enter the length of rectangle: "))

breadth = int(input("Enter the breadth of rectangle: "))

area = length * breadth

perimeter = 2 * (length + breadth)

print(f"Area of rectangle is {area}")

print(f"Perimeter of rectangle is {perimeter}")

 

22. Display area and perimeter of square.

side = int(input("Enter the side of the square: "))

area = side * side       

perimeter = 4 * side

print(f"Area of square with side {side} is {area}")

print(f"Perimeter of square with side {side} is {perimeter}")

 

23. Display area and circumference of circle.

radius = float(input("Enter the radius of the circle: "))

area = 22 / 7 * (radius ** 2)

circumference = 2 * 22 / 7 * radius

print(f"Area of circle with radius {radius} is {area}")

print(f"Circumference of circle with radius {radius} is {circumference}")

 

24. Display area of 4 walls.

length = float(input("Enter the length of the room: "))

breadth = float(input("Enter the breadth of the room: "))

height = float(input("Enter the height of the room: "))

area_walls = 2 * (length + breadth) * height

print(f"Area of 4 walls of room is {area_walls}")

 

25. Display area of triangle.

base = float(input("Enter the base of the triangle: "))

height = float(input("Enter the height of the triangle: "))

area = 0.5 * base * height

print(f"Area of triangle with base {base} and height {height} is {area}")

 

26. Display area of parallelogram.

base = float(input("Enter the base of the parallelogram: "))

height = float(input("Enter the height of the parallelogram: "))

area = base * height

print(f"Area of parallelogram is {area}")

 

27. Display area of triangle when three sides are given.

a = float(input("Enter first side of the triangle: "))

b = float(input("Enter second side of the triangle: "))

c = float(input("Enter third side of the triangle: "))

s = (a + b + c) / 2  

area = (s * (s - a) * (s - b) * (s - c)) ** 0.5  

print(f"Area of triangle with sides {a}, {b}, {c} is {area}")

Python Program Collection 01 - to find sum, product, average and product of two numbers

 


1. Enter any two numbers and display its sum.

first_num = int(input("Enter the first number: "))

second_num = int(input("Enter the second number: "))    

sum = first_num + second_num

print(f"The sum of {first_num} and {second_num} is {sum}")

 

2. Enter any two numbers and display its difference.

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

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

difference = num1 - num2

print("The difference of two number is:", difference)

 

3. Enter any two numbers and display its product.

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

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

product = num1 * num2

print(f"The product of {num1} and {num2} is {product}")

 

4. Enter any two numbers and display its average.

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

average = (num1 + num2) / 2

print("The average of two numbers = ", average)

 

5. Enter any two numbers and display its sum, difference, product and average.

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

sum_result = num1 + num2

difference = num1 - num2

product = num1 * num2

average = (num1 + num2) / 2

print(f"Sum of two numbers = {sum_result}")

print(f"Difference of two numbers =  {difference}")

print(f"Product of two numbers =  {product}")

print(f"Average of two numbers =  {average}")

 

6. Enter any three numbers and display its sum, product and average.

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

num3 = float(input("Enter third number: "))

sum_result = num1 + num2 + num3

product = num1 * num2 * num3

average = (num1 + num2 + num3) / 3

product = num1 * num2 * num3

print(f"Sum of three numbers = {sum_result}")

print(f"Product of three numbers = { product }")

print(f"Average of three numbers = {average}")

 

7. Display square of an input number.

num = float(input("Enter a number: "))

square = num ** 2

print("Square of the number is:", square)

 

8. Display cube of an input number.

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

square = num ** 3

print("Cube of the number is:", square)

 

9. Display square root of an input number.

num = float(input("Enter a number: "))

sqrt = num ** 0.5   # exponent 0.5 gives square root

print("Square root of", num, "is", sqrt)

 

10. Display cube root of an input number.

num = float(input("Enter a number: "))

cube_root = num ** (1/3)

print(f"Cube root of {num} is {cube_root}")

 

11. Display sum of square of any two input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

sum_of_squares = (a ** 2) + (b ** 2)

print(f"Sum of squares of {a} and {b} is {sum_of_squares}")

12. Display sum of cube of any two input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

sum_of_cubes = (a ** 3) + (b ** 3)

print(f"Sum of cubes of {a} and {b} is {sum_of_cubes}")

 

13. Display sum of square of any three input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

c = float(input("Enter third number: "))

sum_of_squares = (a ** 2) + (b ** 2) + (c ** 2)

print(f"Sum of squares of {a}, {b} and {c} is {sum_of_squares}")

 

14. Display sum of cube of any three input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

c = float(input("Enter third number: "))

sum_of_cubes = (a ** 3) + (b ** 3) + (c ** 3)

print(f"Sum of cubes of {a}, {b} and {c} is {sum_of_cubes}")