Profit Loss Program in Python


If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.

This program calculates the profit or loss of an item based on the cost price and selling price entered by the user. It first takes the cost price and selling price as input from the user and stores them as float variables "cost_price" and "selling_price" respectively. Then, it checks if the selling price is greater than the cost price using an if statement. If it is, it calculates the profit by subtracting the cost price from the selling price and prints the result. If the cost price is greater than the selling price, it calculates the loss by subtracting the selling price from the cost price and prints the result. If the cost price and selling price are equal, it prints "No Profit No Loss".


Source Code

cost_price=float(input("Enter the cost Price of an Item :"))
selling_price=float(input("Enter the Selling Price of an Item :"))
if (selling_price > cost_price):
	profit = selling_price - cost_price
	print("Profit :",profit)
elif( cost_price > selling_price):
	loss = cost_price - selling_price
	print("Loss :",loss)
else:
	print("No Profit No Loss")

Output

Enter the cost Price of an Item :230
Enter the Selling Price of an Item :250
Profit : 20.0


Example Programs