Coursework 2

(f) Determine Payment from a "Pocket" of Available Coins

An android is being programmed to go shopping. It will need to deal with coins and payments in a similar way to humans.

Define a function pay_with_coins_from_pocket( amount, pocket ), where amount is a floating point number with up to two decimal places, and pocket is a list of 8 integers representing the numbers of coins the android has in its pocket, given in the following order (same as for part (e)):

The value returned by pay_with_coins_from_pocket( amount, pocket ) is given by the following specification:

Examples
INPUT 1 INPUT 2 OUPUT Coins to be paid
0.50 [0,0,0,0,4,1,1,1] False Cannot pay (only have 48p)
1.62 [2,1,0,0,0,0,0,0] [1,0,0,0,0,0,0,0,0.38] 1×£2, Change 38p
3.75 [2,3,4,0,0,0,0,0] [0,2,4,0,0,0,0,0,0.25] 2×£1, 4×50p, Change 25p
0.05 [0,0,0,0,0,5,3,6] [0,0,0,0,0,0,0,5,0] 5×1p, Change 0
0.05 [0,0,0,0,0,1,3,0] [0,0,0,0,0,1,0,0,0] 1×5p, Change 0
0.08 [0,0,0,0,0,1,4,3] [0,0,0,0,0,0,3,2,0] 3×2p, 2×1p, Change 0

Notes: