Find cost price from given selling price and profit or loss percentage | Function to calculate cost price with profit ; required formula to calculate CP with profit ; Function to calculate cost price with loss ; required formula to calculate CP with loss ; Driver code
def CPwithProfit ( sellingPrice , profit ) : NEW_LINE INDENT costPrice = ( ( sellingPrice * 100.0 ) / ( 100 + profit ) ) NEW_LINE return costPrice NEW_LINE DEDENT def CPwithLoss ( sellingPrice , loss ) : NEW_LINE INDENT costPrice = ( ( sellingPrice * 100.0 ) / ( 100 - loss ) ) NEW_LINE return costPrice NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT SP = 1020 NEW_LINE profit = 20 NEW_LINE print ( " Cost ▁ Price ▁ = " , CPwithProfit ( SP , profit ) ) NEW_LINE SP = 900 NEW_LINE loss = 10 NEW_LINE print ( " Cost ▁ Price ▁ = " , CPwithLoss ( SP , loss ) ) NEW_LINE SP = 42039 NEW_LINE profit = 8 NEW_LINE print ( " Cost ▁ Price ▁ = " , int ( CPwithProfit ( SP , profit ) ) ) NEW_LINE DEDENT