I have the following code that prints out the least amount of bills needed to form a given amount of dollars:
dollars = 568
billSelection = [100,50,20,10,5,1]
def thingy(bill):
global dollars
numOfBills = dollars // bill
dollars -= numOfBills * bill
return numOfBills
result = list(map(thingy,billSelection))
print(result)
print(sum(result))
I would like to pass 'dollars' into the function in order to avoid the ugly global variable. It works if I set dollars as a list with 1 element and write dollars[0] everywhere else but this is also not optimal. Any suggestions for how to do this cleanly? Thanks!