# Python program to calculate profit and loss

By IncludeHelp Last updated : February 8, 2024

Sometimes you may need to calculate profit and loss. Profile and loss are calculated by using mathematical formulas based on the cost price and selling price.

## Profit and Loss Formulas

If the selling price and cost price are given, the formulas to calculate the profit and loss are:

• Profit = Selling price - Cost price
• Loss = Cost price - Selling price

## Problem statement

Given the cost and selling prices of an item, write a Python program to calculate profit and loss.

## Calculating profile and loss in Python

In Python, if the selling price and cost price are given, you can calculate the profit and loss by using the following basic formulas:

• Profit = Selling price - Cost price
• Loss = Cost price - Selling price

## Python program to calculate profit and loss

```# Python program to calculate
# Profit and Loss based on the give
# Cost price and selling price

# Functions to calculate profit and liss
def CalculateProfit(cost_price, selling_Price):
result = selling_Price - cost_price
return result

def CalculateLoss(cost_price, selling_Price):
result = cost_price - selling_Price
return result

# The main code
# Input cost and saling price
cost_price = float(input("Enter cost price : "))
selling_Price = float(input("Enter selling price : "))

# Calculating profit and loss
# If both prices are same
if selling_Price == cost_price:
print("No profit loss.")

# If selling price is higher than cost price
# Then, it will be a profit
elif selling_Price > cost_price:
profit = CalculateProfit(cost_price, selling_Price)
print("Profit :", profit)

# else, loss will be there
else:
loss = CalculateLoss(cost_price, selling_Price)
print("Loss :", loss)
```

## Output

The output of the above program is:

```RUN 1:
Enter cost price : 15350
Enter selling price : 21450
Profit : 6100.0

RUN 2:
Enter cost price : 1200
Enter selling price : 1180
Loss : 20.0

RUN 3:
Enter cost price : 1008
Enter selling price : 1008
No profit loss.
```

To understand the above program, you should have the basic knowledge of the following Python topics: