Can someone explain to me why this doesn't work?
I am trying to create a change machine using recursion. The first parameter is the amount of change that we need to give back, and the second parameter is an array of the number of bills with the first element representing $25, the second representing $50 and the last representing $100.
When I call checkchange(125,[0,1,1]) it now does not return "T" or "F"
instead it just prints out
lets go
Bills: 011 Money: 125
ok the money is greater than 100
lets go
Bills: 010 Money: 25
this is the money 25
Here is the code:
def checkchange(money,bills):
tot = bills[0] * 25 + bills[1] * 50 + bills[2] * 100
print("lets go")
string = "".join(str(e) for e in bills)
print("Bills: %s Money %d" % (string,money))
if tot < money:
return "F"
elif money == 25 and bills[0] == 0:
return "F"
elif money >= 100 and bills[2] > 0:
print("ok the money is greater than 100")
money -= 100
bills[2] -= 1
checkchange(money,bills)
print("this is the money %d" % money)
elif money >= 50 and bills[1] > 0:
print("ok the money is greater than 50")
money -= 50
bills[1] -= 1
checkchange(money,bills)
elif money >= 25 and bills[0] > 0:
print("money is greater than 25")
money -= 25
bills[0] -=1
checkchange(money,bills)
else:
return "T"
and, not&