Exercicio sobre moedas

This commit is contained in:
Caio1w
2025-11-01 18:45:47 -03:00
parent 4a522fd86f
commit 1940701c78
3 changed files with 22 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
troco = 187
moedas = [1,5,10,25,50,100]
moedasr = moedas[::-1]
valor = 0
moedas_final = 0
for moeda in moedasr:
while valor < troco:
valor += moeda
moedas_final += 1
if valor > troco:
moedas_final -= 1
valor -= moeda
break
if valor == troco:
print(moedas_final)
break