Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dojo cujo problema é o do mínimo número possível de moedas de um troco
def troco(valor):
retorno = {50: 0, 25: 0, 10:0, 5: 0, 1: 0}
while valor >= 5:
if valor >= 50:
retorno[50] += 1
valor = valor - 50
elif valor >= 25:
retorno[25] = 1
valor = valor - 25
elif valor >= 10:
retorno[10] += 1
valor = valor - 10
elif valor >= 5:
retorno[5] = 1
valor = valor - 5
retorno[1] = 1 * valor
return retorno
assert troco(0) == {50: 0, 25: 0, 10:0, 5: 0, 1: 0}
assert troco(5) == {50: 0, 25: 0, 10:0, 5: 1, 1: 0}
assert troco(1) == {50: 0, 25: 0, 10:0, 5: 0, 1: 1}
assert troco(3) == {50: 0, 25: 0, 10:0, 5: 0, 1: 3}
assert troco(6) == {50: 0, 25: 0, 10:0, 5: 1, 1: 1}
assert troco(17) == {50: 0, 25: 0, 10:1, 5: 1, 1: 2}
assert troco(18) == {50: 0, 25: 0, 10:1, 5: 1, 1: 3}
assert troco(32) == {50: 0, 25: 1, 10:0, 5: 1, 1: 2}
assert troco(62) == {50: 1, 25: 0, 10:1, 5: 0, 1: 2}, troco(62)
assert troco(232) == {50: 4, 25: 1, 10:0, 5: 1, 1: 2}, troco(232)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.