Minimize the cost of buying the Objects | Function that will calculate the price ; Calculate the number of items we can get for free ; Calculate the number of items we will have to pay the price for ; Calculate the price ; Driver code ; Calling function
def totalPay ( totalItems , priceOfOneItem , N , M ) : NEW_LINE INDENT freeItems = 0 NEW_LINE actual = 0 NEW_LINE freeItems = totalItems // ( N + M ) NEW_LINE actual = totalItems - freeItems NEW_LINE amount = actual * priceOfOneItem NEW_LINE return amount NEW_LINE DEDENT T = 12 NEW_LINE P = 8 NEW_LINE N = 2 NEW_LINE M = 1 NEW_LINE print ( " Amount ▁ = ▁ " , totalPay ( T , P , N , M ) ) NEW_LINE