Created
August 14, 2017 01:10
-
-
Save gabrielleme00/1a5d202370a21714b1324ba39383e438 to your computer and use it in GitHub Desktop.
Problema do troco mínimo (Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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