Skip to content

Instantly share code, notes, and snippets.

@gabrielleme00
Created August 14, 2017 01:10
Show Gist options
  • Save gabrielleme00/1a5d202370a21714b1324ba39383e438 to your computer and use it in GitHub Desktop.
Save gabrielleme00/1a5d202370a21714b1324ba39383e438 to your computer and use it in GitHub Desktop.
Problema do troco mínimo (Python)
def troco_minimo(troco):
moedas_disponiveis = [100, 50, 25, 10, 5, 1]
moedas_utilizadas = {} # Dicionario (moeda: quantidade)
total = 0
for i in range(len(moedas_disponiveis)):
num_moedas = troco // moedas_disponiveis[i]
troco -= num_moedas * moedas_disponiveis[i]
total += num_moedas
if num_moedas > 0:
moedas_utilizadas[moedas_disponiveis[i]] = num_moedas
print("Total:", total)
print("Moedas utilizadas:")
for moeda, quantidade in moedas_utilizadas.items():
print("Moeda de", moeda, "->", quantidade)
troco_minimo(130)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment