Here we are going to write python program to calculate profit loss for a given cost and sale price
Profit and Loss formulas are given as
Profit = sale_price - cost_price
Loss = cost_price - sale_price
Example :
Example : Actual cost of product is 5000 and selling cost of product is 6000 then find profit or loss of the given product
Solution :
If actual cost of the product is less than selling cost then profit is calculated as follows
Profit = sale_price – cost_price
Here Actual cost of product is 5000 which is less then selling cost of product so profit will be calculated
Profit = 6000 – 5000
Profit = 1000
Program:
# Python Program to Calculate Profit or Loss
# Input Actual cost price of product
cost_price = float(input("Enter the Actual Product Price: "))
# Input Selling price of product
sale_price = float(input("Enter the Sales Price: "))
# If sale price is greater than actual price then calcualate profit
if(sale_price > cost_price):
profit = sale_price - cost_price
print("Total Profit = {0}".format(profit))
# If sale price is less than actual price then calcualate loss
elif(cost_price > sale_price):
loss = cost_price - sale_price
print("Total Loss Amount = {0}".format(loss))
# If sale price is less than actual price then no profit or no loss
else:
print("No Profit No Loss!!!")
Output:
>>> %Run 'profit and loss.py' Enter the Actual Product Price: 5340 Enter the Sales Price: 6500 Total Profit = 1160.0 >>> %Run 'profit and loss.py' Enter the Actual Product Price: 5400 Enter the Sales Price: 5400 No Profit No Loss!!! >>> %Run 'profit and loss.py' Enter the Actual Product Price: 5000 Enter the Sales Price: 6000 Total Profit = 1000.0 >>> %Run 'profit and loss.py' Enter the Actual Product Price: 6000 Enter the Sales Price: 5000 Total Loss Amount = 1000.0
Other python programs:
<