Horje
Python Program to calculate Profit Or Loss

Given the Cost Price(CP) and Selling Price(SP) of a product. The task is to Calculate the Profit or Loss.
Examples: 

Input: CP = 1500, SP = 2000
Output: 500 Profit

Input: CP = 3125, SP = 1125
Output: 2000 Loss

Formula: 

Profit = (Selling Price – Cost Price)

Loss = (Cost Price – Selling Price)

Program to calculate Profit Or Loss 

Below is the required implementation:  

Python 3

# Python 3 program to demonstrate
# Profit and Loss
 
# Function to calculate Profit.
def Profit(costPrice, sellingPrice) :
 
    profit = (sellingPrice - costPrice)
 
    return profit
 
# Function to calculate Loss.
def Loss(costPrice, sellingPrice) :
 
    Loss = (costPrice - sellingPrice)
 
    return Loss
 
# Driver code
if __name__ == "__main__" :
 
    costPrice, sellingPrice = 1500, 2000
 
    if sellingPrice == costPrice :
        print("No profit nor Loss")
 
    elif sellingPrice > costPrice :
        print(Profit(costPrice,
                     sellingPrice), "Profit")
 
    else :
        print(Loss(costPrice,
                   sellingPrice), "Loss")

Output: 

500 Profit

Time Complexity: O(1)
Auxiliary Space: O(1)




Reffered: https://www.geeksforgeeks.org


Python Programs

Related
Python Program for Convert characters of a string to opposite case Python Program for Convert characters of a string to opposite case
Python Program for Remove leading zeros from a Number given as a string Python Program for Remove leading zeros from a Number given as a string
Python Program to find if a character is vowel or Consonant Python Program to find if a character is vowel or Consonant
Python program to find power of a number Python program to find power of a number
Python Program for Coin Change | DP-7 Python Program for Coin Change | DP-7

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13