Python Programming : profit and loss

Example

Input 
enter the cost price 250 
enter the sell price 260
Output
The profit is 10

Required to know

Use of Variables, Use of different operators like assignment or arithmetic operators, Use of functions like print(), and input(), Use of If-else, and Use of Data types.

Steps

  • Take the cost price and sell price as input from the user.

  • Check if the cost price is less than the selling price, then it should be profit. Otherwise, it will be a loss.

Condition

1. if(cp>sp):
    amount = cp - sp
    print("Loss")
2. if(sp>cp):
    amount = sp - cp
    print("profit")

Program

# This program calculates the profit or loss of a business.
# Get the cost price and selling price from the user.
cost_price = float(input("Enter the cost price: "))
selling_price = float(input("Enter the selling price: "))
# Print the profit or loss.
if cost_price > selling_price:
    amount = cost_price - selling_price
    print("The Loss is $", amount)
elif selling_price > cost_price:
    amount = selling_price - cost_price
    print("The profit is $", amount)
else:
    print("There is no profit or loss.")