The goal of this challenge is to design a cash register program. You will be given two decimal numbers. The first is the purchase price (PP) of the item. The second is the cash
(CH)
given by the customer. Your register currently has the following bills/coins within it: 'PENNY': 01, 'NICKEL': .05, 'DIME': .10, 'QUARTER': .25, 'HALF DOLLAR': .50, 'ONE': 1.00, 'TWO': 2.00, 'FIVE': 5.00, 'TEN': 10.00, 'TWENTY': 20.00, 'FIFTY': 50.00, 'ONE HUNDRED':
100.00
The aim of the program is to calculate the change that has to be returned to the customer. Each input string contains two numbers which are separated by a semicolon. The first is the Purchase price (PP) and the second is the cash(CH) given by the customer. For each line of input return single line string is the change to be returned to the customer. In case the
CH , return "ERROR". If
CH==PP
, return "ZERO". For all other cases return a comma separated string with the amount that needs to be returned, in terms of the currency values provided. The output should be alphabetically sorted. # # Complete the 'MakeChange' function below. # # The function is expected to return a STRING. # The function accepts STRING purchaseInfo as parameter. # def MakeChange(purchaseInfo): # Write your code here n if

Respuesta :

Using the knowledge of computational language in python it is possible to write a code that given two decimal numbers and The first is the purchase price (PP) of the item.

Writting the code:

def MakeChange(purchaseInfo):

a = []

k = purchaseInfo.split(';')

for i in k:

a.append(float(i))

price = a[0]

cash = a[1]

if (cash < price):

return "ERROR"

if (cash == price):

return "ZERO"

cashBack = cash - price;

change =[]

while (cashBack > 0.01):

if (cashBack >= 100.0):

change.append("ONE HUNDRED")

cashBack -= 100.0

elif (cashBack >= 50.0):

change.append("FIFTY")

cashBack -= 50.0

elif (cashBack >= 20.0):

change.append("TWENTY")

cashBack -= 20.0

elif (cashBack >= 10.0):

change.append("TEN");

cashBack -= 10.0;

elif (cashBack >= 5.0):

change.append("FIVE")

cashBack -= 5.0

elif (cashBack >= 2.0):

change.append("TWO");

cashBack -= 2.0;

elif (cashBack >= 1.0):

change.append("ONE")

cashBack -= 1.0

elif (cashBack >= 0.5):

change.append("HALF DOLLAR")

cashBack -= 0.5

elif (cashBack >= 0.25):

change.append("QUARTER")

cashBack -= 0.25

elif (cashBack >= 0.1):

change.append("DIME");

cashBack -= 0.1;

elif (cashBack >= 0.05):

change.append("NICKEL")

cashBack -= 0.05

else:

change.append("PENNY");

cashBack -= 0.01;

See more about python at brainly.com/question/18502436

#SPJ1

Ver imagen lhmarianateixeira